| author | |
| committer | |
| log | 67154d233ef68d9fd63e673e63e7d66f149060a5 |
| tree | 341521e1c7cd9d3ea77726e27661b08d46b9a8dd |
| parent | fed1c9c3ece7b79ce7fccc6af510f1dab98401a9 |
| parent | 7437c47d55da4c73aba26327d1a140aaf6591d4a |
| signature |
Allow tests to fail407 files changed, 12827 insertions(+), 12815 deletions(-)
doc/langref.html.in+349-348| ... | ... | @@ -358,7 +358,7 @@ test "comments" { |
| 358 | 358 | //expect(false); |
| 359 | 359 | |
| 360 | 360 | const x = true; // another comment |
| 361 | expect(x); | |
| 361 | try expect(x); | |
| 362 | 362 | } |
| 363 | 363 | {#code_end#} |
| 364 | 364 | <p> |
| ... | ... | @@ -718,15 +718,15 @@ const mem = @import("std").mem; |
| 718 | 718 | |
| 719 | 719 | test "string literals" { |
| 720 | 720 | const bytes = "hello"; |
| 721 | expect(@TypeOf(bytes) == *const [5:0]u8); | |
| 722 | expect(bytes.len == 5); | |
| 723 | expect(bytes[1] == 'e'); | |
| 724 | expect(bytes[5] == 0); | |
| 725 | expect('e' == '\x65'); | |
| 726 | expect('\u{1f4a9}' == 128169); | |
| 727 | expect('💯' == 128175); | |
| 728 | expect(mem.eql(u8, "hello", "h\x65llo")); | |
| 729 | expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation. | |
| 721 | try expect(@TypeOf(bytes) == *const [5:0]u8); | |
| 722 | try expect(bytes.len == 5); | |
| 723 | try expect(bytes[1] == 'e'); | |
| 724 | try expect(bytes[5] == 0); | |
| 725 | try expect('e' == '\x65'); | |
| 726 | try expect('\u{1f4a9}' == 128169); | |
| 727 | try expect('💯' == 128175); | |
| 728 | try expect(mem.eql(u8, "hello", "h\x65llo")); | |
| 729 | try expect("\xff"[0] == 0xff); // non-UTF-8 strings are possible with \xNN notation. | |
| 730 | 730 | } |
| 731 | 731 | {#code_end#} |
| 732 | 732 | {#see_also|Arrays|Zig Test|Source Encoding#} |
| ... | ... | @@ -826,7 +826,7 @@ test "var" { |
| 826 | 826 | |
| 827 | 827 | y += 1; |
| 828 | 828 | |
| 829 | expect(y == 5679); | |
| 829 | try expect(y == 5679); | |
| 830 | 830 | } |
| 831 | 831 | {#code_end#} |
| 832 | 832 | <p>Variables must be initialized:</p> |
| ... | ... | @@ -845,7 +845,7 @@ const expect = @import("std").testing.expect; |
| 845 | 845 | test "init with undefined" { |
| 846 | 846 | var x: i32 = undefined; |
| 847 | 847 | x = 1; |
| 848 | expect(x == 1); | |
| 848 | try expect(x == 1); | |
| 849 | 849 | } |
| 850 | 850 | {#code_end#} |
| 851 | 851 | <p> |
| ... | ... | @@ -887,8 +887,8 @@ var y: i32 = add(10, x); |
| 887 | 887 | const x: i32 = add(12, 34); |
| 888 | 888 | |
| 889 | 889 | test "global variables" { |
| 890 | expect(x == 46); | |
| 891 | expect(y == 56); | |
| 890 | try expect(x == 46); | |
| 891 | try expect(y == 56); | |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -906,8 +906,8 @@ const std = @import("std"); |
| 906 | 906 | const expect = std.testing.expect; |
| 907 | 907 | |
| 908 | 908 | test "namespaced global variable" { |
| 909 | expect(foo() == 1235); | |
| 910 | expect(foo() == 1236); | |
| 909 | try expect(foo() == 1235); | |
| 910 | try expect(foo() == 1236); | |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | fn foo() i32 { |
| ... | ... | @@ -985,8 +985,8 @@ test "comptime vars" { |
| 985 | 985 | x += 1; |
| 986 | 986 | y += 1; |
| 987 | 987 | |
| 988 | expect(x == 2); | |
| 989 | expect(y == 2); | |
| 988 | try expect(x == 2); | |
| 989 | try expect(y == 2); | |
| 990 | 990 | |
| 991 | 991 | if (y != 2) { |
| 992 | 992 | // This compile error never triggers because y is a comptime variable, |
| ... | ... | @@ -1777,6 +1777,7 @@ orelse catch |
| 1777 | 1777 | {#header_open|Arrays#} |
| 1778 | 1778 | {#code_begin|test|arrays#} |
| 1779 | 1779 | const expect = @import("std").testing.expect; |
| 1780 | const assert = @import("std").debug.assert; | |
| 1780 | 1781 | const mem = @import("std").mem; |
| 1781 | 1782 | |
| 1782 | 1783 | // array literal |
| ... | ... | @@ -1784,14 +1785,14 @@ const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' }; |
| 1784 | 1785 | |
| 1785 | 1786 | // get the size of an array |
| 1786 | 1787 | comptime { |
| 1787 | expect(message.len == 5); | |
| 1788 | assert(message.len == 5); | |
| 1788 | 1789 | } |
| 1789 | 1790 | |
| 1790 | 1791 | // A string literal is a single-item pointer to an array literal. |
| 1791 | 1792 | const same_message = "hello"; |
| 1792 | 1793 | |
| 1793 | 1794 | comptime { |
| 1794 | expect(mem.eql(u8, &message, same_message)); | |
| 1795 | assert(mem.eql(u8, &message, same_message)); | |
| 1795 | 1796 | } |
| 1796 | 1797 | |
| 1797 | 1798 | test "iterate over an array" { |
| ... | ... | @@ -1799,7 +1800,7 @@ test "iterate over an array" { |
| 1799 | 1800 | for (message) |byte| { |
| 1800 | 1801 | sum += byte; |
| 1801 | 1802 | } |
| 1802 | expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); | |
| 1803 | try expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); | |
| 1803 | 1804 | } |
| 1804 | 1805 | |
| 1805 | 1806 | // modifiable array |
| ... | ... | @@ -1809,8 +1810,8 @@ test "modify an array" { |
| 1809 | 1810 | for (some_integers) |*item, i| { |
| 1810 | 1811 | item.* = @intCast(i32, i); |
| 1811 | 1812 | } |
| 1812 | expect(some_integers[10] == 10); | |
| 1813 | expect(some_integers[99] == 99); | |
| 1813 | try expect(some_integers[10] == 10); | |
| 1814 | try expect(some_integers[99] == 99); | |
| 1814 | 1815 | } |
| 1815 | 1816 | |
| 1816 | 1817 | // array concatenation works if the values are known |
| ... | ... | @@ -1819,7 +1820,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 }; |
| 1819 | 1820 | const part_two = [_]i32{ 5, 6, 7, 8 }; |
| 1820 | 1821 | const all_of_it = part_one ++ part_two; |
| 1821 | 1822 | comptime { |
| 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 | } |
| 1824 | 1825 | |
| 1825 | 1826 | // remember that string literals are arrays |
| ... | ... | @@ -1827,21 +1828,21 @@ const hello = "hello"; |
| 1827 | 1828 | const world = "world"; |
| 1828 | 1829 | const hello_world = hello ++ " " ++ world; |
| 1829 | 1830 | comptime { |
| 1830 | expect(mem.eql(u8, hello_world, "hello world")); | |
| 1831 | assert(mem.eql(u8, hello_world, "hello world")); | |
| 1831 | 1832 | } |
| 1832 | 1833 | |
| 1833 | 1834 | // ** does repeating patterns |
| 1834 | 1835 | const pattern = "ab" ** 3; |
| 1835 | 1836 | comptime { |
| 1836 | expect(mem.eql(u8, pattern, "ababab")); | |
| 1837 | assert(mem.eql(u8, pattern, "ababab")); | |
| 1837 | 1838 | } |
| 1838 | 1839 | |
| 1839 | 1840 | // initialize an array to zero |
| 1840 | 1841 | const all_zero = [_]u16{0} ** 10; |
| 1841 | 1842 | |
| 1842 | 1843 | comptime { |
| 1843 | expect(all_zero.len == 10); | |
| 1844 | expect(all_zero[5] == 0); | |
| 1844 | assert(all_zero.len == 10); | |
| 1845 | assert(all_zero[5] == 0); | |
| 1845 | 1846 | } |
| 1846 | 1847 | |
| 1847 | 1848 | // use compile-time code to initialize an array |
| ... | ... | @@ -1861,8 +1862,8 @@ const Point = struct { |
| 1861 | 1862 | }; |
| 1862 | 1863 | |
| 1863 | 1864 | test "compile-time array initialization" { |
| 1864 | expect(fancy_array[4].x == 4); | |
| 1865 | expect(fancy_array[4].y == 8); | |
| 1865 | try expect(fancy_array[4].x == 4); | |
| 1866 | try expect(fancy_array[4].y == 8); | |
| 1866 | 1867 | } |
| 1867 | 1868 | |
| 1868 | 1869 | // call a function to initialize an array |
| ... | ... | @@ -1874,9 +1875,9 @@ fn makePoint(x: i32) Point { |
| 1874 | 1875 | }; |
| 1875 | 1876 | } |
| 1876 | 1877 | test "array initialization with function calls" { |
| 1877 | expect(more_points[4].x == 3); | |
| 1878 | expect(more_points[4].y == 6); | |
| 1879 | expect(more_points.len == 10); | |
| 1878 | try expect(more_points[4].x == 3); | |
| 1879 | try expect(more_points[4].y == 6); | |
| 1880 | try expect(more_points.len == 10); | |
| 1880 | 1881 | } |
| 1881 | 1882 | {#code_end#} |
| 1882 | 1883 | {#see_also|for|Slices#} |
| ... | ... | @@ -1890,10 +1891,10 @@ const expect = std.testing.expect; |
| 1890 | 1891 | |
| 1891 | 1892 | test "anonymous list literal syntax" { |
| 1892 | 1893 | var array: [4]u8 = .{11, 22, 33, 44}; |
| 1893 | expect(array[0] == 11); | |
| 1894 | expect(array[1] == 22); | |
| 1895 | expect(array[2] == 33); | |
| 1896 | expect(array[3] == 44); | |
| 1894 | try expect(array[0] == 11); | |
| 1895 | try expect(array[1] == 22); | |
| 1896 | try expect(array[2] == 33); | |
| 1897 | try expect(array[3] == 44); | |
| 1897 | 1898 | } |
| 1898 | 1899 | {#code_end#} |
| 1899 | 1900 | <p> |
| ... | ... | @@ -1905,15 +1906,15 @@ const std = @import("std"); |
| 1905 | 1906 | const expect = std.testing.expect; |
| 1906 | 1907 | |
| 1907 | 1908 | test "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 | } |
| 1910 | 1911 | |
| 1911 | fn dump(args: anytype) void { | |
| 1912 | expect(args.@"0" == 1234); | |
| 1913 | expect(args.@"1" == 12.34); | |
| 1914 | expect(args.@"2"); | |
| 1915 | expect(args.@"3"[0] == 'h'); | |
| 1916 | expect(args.@"3"[1] == 'i'); | |
| 1912 | fn dump(args: anytype) !void { | |
| 1913 | try expect(args.@"0" == 1234); | |
| 1914 | try expect(args.@"1" == 12.34); | |
| 1915 | try expect(args.@"2"); | |
| 1916 | try expect(args.@"3"[0] == 'h'); | |
| 1917 | try expect(args.@"3"[1] == 'i'); | |
| 1917 | 1918 | } |
| 1918 | 1919 | {#code_end#} |
| 1919 | 1920 | {#header_close#} |
| ... | ... | @@ -1934,13 +1935,13 @@ const mat4x4 = [4][4]f32{ |
| 1934 | 1935 | }; |
| 1935 | 1936 | test "multidimensional arrays" { |
| 1936 | 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); | |
| 1938 | 1939 | |
| 1939 | 1940 | // Here we iterate with for loops. |
| 1940 | 1941 | for (mat4x4) |row, row_index| { |
| 1941 | 1942 | for (row) |cell, column_index| { |
| 1942 | 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 | 1961 | test "null terminated array" { |
| 1961 | 1962 | const array = [_:0]u8 {1, 2, 3, 4}; |
| 1962 | 1963 | |
| 1963 | expect(@TypeOf(array) == [4:0]u8); | |
| 1964 | expect(array.len == 4); | |
| 1965 | expect(array[4] == 0); | |
| 1964 | try expect(@TypeOf(array) == [4:0]u8); | |
| 1965 | try expect(array.len == 4); | |
| 1966 | try expect(array[4] == 0); | |
| 1966 | 1967 | } |
| 1967 | 1968 | {#code_end#} |
| 1968 | 1969 | {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Slices#} |
| ... | ... | @@ -2040,17 +2041,17 @@ test "address of syntax" { |
| 2040 | 2041 | const x_ptr = &x; |
| 2041 | 2042 | |
| 2042 | 2043 | // Dereference a pointer: |
| 2043 | expect(x_ptr.* == 1234); | |
| 2044 | try expect(x_ptr.* == 1234); | |
| 2044 | 2045 | |
| 2045 | 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); | |
| 2047 | 2048 | |
| 2048 | 2049 | // If you want to mutate the value, you'd need an address of a mutable variable: |
| 2049 | 2050 | var y: i32 = 5678; |
| 2050 | 2051 | const y_ptr = &y; |
| 2051 | expect(@TypeOf(y_ptr) == *i32); | |
| 2052 | try expect(@TypeOf(y_ptr) == *i32); | |
| 2052 | 2053 | y_ptr.* += 1; |
| 2053 | expect(y_ptr.* == 5679); | |
| 2054 | try expect(y_ptr.* == 5679); | |
| 2054 | 2055 | } |
| 2055 | 2056 | |
| 2056 | 2057 | test "pointer array access" { |
| ... | ... | @@ -2059,11 +2060,11 @@ test "pointer array access" { |
| 2059 | 2060 | // does not support pointer arithmetic. |
| 2060 | 2061 | var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 2061 | 2062 | const ptr = &array[2]; |
| 2062 | expect(@TypeOf(ptr) == *u8); | |
| 2063 | try expect(@TypeOf(ptr) == *u8); | |
| 2063 | 2064 | |
| 2064 | expect(array[2] == 3); | |
| 2065 | try expect(array[2] == 3); | |
| 2065 | 2066 | ptr.* += 1; |
| 2066 | expect(array[2] == 4); | |
| 2067 | try expect(array[2] == 4); | |
| 2067 | 2068 | } |
| 2068 | 2069 | {#code_end#} |
| 2069 | 2070 | <p> |
| ... | ... | @@ -2081,11 +2082,11 @@ const expect = @import("std").testing.expect; |
| 2081 | 2082 | test "pointer slicing" { |
| 2082 | 2083 | var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 2083 | 2084 | const slice = array[2..4]; |
| 2084 | expect(slice.len == 2); | |
| 2085 | try expect(slice.len == 2); | |
| 2085 | 2086 | |
| 2086 | expect(array[3] == 4); | |
| 2087 | try expect(array[3] == 4); | |
| 2087 | 2088 | slice[1] += 1; |
| 2088 | expect(array[3] == 5); | |
| 2089 | try expect(array[3] == 5); | |
| 2089 | 2090 | } |
| 2090 | 2091 | {#code_end#} |
| 2091 | 2092 | <p>Pointers work at compile-time too, as long as the code does not depend on |
| ... | ... | @@ -2099,7 +2100,7 @@ test "comptime pointers" { |
| 2099 | 2100 | const ptr = &x; |
| 2100 | 2101 | ptr.* += 1; |
| 2101 | 2102 | x += 1; |
| 2102 | expect(ptr.* == 3); | |
| 2103 | try expect(ptr.* == 3); | |
| 2103 | 2104 | } |
| 2104 | 2105 | } |
| 2105 | 2106 | {#code_end#} |
| ... | ... | @@ -2111,8 +2112,8 @@ const expect = @import("std").testing.expect; |
| 2111 | 2112 | test "@ptrToInt and @intToPtr" { |
| 2112 | 2113 | const ptr = @intToPtr(*i32, 0xdeadbee0); |
| 2113 | 2114 | const addr = @ptrToInt(ptr); |
| 2114 | expect(@TypeOf(addr) == usize); | |
| 2115 | expect(addr == 0xdeadbee0); | |
| 2115 | try expect(@TypeOf(addr) == usize); | |
| 2116 | try expect(addr == 0xdeadbee0); | |
| 2116 | 2117 | } |
| 2117 | 2118 | {#code_end#} |
| 2118 | 2119 | <p>Zig is able to preserve memory addresses in comptime code, as long as |
| ... | ... | @@ -2126,8 +2127,8 @@ test "comptime @intToPtr" { |
| 2126 | 2127 | // ptr is never dereferenced. |
| 2127 | 2128 | const ptr = @intToPtr(*i32, 0xdeadbee0); |
| 2128 | 2129 | const addr = @ptrToInt(ptr); |
| 2129 | expect(@TypeOf(addr) == usize); | |
| 2130 | expect(addr == 0xdeadbee0); | |
| 2130 | try expect(@TypeOf(addr) == usize); | |
| 2131 | try expect(addr == 0xdeadbee0); | |
| 2131 | 2132 | } |
| 2132 | 2133 | } |
| 2133 | 2134 | {#code_end#} |
| ... | ... | @@ -2142,7 +2143,7 @@ const expect = @import("std").testing.expect; |
| 2142 | 2143 | |
| 2143 | 2144 | test "volatile" { |
| 2144 | 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 | 2148 | {#code_end#} |
| 2148 | 2149 | <p> |
| ... | ... | @@ -2163,20 +2164,20 @@ const expect = std.testing.expect; |
| 2163 | 2164 | test "pointer casting" { |
| 2164 | 2165 | const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 }; |
| 2165 | 2166 | const u32_ptr = @ptrCast(*const u32, &bytes); |
| 2166 | expect(u32_ptr.* == 0x12121212); | |
| 2167 | try expect(u32_ptr.* == 0x12121212); | |
| 2167 | 2168 | |
| 2168 | 2169 | // Even this example is contrived - there are better ways to do the above than |
| 2169 | 2170 | // pointer casting. For example, using a slice narrowing cast: |
| 2170 | 2171 | const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0]; |
| 2171 | expect(u32_value == 0x12121212); | |
| 2172 | try expect(u32_value == 0x12121212); | |
| 2172 | 2173 | |
| 2173 | 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 | } |
| 2176 | 2177 | |
| 2177 | 2178 | test "pointer child type" { |
| 2178 | 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 | 2182 | {#code_end#} |
| 2182 | 2183 | {#header_open|Alignment#} |
| ... | ... | @@ -2201,10 +2202,10 @@ const expect = std.testing.expect; |
| 2201 | 2202 | test "variable alignment" { |
| 2202 | 2203 | var x: i32 = 1234; |
| 2203 | 2204 | const align_of_i32 = @alignOf(@TypeOf(x)); |
| 2204 | expect(@TypeOf(&x) == *i32); | |
| 2205 | expect(*i32 == *align(align_of_i32) i32); | |
| 2205 | try expect(@TypeOf(&x) == *i32); | |
| 2206 | try expect(*i32 == *align(align_of_i32) i32); | |
| 2206 | 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 | 2211 | {#code_end#} |
| ... | ... | @@ -2222,11 +2223,11 @@ const expect = @import("std").testing.expect; |
| 2222 | 2223 | var foo: u8 align(4) = 100; |
| 2223 | 2224 | |
| 2224 | 2225 | test "global variable alignment" { |
| 2225 | expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 2226 | expect(@TypeOf(&foo) == *align(4) u8); | |
| 2226 | try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 2227 | try expect(@TypeOf(&foo) == *align(4) u8); | |
| 2227 | 2228 | const as_pointer_to_array: *[1]u8 = &foo; |
| 2228 | 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 | } |
| 2231 | 2232 | |
| 2232 | 2233 | fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } |
| ... | ... | @@ -2234,9 +2235,9 @@ fn noop1() align(1) void {} |
| 2234 | 2235 | fn noop4() align(4) void {} |
| 2235 | 2236 | |
| 2236 | 2237 | test "function alignment" { |
| 2237 | expect(derp() == 1234); | |
| 2238 | expect(@TypeOf(noop1) == fn() align(1) void); | |
| 2239 | expect(@TypeOf(noop4) == fn() align(4) void); | |
| 2238 | try expect(derp() == 1234); | |
| 2239 | try expect(@TypeOf(noop1) == fn() align(1) void); | |
| 2240 | try expect(@TypeOf(noop4) == fn() align(4) void); | |
| 2240 | 2241 | noop1(); |
| 2241 | 2242 | noop4(); |
| 2242 | 2243 | } |
| ... | ... | @@ -2253,7 +2254,7 @@ const std = @import("std"); |
| 2253 | 2254 | test "pointer alignment safety" { |
| 2254 | 2255 | var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; |
| 2255 | 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 | } |
| 2258 | 2259 | fn foo(bytes: []u8) u32 { |
| 2259 | 2260 | const slice4 = bytes[1..5]; |
| ... | ... | @@ -2279,7 +2280,7 @@ const expect = std.testing.expect; |
| 2279 | 2280 | test "allowzero" { |
| 2280 | 2281 | var zero: usize = 0; |
| 2281 | 2282 | var ptr = @intToPtr(*allowzero i32, zero); |
| 2282 | expect(@ptrToInt(ptr) == 0); | |
| 2283 | try expect(@ptrToInt(ptr) == 0); | |
| 2283 | 2284 | } |
| 2284 | 2285 | {#code_end#} |
| 2285 | 2286 | {#header_close#} |
| ... | ... | @@ -2321,14 +2322,14 @@ test "basic slices" { |
| 2321 | 2322 | // Both can be accessed with the `len` field. |
| 2322 | 2323 | var known_at_runtime_zero: usize = 0; |
| 2323 | 2324 | const slice = array[known_at_runtime_zero..array.len]; |
| 2324 | expect(&slice[0] == &array[0]); | |
| 2325 | expect(slice.len == array.len); | |
| 2325 | try expect(&slice[0] == &array[0]); | |
| 2326 | try expect(slice.len == array.len); | |
| 2326 | 2327 | |
| 2327 | 2328 | // Using the address-of operator on a slice gives a single-item pointer, |
| 2328 | 2329 | // while using the `ptr` field gives a many-item pointer. |
| 2329 | expect(@TypeOf(slice.ptr) == [*]i32); | |
| 2330 | expect(@TypeOf(&slice[0]) == *i32); | |
| 2331 | expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); | |
| 2330 | try expect(@TypeOf(slice.ptr) == [*]i32); | |
| 2331 | try expect(@TypeOf(&slice[0]) == *i32); | |
| 2332 | try expect(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); | |
| 2332 | 2333 | |
| 2333 | 2334 | // Slices have array bounds checking. If you try to access something out |
| 2334 | 2335 | // of bounds, you'll get a safety check failure: |
| ... | ... | @@ -2362,7 +2363,7 @@ test "using slices for strings" { |
| 2362 | 2363 | // Generally, you can use UTF-8 and not worry about whether something is a |
| 2363 | 2364 | // string. If you don't need to deal with individual characters, no need |
| 2364 | 2365 | // to decode. |
| 2365 | expect(mem.eql(u8, hello_world, "hello 世界")); | |
| 2366 | try expect(mem.eql(u8, hello_world, "hello 世界")); | |
| 2366 | 2367 | } |
| 2367 | 2368 | |
| 2368 | 2369 | test "slice pointer" { |
| ... | ... | @@ -2372,16 +2373,16 @@ test "slice pointer" { |
| 2372 | 2373 | // You can use slicing syntax to convert a pointer into a slice: |
| 2373 | 2374 | const slice = ptr[0..5]; |
| 2374 | 2375 | slice[2] = 3; |
| 2375 | expect(slice[2] == 3); | |
| 2376 | try expect(slice[2] == 3); | |
| 2376 | 2377 | // The slice is mutable because we sliced a mutable pointer. |
| 2377 | 2378 | // Furthermore, it is actually a pointer to an array, since the start |
| 2378 | 2379 | // and end indexes were both comptime-known. |
| 2379 | expect(@TypeOf(slice) == *[5]u8); | |
| 2380 | try expect(@TypeOf(slice) == *[5]u8); | |
| 2380 | 2381 | |
| 2381 | 2382 | // You can also slice a slice: |
| 2382 | 2383 | const slice2 = slice[2..3]; |
| 2383 | expect(slice2.len == 1); | |
| 2384 | expect(slice2[0] == 3); | |
| 2384 | try expect(slice2.len == 1); | |
| 2385 | try expect(slice2[0] == 3); | |
| 2385 | 2386 | } |
| 2386 | 2387 | {#code_end#} |
| 2387 | 2388 | {#see_also|Pointers|for|Arrays#} |
| ... | ... | @@ -2400,8 +2401,8 @@ const expect = std.testing.expect; |
| 2400 | 2401 | test "null terminated slice" { |
| 2401 | 2402 | const slice: [:0]const u8 = "hello"; |
| 2402 | 2403 | |
| 2403 | expect(slice.len == 5); | |
| 2404 | expect(slice[5] == 0); | |
| 2404 | try expect(slice.len == 5); | |
| 2405 | try expect(slice[5] == 0); | |
| 2405 | 2406 | } |
| 2406 | 2407 | {#code_end#} |
| 2407 | 2408 | {#see_also|Sentinel-Terminated Pointers|Sentinel-Terminated Arrays#} |
| ... | ... | @@ -2463,12 +2464,12 @@ const expect = @import("std").testing.expect; |
| 2463 | 2464 | test "dot product" { |
| 2464 | 2465 | const v1 = Vec3.init(1.0, 0.0, 0.0); |
| 2465 | 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); | |
| 2467 | 2468 | |
| 2468 | 2469 | // Other than being available to call with dot syntax, struct methods are |
| 2469 | 2470 | // not special. You can reference them as any other declaration inside |
| 2470 | 2471 | // the struct: |
| 2471 | expect(Vec3.dot(v1, v2) == 0.0); | |
| 2472 | try expect(Vec3.dot(v1, v2) == 0.0); | |
| 2472 | 2473 | } |
| 2473 | 2474 | |
| 2474 | 2475 | // Structs can have global declarations. |
| ... | ... | @@ -2477,8 +2478,8 @@ const Empty = struct { |
| 2477 | 2478 | pub const PI = 3.14; |
| 2478 | 2479 | }; |
| 2479 | 2480 | test "struct namespaced variable" { |
| 2480 | expect(Empty.PI == 3.14); | |
| 2481 | expect(@sizeOf(Empty) == 0); | |
| 2481 | try expect(Empty.PI == 3.14); | |
| 2482 | try expect(@sizeOf(Empty) == 0); | |
| 2482 | 2483 | |
| 2483 | 2484 | // you can still instantiate an empty struct |
| 2484 | 2485 | const does_nothing = Empty {}; |
| ... | ... | @@ -2496,7 +2497,7 @@ test "field parent pointer" { |
| 2496 | 2497 | .y = 0.5678, |
| 2497 | 2498 | }; |
| 2498 | 2499 | setYBasedOnX(&point.x, 0.9); |
| 2499 | expect(point.y == 0.9); | |
| 2500 | try expect(point.y == 0.9); | |
| 2500 | 2501 | } |
| 2501 | 2502 | |
| 2502 | 2503 | // 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 | 2519 | test "linked list" { |
| 2519 | 2520 | // Functions called at compile-time are memoized. This means you can |
| 2520 | 2521 | // do this: |
| 2521 | expect(LinkedList(i32) == LinkedList(i32)); | |
| 2522 | try expect(LinkedList(i32) == LinkedList(i32)); | |
| 2522 | 2523 | |
| 2523 | 2524 | var list = LinkedList(i32) { |
| 2524 | 2525 | .first = null, |
| 2525 | 2526 | .last = null, |
| 2526 | 2527 | .len = 0, |
| 2527 | 2528 | }; |
| 2528 | expect(list.len == 0); | |
| 2529 | try expect(list.len == 0); | |
| 2529 | 2530 | |
| 2530 | 2531 | // Since types are first class values you can instantiate the type |
| 2531 | 2532 | // by assigning it to a variable: |
| 2532 | 2533 | const ListOfInts = LinkedList(i32); |
| 2533 | expect(ListOfInts == LinkedList(i32)); | |
| 2534 | try expect(ListOfInts == LinkedList(i32)); | |
| 2534 | 2535 | |
| 2535 | 2536 | var node = ListOfInts.Node { |
| 2536 | 2537 | .prev = null, |
| ... | ... | @@ -2542,7 +2543,7 @@ test "linked list" { |
| 2542 | 2543 | .last = &node, |
| 2543 | 2544 | .len = 1, |
| 2544 | 2545 | }; |
| 2545 | expect(list2.first.?.data == 1234); | |
| 2546 | try expect(list2.first.?.data == 1234); | |
| 2546 | 2547 | } |
| 2547 | 2548 | {#code_end#} |
| 2548 | 2549 | |
| ... | ... | @@ -2615,25 +2616,25 @@ const Divided = packed struct { |
| 2615 | 2616 | }; |
| 2616 | 2617 | |
| 2617 | 2618 | test "@bitCast between packed structs" { |
| 2618 | doTheTest(); | |
| 2619 | comptime doTheTest(); | |
| 2619 | try doTheTest(); | |
| 2620 | comptime try doTheTest(); | |
| 2620 | 2621 | } |
| 2621 | 2622 | |
| 2622 | fn doTheTest() void { | |
| 2623 | expect(@sizeOf(Full) == 2); | |
| 2624 | expect(@sizeOf(Divided) == 2); | |
| 2623 | fn doTheTest() !void { | |
| 2624 | try expect(@sizeOf(Full) == 2); | |
| 2625 | try expect(@sizeOf(Divided) == 2); | |
| 2625 | 2626 | var full = Full{ .number = 0x1234 }; |
| 2626 | 2627 | var divided = @bitCast(Divided, full); |
| 2627 | 2628 | switch (builtin.endian) { |
| 2628 | 2629 | .Big => { |
| 2629 | expect(divided.half1 == 0x12); | |
| 2630 | expect(divided.quarter3 == 0x3); | |
| 2631 | expect(divided.quarter4 == 0x4); | |
| 2630 | try expect(divided.half1 == 0x12); | |
| 2631 | try expect(divided.quarter3 == 0x3); | |
| 2632 | try expect(divided.quarter4 == 0x4); | |
| 2632 | 2633 | }, |
| 2633 | 2634 | .Little => { |
| 2634 | expect(divided.half1 == 0x34); | |
| 2635 | expect(divided.quarter3 == 0x2); | |
| 2636 | expect(divided.quarter4 == 0x1); | |
| 2635 | try expect(divided.half1 == 0x34); | |
| 2636 | try expect(divided.quarter3 == 0x2); | |
| 2637 | try expect(divided.quarter4 == 0x1); | |
| 2637 | 2638 | }, |
| 2638 | 2639 | } |
| 2639 | 2640 | } |
| ... | ... | @@ -2659,7 +2660,7 @@ var foo = BitField{ |
| 2659 | 2660 | |
| 2660 | 2661 | test "pointer to non-byte-aligned field" { |
| 2661 | 2662 | const ptr = &foo.b; |
| 2662 | expect(ptr.* == 2); | |
| 2663 | try expect(ptr.* == 2); | |
| 2663 | 2664 | } |
| 2664 | 2665 | {#code_end#} |
| 2665 | 2666 | <p> |
| ... | ... | @@ -2683,7 +2684,7 @@ var bit_field = BitField{ |
| 2683 | 2684 | }; |
| 2684 | 2685 | |
| 2685 | 2686 | test "pointer to non-bit-aligned field" { |
| 2686 | expect(bar(&bit_field.b) == 2); | |
| 2687 | try expect(bar(&bit_field.b) == 2); | |
| 2687 | 2688 | } |
| 2688 | 2689 | |
| 2689 | 2690 | fn bar(x: *const u3) u3 { |
| ... | ... | @@ -2714,8 +2715,8 @@ var bit_field = BitField{ |
| 2714 | 2715 | }; |
| 2715 | 2716 | |
| 2716 | 2717 | test "pointer to non-bit-aligned field" { |
| 2717 | expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b)); | |
| 2718 | expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c)); | |
| 2718 | try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.b)); | |
| 2719 | try expect(@ptrToInt(&bit_field.a) == @ptrToInt(&bit_field.c)); | |
| 2719 | 2720 | } |
| 2720 | 2721 | {#code_end#} |
| 2721 | 2722 | <p> |
| ... | ... | @@ -2733,13 +2734,13 @@ const BitField = packed struct { |
| 2733 | 2734 | |
| 2734 | 2735 | test "pointer to non-bit-aligned field" { |
| 2735 | 2736 | comptime { |
| 2736 | expect(@bitOffsetOf(BitField, "a") == 0); | |
| 2737 | expect(@bitOffsetOf(BitField, "b") == 3); | |
| 2738 | expect(@bitOffsetOf(BitField, "c") == 6); | |
| 2737 | try expect(@bitOffsetOf(BitField, "a") == 0); | |
| 2738 | try expect(@bitOffsetOf(BitField, "b") == 3); | |
| 2739 | try expect(@bitOffsetOf(BitField, "c") == 6); | |
| 2739 | 2740 | |
| 2740 | expect(@byteOffsetOf(BitField, "a") == 0); | |
| 2741 | expect(@byteOffsetOf(BitField, "b") == 0); | |
| 2742 | expect(@byteOffsetOf(BitField, "c") == 0); | |
| 2741 | try expect(@byteOffsetOf(BitField, "a") == 0); | |
| 2742 | try expect(@byteOffsetOf(BitField, "b") == 0); | |
| 2743 | try expect(@byteOffsetOf(BitField, "c") == 0); | |
| 2743 | 2744 | } |
| 2744 | 2745 | } |
| 2745 | 2746 | {#code_end#} |
| ... | ... | @@ -2776,9 +2777,9 @@ test "aligned struct fields" { |
| 2776 | 2777 | }; |
| 2777 | 2778 | var foo = S{ .a = 1, .b = 2 }; |
| 2778 | 2779 | |
| 2779 | expectEqual(64, @alignOf(S)); | |
| 2780 | expectEqual(*align(2) u32, @TypeOf(&foo.a)); | |
| 2781 | expectEqual(*align(64) u32, @TypeOf(&foo.b)); | |
| 2780 | try expectEqual(64, @alignOf(S)); | |
| 2781 | try expectEqual(*align(2) u32, @TypeOf(&foo.a)); | |
| 2782 | try expectEqual(*align(64) u32, @TypeOf(&foo.b)); | |
| 2782 | 2783 | } |
| 2783 | 2784 | {#code_end#} |
| 2784 | 2785 | <p> |
| ... | ... | @@ -2834,8 +2835,8 @@ test "anonymous struct literal" { |
| 2834 | 2835 | .x = 13, |
| 2835 | 2836 | .y = 67, |
| 2836 | 2837 | }; |
| 2837 | expect(pt.x == 13); | |
| 2838 | expect(pt.y == 67); | |
| 2838 | try expect(pt.x == 13); | |
| 2839 | try expect(pt.y == 67); | |
| 2839 | 2840 | } |
| 2840 | 2841 | {#code_end#} |
| 2841 | 2842 | <p> |
| ... | ... | @@ -2847,7 +2848,7 @@ const std = @import("std"); |
| 2847 | 2848 | const expect = std.testing.expect; |
| 2848 | 2849 | |
| 2849 | 2850 | test "fully anonymous struct" { |
| 2850 | dump(.{ | |
| 2851 | try dump(.{ | |
| 2851 | 2852 | .int = @as(u32, 1234), |
| 2852 | 2853 | .float = @as(f64, 12.34), |
| 2853 | 2854 | .b = true, |
| ... | ... | @@ -2855,12 +2856,12 @@ test "fully anonymous struct" { |
| 2855 | 2856 | }); |
| 2856 | 2857 | } |
| 2857 | 2858 | |
| 2858 | fn dump(args: anytype) void { | |
| 2859 | expect(args.int == 1234); | |
| 2860 | expect(args.float == 12.34); | |
| 2861 | expect(args.b); | |
| 2862 | expect(args.s[0] == 'h'); | |
| 2863 | expect(args.s[1] == 'i'); | |
| 2859 | fn dump(args: anytype) !void { | |
| 2860 | try expect(args.int == 1234); | |
| 2861 | try expect(args.float == 12.34); | |
| 2862 | try expect(args.b); | |
| 2863 | try expect(args.s[0] == 'h'); | |
| 2864 | try expect(args.s[1] == 'i'); | |
| 2864 | 2865 | } |
| 2865 | 2866 | {#code_end#} |
| 2866 | 2867 | <p> |
| ... | ... | @@ -2884,14 +2885,14 @@ test "tuple" { |
| 2884 | 2885 | true, |
| 2885 | 2886 | "hi", |
| 2886 | 2887 | } ++ .{false} ** 2; |
| 2887 | expect(values[0] == 1234); | |
| 2888 | expect(values[4] == false); | |
| 2888 | try expect(values[0] == 1234); | |
| 2889 | try expect(values[4] == false); | |
| 2889 | 2890 | inline for (values) |v, i| { |
| 2890 | 2891 | if (i != 2) continue; |
| 2891 | expect(v); | |
| 2892 | try expect(v); | |
| 2892 | 2893 | } |
| 2893 | expect(values.len == 6); | |
| 2894 | expect(values.@"3"[0] == 'h'); | |
| 2894 | try expect(values.len == 6); | |
| 2895 | try expect(values.@"3"[0] == 'h'); | |
| 2895 | 2896 | } |
| 2896 | 2897 | {#code_end#} |
| 2897 | 2898 | {#header_close#} |
| ... | ... | @@ -2922,9 +2923,9 @@ const Value = enum(u2) { |
| 2922 | 2923 | // Now you can cast between u2 and Value. |
| 2923 | 2924 | // The ordinal value starts from 0, counting up for each member. |
| 2924 | 2925 | test "enum ordinal value" { |
| 2925 | expect(@enumToInt(Value.zero) == 0); | |
| 2926 | expect(@enumToInt(Value.one) == 1); | |
| 2927 | expect(@enumToInt(Value.two) == 2); | |
| 2926 | try expect(@enumToInt(Value.zero) == 0); | |
| 2927 | try expect(@enumToInt(Value.one) == 1); | |
| 2928 | try expect(@enumToInt(Value.two) == 2); | |
| 2928 | 2929 | } |
| 2929 | 2930 | |
| 2930 | 2931 | // You can override the ordinal value for an enum. |
| ... | ... | @@ -2934,9 +2935,9 @@ const Value2 = enum(u32) { |
| 2934 | 2935 | million = 1000000, |
| 2935 | 2936 | }; |
| 2936 | 2937 | test "set enum ordinal value" { |
| 2937 | expect(@enumToInt(Value2.hundred) == 100); | |
| 2938 | expect(@enumToInt(Value2.thousand) == 1000); | |
| 2939 | expect(@enumToInt(Value2.million) == 1000000); | |
| 2938 | try expect(@enumToInt(Value2.hundred) == 100); | |
| 2939 | try expect(@enumToInt(Value2.thousand) == 1000); | |
| 2940 | try expect(@enumToInt(Value2.million) == 1000000); | |
| 2940 | 2941 | } |
| 2941 | 2942 | |
| 2942 | 2943 | // Enums can have methods, the same as structs and unions. |
| ... | ... | @@ -2954,7 +2955,7 @@ const Suit = enum { |
| 2954 | 2955 | }; |
| 2955 | 2956 | test "enum method" { |
| 2956 | 2957 | const p = Suit.spades; |
| 2957 | expect(!p.isClubs()); | |
| 2958 | try expect(!p.isClubs()); | |
| 2958 | 2959 | } |
| 2959 | 2960 | |
| 2960 | 2961 | // An enum variant of different types can be switched upon. |
| ... | ... | @@ -2970,7 +2971,7 @@ test "enum variant switch" { |
| 2970 | 2971 | Foo.number => "this is a number", |
| 2971 | 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 | } |
| 2975 | 2976 | |
| 2976 | 2977 | // @typeInfo can be used to access the integer tag type of an enum. |
| ... | ... | @@ -2981,18 +2982,18 @@ const Small = enum { |
| 2981 | 2982 | four, |
| 2982 | 2983 | }; |
| 2983 | 2984 | test "std.meta.Tag" { |
| 2984 | expect(@typeInfo(Small).Enum.tag_type == u2); | |
| 2985 | try expect(@typeInfo(Small).Enum.tag_type == u2); | |
| 2985 | 2986 | } |
| 2986 | 2987 | |
| 2987 | 2988 | // @typeInfo tells us the field count and the fields names: |
| 2988 | 2989 | test "@typeInfo" { |
| 2989 | expect(@typeInfo(Small).Enum.fields.len == 4); | |
| 2990 | expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two")); | |
| 2990 | try expect(@typeInfo(Small).Enum.fields.len == 4); | |
| 2991 | try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two")); | |
| 2991 | 2992 | } |
| 2992 | 2993 | |
| 2993 | 2994 | // @tagName gives a []const u8 representation of an enum value: |
| 2994 | 2995 | test "@tagName" { |
| 2995 | expect(mem.eql(u8, @tagName(Small.three), "three")); | |
| 2996 | try expect(mem.eql(u8, @tagName(Small.three), "three")); | |
| 2996 | 2997 | } |
| 2997 | 2998 | {#code_end#} |
| 2998 | 2999 | {#see_also|@typeInfo|@tagName|@sizeOf#} |
| ... | ... | @@ -3027,7 +3028,7 @@ test "packed enum" { |
| 3027 | 3028 | two, |
| 3028 | 3029 | three, |
| 3029 | 3030 | }; |
| 3030 | std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); | |
| 3031 | try std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); | |
| 3031 | 3032 | } |
| 3032 | 3033 | {#code_end#} |
| 3033 | 3034 | <p>This makes the enum eligible to be in a {#link|packed struct#}.</p> |
| ... | ... | @@ -3050,7 +3051,7 @@ const Color = enum { |
| 3050 | 3051 | test "enum literals" { |
| 3051 | 3052 | const color1: Color = .auto; |
| 3052 | 3053 | const color2 = Color.auto; |
| 3053 | expect(color1 == color2); | |
| 3054 | try expect(color1 == color2); | |
| 3054 | 3055 | } |
| 3055 | 3056 | |
| 3056 | 3057 | test "switch using enum literals" { |
| ... | ... | @@ -3060,7 +3061,7 @@ test "switch using enum literals" { |
| 3060 | 3061 | .on => true, |
| 3061 | 3062 | .off => false, |
| 3062 | 3063 | }; |
| 3063 | expect(result); | |
| 3064 | try expect(result); | |
| 3064 | 3065 | } |
| 3065 | 3066 | {#code_end#} |
| 3066 | 3067 | {#header_close#} |
| ... | ... | @@ -3096,12 +3097,12 @@ test "switch on non-exhaustive enum" { |
| 3096 | 3097 | .three => false, |
| 3097 | 3098 | _ => false, |
| 3098 | 3099 | }; |
| 3099 | expect(result); | |
| 3100 | try expect(result); | |
| 3100 | 3101 | const is_one = switch (number) { |
| 3101 | 3102 | .one => true, |
| 3102 | 3103 | else => false, |
| 3103 | 3104 | }; |
| 3104 | expect(is_one); | |
| 3105 | try expect(is_one); | |
| 3105 | 3106 | } |
| 3106 | 3107 | {#code_end#} |
| 3107 | 3108 | {#header_close#} |
| ... | ... | @@ -3141,9 +3142,9 @@ const Payload = union { |
| 3141 | 3142 | }; |
| 3142 | 3143 | test "simple union" { |
| 3143 | 3144 | var payload = Payload{ .int = 1234 }; |
| 3144 | expect(payload.int == 1234); | |
| 3145 | try expect(payload.int == 1234); | |
| 3145 | 3146 | payload = Payload{ .float = 12.34 }; |
| 3146 | expect(payload.float == 12.34); | |
| 3147 | try expect(payload.float == 12.34); | |
| 3147 | 3148 | } |
| 3148 | 3149 | {#code_end#} |
| 3149 | 3150 | <p> |
| ... | ... | @@ -3174,24 +3175,24 @@ const ComplexType = union(ComplexTypeTag) { |
| 3174 | 3175 | |
| 3175 | 3176 | test "switch on tagged union" { |
| 3176 | 3177 | const c = ComplexType{ .ok = 42 }; |
| 3177 | expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); | |
| 3178 | try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); | |
| 3178 | 3179 | |
| 3179 | 3180 | switch (c) { |
| 3180 | ComplexTypeTag.ok => |value| expect(value == 42), | |
| 3181 | ComplexTypeTag.ok => |value| try expect(value == 42), | |
| 3181 | 3182 | ComplexTypeTag.not_ok => unreachable, |
| 3182 | 3183 | } |
| 3183 | 3184 | } |
| 3184 | 3185 | |
| 3185 | 3186 | test "get tag type" { |
| 3186 | expect(std.meta.Tag(ComplexType) == ComplexTypeTag); | |
| 3187 | try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); | |
| 3187 | 3188 | } |
| 3188 | 3189 | |
| 3189 | 3190 | test "coerce to enum" { |
| 3190 | 3191 | const c1 = ComplexType{ .ok = 42 }; |
| 3191 | 3192 | const c2 = ComplexType.not_ok; |
| 3192 | 3193 | |
| 3193 | expect(c1 == .ok); | |
| 3194 | expect(c2 == .not_ok); | |
| 3194 | try expect(c1 == .ok); | |
| 3195 | try expect(c2 == .not_ok); | |
| 3195 | 3196 | } |
| 3196 | 3197 | {#code_end#} |
| 3197 | 3198 | <p>In order to modify the payload of a tagged union in a switch expression, |
| ... | ... | @@ -3212,14 +3213,14 @@ const ComplexType = union(ComplexTypeTag) { |
| 3212 | 3213 | |
| 3213 | 3214 | test "modify tagged union in switch" { |
| 3214 | 3215 | var c = ComplexType{ .ok = 42 }; |
| 3215 | expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); | |
| 3216 | try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); | |
| 3216 | 3217 | |
| 3217 | 3218 | switch (c) { |
| 3218 | 3219 | ComplexTypeTag.ok => |*value| value.* += 1, |
| 3219 | 3220 | ComplexTypeTag.not_ok => unreachable, |
| 3220 | 3221 | } |
| 3221 | 3222 | |
| 3222 | expect(c.ok == 43); | |
| 3223 | try expect(c.ok == 43); | |
| 3223 | 3224 | } |
| 3224 | 3225 | {#code_end#} |
| 3225 | 3226 | <p> |
| ... | ... | @@ -3250,8 +3251,8 @@ test "union method" { |
| 3250 | 3251 | var v1 = Variant{ .int = 1 }; |
| 3251 | 3252 | var v2 = Variant{ .boolean = false }; |
| 3252 | 3253 | |
| 3253 | expect(v1.truthy()); | |
| 3254 | expect(!v2.truthy()); | |
| 3254 | try expect(v1.truthy()); | |
| 3255 | try expect(!v2.truthy()); | |
| 3255 | 3256 | } |
| 3256 | 3257 | {#code_end#} |
| 3257 | 3258 | <p> |
| ... | ... | @@ -3268,7 +3269,7 @@ const Small2 = union(enum) { |
| 3268 | 3269 | c: u8, |
| 3269 | 3270 | }; |
| 3270 | 3271 | test "@tagName" { |
| 3271 | expect(std.mem.eql(u8, @tagName(Small2.a), "a")); | |
| 3272 | try expect(std.mem.eql(u8, @tagName(Small2.a), "a")); | |
| 3272 | 3273 | } |
| 3273 | 3274 | {#code_end#} |
| 3274 | 3275 | {#header_close#} |
| ... | ... | @@ -3301,8 +3302,8 @@ const Number = union { |
| 3301 | 3302 | test "anonymous union literal syntax" { |
| 3302 | 3303 | var i: Number = .{.int = 42}; |
| 3303 | 3304 | var f = makeNumber(); |
| 3304 | expect(i.int == 42); | |
| 3305 | expect(f.float == 12.34); | |
| 3305 | try expect(i.int == 42); | |
| 3306 | try expect(f.float == 12.34); | |
| 3306 | 3307 | } |
| 3307 | 3308 | |
| 3308 | 3309 | fn makeNumber() Number { |
| ... | ... | @@ -3364,8 +3365,8 @@ test "labeled break from labeled block expression" { |
| 3364 | 3365 | y += 1; |
| 3365 | 3366 | break :blk y; |
| 3366 | 3367 | }; |
| 3367 | expect(x == 124); | |
| 3368 | expect(y == 124); | |
| 3368 | try expect(x == 124); | |
| 3369 | try expect(y == 124); | |
| 3369 | 3370 | } |
| 3370 | 3371 | {#code_end#} |
| 3371 | 3372 | <p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p> |
| ... | ... | @@ -3443,7 +3444,7 @@ test "switch simple" { |
| 3443 | 3444 | else => 9, |
| 3444 | 3445 | }; |
| 3445 | 3446 | |
| 3446 | expect(b == 1); | |
| 3447 | try expect(b == 1); | |
| 3447 | 3448 | } |
| 3448 | 3449 | |
| 3449 | 3450 | // Switch expressions can be used outside a function: |
| ... | ... | @@ -3506,8 +3507,8 @@ test "switch on tagged union" { |
| 3506 | 3507 | Item.d => 8, |
| 3507 | 3508 | }; |
| 3508 | 3509 | |
| 3509 | expect(b == 6); | |
| 3510 | expect(a.c.x == 2); | |
| 3510 | try expect(b == 6); | |
| 3511 | try expect(a.c.x == 2); | |
| 3511 | 3512 | } |
| 3512 | 3513 | {#code_end#} |
| 3513 | 3514 | {#see_also|comptime|enum|@compileError|Compile Variables#} |
| ... | ... | @@ -3556,7 +3557,7 @@ test "enum literals with switch" { |
| 3556 | 3557 | .on => false, |
| 3557 | 3558 | .off => true, |
| 3558 | 3559 | }; |
| 3559 | expect(result); | |
| 3560 | try expect(result); | |
| 3560 | 3561 | } |
| 3561 | 3562 | {#code_end#} |
| 3562 | 3563 | {#header_close#} |
| ... | ... | @@ -3575,7 +3576,7 @@ test "while basic" { |
| 3575 | 3576 | while (i < 10) { |
| 3576 | 3577 | i += 1; |
| 3577 | 3578 | } |
| 3578 | expect(i == 10); | |
| 3579 | try expect(i == 10); | |
| 3579 | 3580 | } |
| 3580 | 3581 | {#code_end#} |
| 3581 | 3582 | <p> |
| ... | ... | @@ -3591,7 +3592,7 @@ test "while break" { |
| 3591 | 3592 | break; |
| 3592 | 3593 | i += 1; |
| 3593 | 3594 | } |
| 3594 | expect(i == 10); | |
| 3595 | try expect(i == 10); | |
| 3595 | 3596 | } |
| 3596 | 3597 | {#code_end#} |
| 3597 | 3598 | <p> |
| ... | ... | @@ -3608,7 +3609,7 @@ test "while continue" { |
| 3608 | 3609 | continue; |
| 3609 | 3610 | break; |
| 3610 | 3611 | } |
| 3611 | expect(i == 10); | |
| 3612 | try expect(i == 10); | |
| 3612 | 3613 | } |
| 3613 | 3614 | {#code_end#} |
| 3614 | 3615 | <p> |
| ... | ... | @@ -3621,7 +3622,7 @@ const expect = @import("std").testing.expect; |
| 3621 | 3622 | test "while loop continue expression" { |
| 3622 | 3623 | var i: usize = 0; |
| 3623 | 3624 | while (i < 10) : (i += 1) {} |
| 3624 | expect(i == 10); | |
| 3625 | try expect(i == 10); | |
| 3625 | 3626 | } |
| 3626 | 3627 | |
| 3627 | 3628 | test "while loop continue expression, more complicated" { |
| ... | ... | @@ -3629,7 +3630,7 @@ test "while loop continue expression, more complicated" { |
| 3629 | 3630 | var j: usize = 1; |
| 3630 | 3631 | while (i * j < 2000) : ({ i *= 2; j *= 3; }) { |
| 3631 | 3632 | const my_ij = i * j; |
| 3632 | expect(my_ij < 2000); | |
| 3633 | try expect(my_ij < 2000); | |
| 3633 | 3634 | } |
| 3634 | 3635 | } |
| 3635 | 3636 | {#code_end#} |
| ... | ... | @@ -3648,8 +3649,8 @@ test "while loop continue expression, more complicated" { |
| 3648 | 3649 | const expect = @import("std").testing.expect; |
| 3649 | 3650 | |
| 3650 | 3651 | test "while else" { |
| 3651 | expect(rangeHasNumber(0, 10, 5)); | |
| 3652 | expect(!rangeHasNumber(0, 10, 15)); | |
| 3652 | try expect(rangeHasNumber(0, 10, 5)); | |
| 3653 | try expect(!rangeHasNumber(0, 10, 15)); | |
| 3653 | 3654 | } |
| 3654 | 3655 | |
| 3655 | 3656 | fn rangeHasNumber(begin: usize, end: usize, number: usize) bool { |
| ... | ... | @@ -3706,14 +3707,14 @@ test "while null capture" { |
| 3706 | 3707 | while (eventuallyNullSequence()) |value| { |
| 3707 | 3708 | sum1 += value; |
| 3708 | 3709 | } |
| 3709 | expect(sum1 == 3); | |
| 3710 | try expect(sum1 == 3); | |
| 3710 | 3711 | |
| 3711 | 3712 | var sum2: u32 = 0; |
| 3712 | 3713 | numbers_left = 3; |
| 3713 | 3714 | while (eventuallyNullSequence()) |value| { |
| 3714 | 3715 | sum2 += value; |
| 3715 | 3716 | } else { |
| 3716 | expect(sum2 == 3); | |
| 3717 | try expect(sum2 == 3); | |
| 3717 | 3718 | } |
| 3718 | 3719 | } |
| 3719 | 3720 | |
| ... | ... | @@ -3748,7 +3749,7 @@ test "while error union capture" { |
| 3748 | 3749 | while (eventuallyErrorSequence()) |value| { |
| 3749 | 3750 | sum1 += value; |
| 3750 | 3751 | } else |err| { |
| 3751 | expect(err == error.ReachedZero); | |
| 3752 | try expect(err == error.ReachedZero); | |
| 3752 | 3753 | } |
| 3753 | 3754 | } |
| 3754 | 3755 | |
| ... | ... | @@ -3784,7 +3785,7 @@ test "inline while loop" { |
| 3784 | 3785 | }; |
| 3785 | 3786 | sum += typeNameLength(T); |
| 3786 | 3787 | } |
| 3787 | expect(sum == 9); | |
| 3788 | try expect(sum == 9); | |
| 3788 | 3789 | } |
| 3789 | 3790 | |
| 3790 | 3791 | fn typeNameLength(comptime T: type) usize { |
| ... | ... | @@ -3819,22 +3820,22 @@ test "for basics" { |
| 3819 | 3820 | } |
| 3820 | 3821 | sum += value; |
| 3821 | 3822 | } |
| 3822 | expect(sum == 16); | |
| 3823 | try expect(sum == 16); | |
| 3823 | 3824 | |
| 3824 | 3825 | // To iterate over a portion of a slice, reslice. |
| 3825 | 3826 | for (items[0..1]) |value| { |
| 3826 | 3827 | sum += value; |
| 3827 | 3828 | } |
| 3828 | expect(sum == 20); | |
| 3829 | try expect(sum == 20); | |
| 3829 | 3830 | |
| 3830 | 3831 | // To access the index of iteration, specify a second capture value. |
| 3831 | 3832 | // This is zero-indexed. |
| 3832 | 3833 | var sum2: i32 = 0; |
| 3833 | 3834 | for (items) |value, i| { |
| 3834 | expect(@TypeOf(i) == usize); | |
| 3835 | try expect(@TypeOf(i) == usize); | |
| 3835 | 3836 | sum2 += @intCast(i32, i); |
| 3836 | 3837 | } |
| 3837 | expect(sum2 == 10); | |
| 3838 | try expect(sum2 == 10); | |
| 3838 | 3839 | } |
| 3839 | 3840 | |
| 3840 | 3841 | test "for reference" { |
| ... | ... | @@ -3846,9 +3847,9 @@ test "for reference" { |
| 3846 | 3847 | value.* += 1; |
| 3847 | 3848 | } |
| 3848 | 3849 | |
| 3849 | expect(items[0] == 4); | |
| 3850 | expect(items[1] == 5); | |
| 3851 | expect(items[2] == 3); | |
| 3850 | try expect(items[0] == 4); | |
| 3851 | try expect(items[1] == 5); | |
| 3852 | try expect(items[2] == 3); | |
| 3852 | 3853 | } |
| 3853 | 3854 | |
| 3854 | 3855 | test "for else" { |
| ... | ... | @@ -3863,10 +3864,10 @@ test "for else" { |
| 3863 | 3864 | sum += value.?; |
| 3864 | 3865 | } |
| 3865 | 3866 | } else blk: { |
| 3866 | expect(sum == 12); | |
| 3867 | try expect(sum == 12); | |
| 3867 | 3868 | break :blk sum; |
| 3868 | 3869 | }; |
| 3869 | expect(result == 12); | |
| 3870 | try expect(result == 12); | |
| 3870 | 3871 | } |
| 3871 | 3872 | {#code_end#} |
| 3872 | 3873 | {#header_open|Labeled for#} |
| ... | ... | @@ -3884,7 +3885,7 @@ test "nested break" { |
| 3884 | 3885 | break :outer; |
| 3885 | 3886 | } |
| 3886 | 3887 | } |
| 3887 | expect(count == 1); | |
| 3888 | try expect(count == 1); | |
| 3888 | 3889 | } |
| 3889 | 3890 | |
| 3890 | 3891 | test "nested continue" { |
| ... | ... | @@ -3896,7 +3897,7 @@ test "nested continue" { |
| 3896 | 3897 | } |
| 3897 | 3898 | } |
| 3898 | 3899 | |
| 3899 | expect(count == 8); | |
| 3900 | try expect(count == 8); | |
| 3900 | 3901 | } |
| 3901 | 3902 | {#code_end#} |
| 3902 | 3903 | {#header_close#} |
| ... | ... | @@ -3923,7 +3924,7 @@ test "inline for loop" { |
| 3923 | 3924 | }; |
| 3924 | 3925 | sum += typeNameLength(T); |
| 3925 | 3926 | } |
| 3926 | expect(sum == 9); | |
| 3927 | try expect(sum == 9); | |
| 3927 | 3928 | } |
| 3928 | 3929 | |
| 3929 | 3930 | fn typeNameLength(comptime T: type) usize { |
| ... | ... | @@ -3956,7 +3957,7 @@ test "if expression" { |
| 3956 | 3957 | const a: u32 = 5; |
| 3957 | 3958 | const b: u32 = 4; |
| 3958 | 3959 | const result = if (a != b) 47 else 3089; |
| 3959 | expect(result == 47); | |
| 3960 | try expect(result == 47); | |
| 3960 | 3961 | } |
| 3961 | 3962 | |
| 3962 | 3963 | test "if boolean" { |
| ... | ... | @@ -3964,7 +3965,7 @@ test "if boolean" { |
| 3964 | 3965 | const a: u32 = 5; |
| 3965 | 3966 | const b: u32 = 4; |
| 3966 | 3967 | if (a != b) { |
| 3967 | expect(true); | |
| 3968 | try expect(true); | |
| 3968 | 3969 | } else if (a == 9) { |
| 3969 | 3970 | unreachable; |
| 3970 | 3971 | } else { |
| ... | ... | @@ -3977,7 +3978,7 @@ test "if optional" { |
| 3977 | 3978 | |
| 3978 | 3979 | const a: ?u32 = 0; |
| 3979 | 3980 | if (a) |value| { |
| 3980 | expect(value == 0); | |
| 3981 | try expect(value == 0); | |
| 3981 | 3982 | } else { |
| 3982 | 3983 | unreachable; |
| 3983 | 3984 | } |
| ... | ... | @@ -3986,17 +3987,17 @@ test "if optional" { |
| 3986 | 3987 | if (b) |value| { |
| 3987 | 3988 | unreachable; |
| 3988 | 3989 | } else { |
| 3989 | expect(true); | |
| 3990 | try expect(true); | |
| 3990 | 3991 | } |
| 3991 | 3992 | |
| 3992 | 3993 | // The else is not required. |
| 3993 | 3994 | if (a) |value| { |
| 3994 | expect(value == 0); | |
| 3995 | try expect(value == 0); | |
| 3995 | 3996 | } |
| 3996 | 3997 | |
| 3997 | 3998 | // To test against null only, use the binary equality operator. |
| 3998 | 3999 | if (b == null) { |
| 3999 | expect(true); | |
| 4000 | try expect(true); | |
| 4000 | 4001 | } |
| 4001 | 4002 | |
| 4002 | 4003 | // Access the value by reference using a pointer capture. |
| ... | ... | @@ -4006,7 +4007,7 @@ test "if optional" { |
| 4006 | 4007 | } |
| 4007 | 4008 | |
| 4008 | 4009 | if (c) |value| { |
| 4009 | expect(value == 2); | |
| 4010 | try expect(value == 2); | |
| 4010 | 4011 | } else { |
| 4011 | 4012 | unreachable; |
| 4012 | 4013 | } |
| ... | ... | @@ -4018,7 +4019,7 @@ test "if error union" { |
| 4018 | 4019 | |
| 4019 | 4020 | const a: anyerror!u32 = 0; |
| 4020 | 4021 | if (a) |value| { |
| 4021 | expect(value == 0); | |
| 4022 | try expect(value == 0); | |
| 4022 | 4023 | } else |err| { |
| 4023 | 4024 | unreachable; |
| 4024 | 4025 | } |
| ... | ... | @@ -4027,17 +4028,17 @@ test "if error union" { |
| 4027 | 4028 | if (b) |value| { |
| 4028 | 4029 | unreachable; |
| 4029 | 4030 | } else |err| { |
| 4030 | expect(err == error.BadValue); | |
| 4031 | try expect(err == error.BadValue); | |
| 4031 | 4032 | } |
| 4032 | 4033 | |
| 4033 | 4034 | // The else and |err| capture is strictly required. |
| 4034 | 4035 | if (a) |value| { |
| 4035 | expect(value == 0); | |
| 4036 | try expect(value == 0); | |
| 4036 | 4037 | } else |_| {} |
| 4037 | 4038 | |
| 4038 | 4039 | // To check only the error value, use an empty block expression. |
| 4039 | 4040 | if (b) |_| {} else |err| { |
| 4040 | expect(err == error.BadValue); | |
| 4041 | try expect(err == error.BadValue); | |
| 4041 | 4042 | } |
| 4042 | 4043 | |
| 4043 | 4044 | // Access the value by reference using a pointer capture. |
| ... | ... | @@ -4049,7 +4050,7 @@ test "if error union" { |
| 4049 | 4050 | } |
| 4050 | 4051 | |
| 4051 | 4052 | if (c) |value| { |
| 4052 | expect(value == 9); | |
| 4053 | try expect(value == 9); | |
| 4053 | 4054 | } else |err| { |
| 4054 | 4055 | unreachable; |
| 4055 | 4056 | } |
| ... | ... | @@ -4061,14 +4062,14 @@ test "if error union with optional" { |
| 4061 | 4062 | |
| 4062 | 4063 | const a: anyerror!?u32 = 0; |
| 4063 | 4064 | if (a) |optional_value| { |
| 4064 | expect(optional_value.? == 0); | |
| 4065 | try expect(optional_value.? == 0); | |
| 4065 | 4066 | } else |err| { |
| 4066 | 4067 | unreachable; |
| 4067 | 4068 | } |
| 4068 | 4069 | |
| 4069 | 4070 | const b: anyerror!?u32 = null; |
| 4070 | 4071 | if (b) |optional_value| { |
| 4071 | expect(optional_value == null); | |
| 4072 | try expect(optional_value == null); | |
| 4072 | 4073 | } else |err| { |
| 4073 | 4074 | unreachable; |
| 4074 | 4075 | } |
| ... | ... | @@ -4077,7 +4078,7 @@ test "if error union with optional" { |
| 4077 | 4078 | if (c) |optional_value| { |
| 4078 | 4079 | unreachable; |
| 4079 | 4080 | } else |err| { |
| 4080 | expect(err == error.BadValue); | |
| 4081 | try expect(err == error.BadValue); | |
| 4081 | 4082 | } |
| 4082 | 4083 | |
| 4083 | 4084 | // Access the value by reference by using a pointer capture each time. |
| ... | ... | @@ -4091,7 +4092,7 @@ test "if error union with optional" { |
| 4091 | 4092 | } |
| 4092 | 4093 | |
| 4093 | 4094 | if (d) |optional_value| { |
| 4094 | expect(optional_value.? == 9); | |
| 4095 | try expect(optional_value.? == 9); | |
| 4095 | 4096 | } else |err| { |
| 4096 | 4097 | unreachable; |
| 4097 | 4098 | } |
| ... | ... | @@ -4106,21 +4107,21 @@ const expect = std.testing.expect; |
| 4106 | 4107 | const print = std.debug.print; |
| 4107 | 4108 | |
| 4108 | 4109 | // defer will execute an expression at the end of the current scope. |
| 4109 | fn deferExample() usize { | |
| 4110 | fn deferExample() !usize { | |
| 4110 | 4111 | var a: usize = 1; |
| 4111 | 4112 | |
| 4112 | 4113 | { |
| 4113 | 4114 | defer a = 2; |
| 4114 | 4115 | a = 1; |
| 4115 | 4116 | } |
| 4116 | expect(a == 2); | |
| 4117 | try expect(a == 2); | |
| 4117 | 4118 | |
| 4118 | 4119 | a = 5; |
| 4119 | 4120 | return a; |
| 4120 | 4121 | } |
| 4121 | 4122 | |
| 4122 | 4123 | test "defer basics" { |
| 4123 | expect(deferExample() == 5); | |
| 4124 | try expect((try deferExample()) == 5); | |
| 4124 | 4125 | } |
| 4125 | 4126 | |
| 4126 | 4127 | // If multiple defer statements are specified, they will be executed in |
| ... | ... | @@ -4258,7 +4259,7 @@ pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("bu |
| 4258 | 4259 | |
| 4259 | 4260 | test "foo" { |
| 4260 | 4261 | const value = bar() catch ExitProcess(1); |
| 4261 | expect(value == 1234); | |
| 4262 | try expect(value == 1234); | |
| 4262 | 4263 | } |
| 4263 | 4264 | |
| 4264 | 4265 | fn bar() anyerror!u32 { |
| ... | ... | @@ -4321,17 +4322,17 @@ fn do_op(fn_call: call2_op, op1: i8, op2: i8) i8 { |
| 4321 | 4322 | } |
| 4322 | 4323 | |
| 4323 | 4324 | test "function" { |
| 4324 | expect(do_op(add, 5, 6) == 11); | |
| 4325 | expect(do_op(sub2, 5, 6) == -1); | |
| 4325 | try expect(do_op(add, 5, 6) == 11); | |
| 4326 | try expect(do_op(sub2, 5, 6) == -1); | |
| 4326 | 4327 | } |
| 4327 | 4328 | {#code_end#} |
| 4328 | 4329 | <p>Function values are like pointers:</p> |
| 4329 | 4330 | {#code_begin|obj#} |
| 4330 | const expect = @import("std").testing.expect; | |
| 4331 | const assert = @import("std").debug.assert; | |
| 4331 | 4332 | |
| 4332 | 4333 | comptime { |
| 4333 | expect(@TypeOf(foo) == fn()void); | |
| 4334 | expect(@sizeOf(fn()void) == @sizeOf(?fn()void)); | |
| 4334 | assert(@TypeOf(foo) == fn()void); | |
| 4335 | assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); | |
| 4335 | 4336 | } |
| 4336 | 4337 | |
| 4337 | 4338 | fn foo() void { } |
| ... | ... | @@ -4366,7 +4367,7 @@ fn foo(point: Point) i32 { |
| 4366 | 4367 | const expect = @import("std").testing.expect; |
| 4367 | 4368 | |
| 4368 | 4369 | test "pass struct to function" { |
| 4369 | expect(foo(Point{ .x = 1, .y = 2 }) == 3); | |
| 4370 | try expect(foo(Point{ .x = 1, .y = 2 }) == 3); | |
| 4370 | 4371 | } |
| 4371 | 4372 | {#code_end#} |
| 4372 | 4373 | <p> |
| ... | ... | @@ -4387,11 +4388,11 @@ fn addFortyTwo(x: anytype) @TypeOf(x) { |
| 4387 | 4388 | } |
| 4388 | 4389 | |
| 4389 | 4390 | test "fn type inference" { |
| 4390 | expect(addFortyTwo(1) == 43); | |
| 4391 | expect(@TypeOf(addFortyTwo(1)) == comptime_int); | |
| 4391 | try expect(addFortyTwo(1) == 43); | |
| 4392 | try expect(@TypeOf(addFortyTwo(1)) == comptime_int); | |
| 4392 | 4393 | var y: i64 = 2; |
| 4393 | expect(addFortyTwo(y) == 44); | |
| 4394 | expect(@TypeOf(addFortyTwo(y)) == i64); | |
| 4394 | try expect(addFortyTwo(y) == 44); | |
| 4395 | try expect(@TypeOf(addFortyTwo(y)) == i64); | |
| 4395 | 4396 | } |
| 4396 | 4397 | {#code_end#} |
| 4397 | 4398 | |
| ... | ... | @@ -4401,8 +4402,8 @@ test "fn type inference" { |
| 4401 | 4402 | const expect = @import("std").testing.expect; |
| 4402 | 4403 | |
| 4403 | 4404 | test "fn reflection" { |
| 4404 | expect(@typeInfo(@TypeOf(expect)).Fn.return_type.? == void); | |
| 4405 | expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false); | |
| 4405 | try expect(@typeInfo(@TypeOf(expect)).Fn.args[0].arg_type.? == bool); | |
| 4406 | try expect(@typeInfo(@TypeOf(expect)).Fn.is_var_args == false); | |
| 4406 | 4407 | } |
| 4407 | 4408 | {#code_end#} |
| 4408 | 4409 | {#header_close#} |
| ... | ... | @@ -4437,7 +4438,7 @@ const AllocationError = error { |
| 4437 | 4438 | |
| 4438 | 4439 | test "coerce subset to superset" { |
| 4439 | 4440 | const err = foo(AllocationError.OutOfMemory); |
| 4440 | std.testing.expect(err == FileOpenError.OutOfMemory); | |
| 4441 | try std.testing.expect(err == FileOpenError.OutOfMemory); | |
| 4441 | 4442 | } |
| 4442 | 4443 | |
| 4443 | 4444 | fn foo(err: AllocationError) FileOpenError { |
| ... | ... | @@ -4545,7 +4546,7 @@ fn charToDigit(c: u8) u8 { |
| 4545 | 4546 | |
| 4546 | 4547 | test "parse u64" { |
| 4547 | 4548 | const result = try parseU64("1234", 10); |
| 4548 | std.testing.expect(result == 1234); | |
| 4549 | try std.testing.expect(result == 1234); | |
| 4549 | 4550 | } |
| 4550 | 4551 | {#code_end#} |
| 4551 | 4552 | <p> |
| ... | ... | @@ -4702,10 +4703,10 @@ test "error union" { |
| 4702 | 4703 | foo = error.SomeError; |
| 4703 | 4704 | |
| 4704 | 4705 | // Use compile-time reflection to access the payload type of an error union: |
| 4705 | comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32); | |
| 4706 | comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32); | |
| 4706 | 4707 | |
| 4707 | 4708 | // Use compile-time reflection to access the error set type of an error union: |
| 4708 | comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror); | |
| 4709 | comptime try expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror); | |
| 4709 | 4710 | } |
| 4710 | 4711 | {#code_end#} |
| 4711 | 4712 | {#header_open|Merging Error Sets#} |
| ... | ... | @@ -5082,7 +5083,7 @@ test "optional type" { |
| 5082 | 5083 | foo = 1234; |
| 5083 | 5084 | |
| 5084 | 5085 | // Use compile-time reflection to access the child type of the optional: |
| 5085 | comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32); | |
| 5086 | comptime try expect(@typeInfo(@TypeOf(foo)).Optional.child == i32); | |
| 5086 | 5087 | } |
| 5087 | 5088 | {#code_end#} |
| 5088 | 5089 | {#header_close#} |
| ... | ... | @@ -5109,11 +5110,11 @@ test "optional pointers" { |
| 5109 | 5110 | var x: i32 = 1; |
| 5110 | 5111 | ptr = &x; |
| 5111 | 5112 | |
| 5112 | expect(ptr.?.* == 1); | |
| 5113 | try expect(ptr.?.* == 1); | |
| 5113 | 5114 | |
| 5114 | 5115 | // Optional pointers are the same size as normal pointers, because pointer |
| 5115 | 5116 | // value 0 is used as the null value. |
| 5116 | expect(@sizeOf(?*i32) == @sizeOf(*i32)); | |
| 5117 | try expect(@sizeOf(?*i32) == @sizeOf(*i32)); | |
| 5117 | 5118 | } |
| 5118 | 5119 | {#code_end#} |
| 5119 | 5120 | {#header_close#} |
| ... | ... | @@ -5186,7 +5187,7 @@ const mem = std.mem; |
| 5186 | 5187 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 5187 | 5188 | const window_name = [1][*]const u8{"window name"}; |
| 5188 | 5189 | const x: [*]const ?[*]const u8 = &window_name; |
| 5189 | expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 5190 | try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 5190 | 5191 | } |
| 5191 | 5192 | {#code_end#} |
| 5192 | 5193 | {#header_close#} |
| ... | ... | @@ -5207,13 +5208,13 @@ test "integer widening" { |
| 5207 | 5208 | var d: u64 = c; |
| 5208 | 5209 | var e: u64 = d; |
| 5209 | 5210 | var f: u128 = e; |
| 5210 | expect(f == a); | |
| 5211 | try expect(f == a); | |
| 5211 | 5212 | } |
| 5212 | 5213 | |
| 5213 | 5214 | test "implicit unsigned integer to signed integer" { |
| 5214 | 5215 | var a: u8 = 250; |
| 5215 | 5216 | var b: i16 = a; |
| 5216 | expect(b == 250); | |
| 5217 | try expect(b == 250); | |
| 5217 | 5218 | } |
| 5218 | 5219 | |
| 5219 | 5220 | test "float widening" { |
| ... | ... | @@ -5225,7 +5226,7 @@ test "float widening" { |
| 5225 | 5226 | var b: f32 = a; |
| 5226 | 5227 | var c: f64 = b; |
| 5227 | 5228 | var d: f128 = c; |
| 5228 | expect(d == a); | |
| 5229 | try expect(d == a); | |
| 5229 | 5230 | } |
| 5230 | 5231 | {#code_end#} |
| 5231 | 5232 | {#header_close#} |
| ... | ... | @@ -5257,48 +5258,48 @@ const expect = std.testing.expect; |
| 5257 | 5258 | test "[N]T to []const T" { |
| 5258 | 5259 | var x1: []const u8 = "hello"; |
| 5259 | 5260 | var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 5260 | expect(std.mem.eql(u8, x1, x2)); | |
| 5261 | try expect(std.mem.eql(u8, x1, x2)); | |
| 5261 | 5262 | |
| 5262 | 5263 | var y: []const f32 = &[2]f32{ 1.2, 3.4 }; |
| 5263 | expect(y[0] == 1.2); | |
| 5264 | try expect(y[0] == 1.2); | |
| 5264 | 5265 | } |
| 5265 | 5266 | |
| 5266 | 5267 | // Likewise, it works when the destination type is an error union. |
| 5267 | 5268 | test "[N]T to E![]const T" { |
| 5268 | 5269 | var x1: anyerror![]const u8 = "hello"; |
| 5269 | 5270 | var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 5270 | expect(std.mem.eql(u8, try x1, try x2)); | |
| 5271 | try expect(std.mem.eql(u8, try x1, try x2)); | |
| 5271 | 5272 | |
| 5272 | 5273 | var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; |
| 5273 | expect((try y)[0] == 1.2); | |
| 5274 | try expect((try y)[0] == 1.2); | |
| 5274 | 5275 | } |
| 5275 | 5276 | |
| 5276 | 5277 | // Likewise, it works when the destination type is an optional. |
| 5277 | 5278 | test "[N]T to ?[]const T" { |
| 5278 | 5279 | var x1: ?[]const u8 = "hello"; |
| 5279 | 5280 | var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; |
| 5280 | expect(std.mem.eql(u8, x1.?, x2.?)); | |
| 5281 | try expect(std.mem.eql(u8, x1.?, x2.?)); | |
| 5281 | 5282 | |
| 5282 | 5283 | var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; |
| 5283 | expect(y.?[0] == 1.2); | |
| 5284 | try expect(y.?[0] == 1.2); | |
| 5284 | 5285 | } |
| 5285 | 5286 | |
| 5286 | 5287 | // In this cast, the array length becomes the slice length. |
| 5287 | 5288 | test "*[N]T to []T" { |
| 5288 | 5289 | var buf: [5]u8 = "hello".*; |
| 5289 | 5290 | const x: []u8 = &buf; |
| 5290 | expect(std.mem.eql(u8, x, "hello")); | |
| 5291 | try expect(std.mem.eql(u8, x, "hello")); | |
| 5291 | 5292 | |
| 5292 | 5293 | const buf2 = [2]f32{ 1.2, 3.4 }; |
| 5293 | 5294 | const x2: []const f32 = &buf2; |
| 5294 | expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); | |
| 5295 | try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); | |
| 5295 | 5296 | } |
| 5296 | 5297 | |
| 5297 | 5298 | // Single-item pointers to arrays can be coerced to many-item pointers. |
| 5298 | 5299 | test "*[N]T to [*]T" { |
| 5299 | 5300 | var buf: [5]u8 = "hello".*; |
| 5300 | 5301 | const x: [*]u8 = &buf; |
| 5301 | expect(x[4] == 'o'); | |
| 5302 | try expect(x[4] == 'o'); | |
| 5302 | 5303 | // x[5] would be an uncaught out of bounds pointer dereference! |
| 5303 | 5304 | } |
| 5304 | 5305 | |
| ... | ... | @@ -5306,7 +5307,7 @@ test "*[N]T to [*]T" { |
| 5306 | 5307 | test "*[N]T to ?[*]T" { |
| 5307 | 5308 | var buf: [5]u8 = "hello".*; |
| 5308 | 5309 | const x: ?[*]u8 = &buf; |
| 5309 | expect(x.?[4] == 'o'); | |
| 5310 | try expect(x.?[4] == 'o'); | |
| 5310 | 5311 | } |
| 5311 | 5312 | |
| 5312 | 5313 | // Single-item pointers can be cast to len-1 single-item arrays. |
| ... | ... | @@ -5314,7 +5315,7 @@ test "*T to *[1]T" { |
| 5314 | 5315 | var x: i32 = 1234; |
| 5315 | 5316 | const y: *[1]i32 = &x; |
| 5316 | 5317 | const z: [*]i32 = y; |
| 5317 | expect(z[0] == 1234); | |
| 5318 | try expect(z[0] == 1234); | |
| 5318 | 5319 | } |
| 5319 | 5320 | {#code_end#} |
| 5320 | 5321 | {#see_also|C Pointers#} |
| ... | ... | @@ -5331,8 +5332,8 @@ test "coerce to optionals" { |
| 5331 | 5332 | const x: ?i32 = 1234; |
| 5332 | 5333 | const y: ?i32 = null; |
| 5333 | 5334 | |
| 5334 | expect(x.? == 1234); | |
| 5335 | expect(y == null); | |
| 5335 | try expect(x.? == 1234); | |
| 5336 | try expect(y == null); | |
| 5336 | 5337 | } |
| 5337 | 5338 | {#code_end#} |
| 5338 | 5339 | <p>It works nested inside the {#link|Error Union Type#}, too:</p> |
| ... | ... | @@ -5344,8 +5345,8 @@ test "coerce to optionals wrapped in error union" { |
| 5344 | 5345 | const x: anyerror!?i32 = 1234; |
| 5345 | 5346 | const y: anyerror!?i32 = null; |
| 5346 | 5347 | |
| 5347 | expect((try x).? == 1234); | |
| 5348 | expect((try y) == null); | |
| 5348 | try expect((try x).? == 1234); | |
| 5349 | try expect((try y) == null); | |
| 5349 | 5350 | } |
| 5350 | 5351 | {#code_end#} |
| 5351 | 5352 | {#header_close#} |
| ... | ... | @@ -5361,8 +5362,8 @@ test "coercion to error unions" { |
| 5361 | 5362 | const x: anyerror!i32 = 1234; |
| 5362 | 5363 | const y: anyerror!i32 = error.Failure; |
| 5363 | 5364 | |
| 5364 | expect((try x) == 1234); | |
| 5365 | std.testing.expectError(error.Failure, y); | |
| 5365 | try expect((try x) == 1234); | |
| 5366 | try std.testing.expectError(error.Failure, y); | |
| 5366 | 5367 | } |
| 5367 | 5368 | {#code_end#} |
| 5368 | 5369 | {#header_close#} |
| ... | ... | @@ -5377,7 +5378,7 @@ const expect = std.testing.expect; |
| 5377 | 5378 | test "coercing large integer type to smaller one when value is comptime known to fit" { |
| 5378 | 5379 | const x: u64 = 255; |
| 5379 | 5380 | const y: u8 = x; |
| 5380 | expect(y == 255); | |
| 5381 | try expect(y == 255); | |
| 5381 | 5382 | } |
| 5382 | 5383 | {#code_end#} |
| 5383 | 5384 | {#header_close#} |
| ... | ... | @@ -5405,11 +5406,11 @@ const U = union(E) { |
| 5405 | 5406 | test "coercion between unions and enums" { |
| 5406 | 5407 | var u = U{ .two = 12.34 }; |
| 5407 | 5408 | var e: E = u; |
| 5408 | expect(e == E.two); | |
| 5409 | try expect(e == E.two); | |
| 5409 | 5410 | |
| 5410 | 5411 | const three = E.three; |
| 5411 | 5412 | var another_u: U = three; |
| 5412 | expect(another_u == E.three); | |
| 5413 | try expect(another_u == E.three); | |
| 5413 | 5414 | } |
| 5414 | 5415 | {#code_end#} |
| 5415 | 5416 | {#see_also|union|enum#} |
| ... | ... | @@ -5482,37 +5483,37 @@ test "peer resolve int widening" { |
| 5482 | 5483 | var a: i8 = 12; |
| 5483 | 5484 | var b: i16 = 34; |
| 5484 | 5485 | var c = a + b; |
| 5485 | expect(c == 46); | |
| 5486 | expect(@TypeOf(c) == i16); | |
| 5486 | try expect(c == 46); | |
| 5487 | try expect(@TypeOf(c) == i16); | |
| 5487 | 5488 | } |
| 5488 | 5489 | |
| 5489 | 5490 | test "peer resolve arrays of different size to const slice" { |
| 5490 | expect(mem.eql(u8, boolToStr(true), "true")); | |
| 5491 | expect(mem.eql(u8, boolToStr(false), "false")); | |
| 5492 | comptime expect(mem.eql(u8, boolToStr(true), "true")); | |
| 5493 | comptime expect(mem.eql(u8, boolToStr(false), "false")); | |
| 5491 | try expect(mem.eql(u8, boolToStr(true), "true")); | |
| 5492 | try expect(mem.eql(u8, boolToStr(false), "false")); | |
| 5493 | comptime try expect(mem.eql(u8, boolToStr(true), "true")); | |
| 5494 | comptime try expect(mem.eql(u8, boolToStr(false), "false")); | |
| 5494 | 5495 | } |
| 5495 | 5496 | fn boolToStr(b: bool) []const u8 { |
| 5496 | 5497 | return if (b) "true" else "false"; |
| 5497 | 5498 | } |
| 5498 | 5499 | |
| 5499 | 5500 | test "peer resolve array and const slice" { |
| 5500 | testPeerResolveArrayConstSlice(true); | |
| 5501 | comptime testPeerResolveArrayConstSlice(true); | |
| 5501 | try testPeerResolveArrayConstSlice(true); | |
| 5502 | comptime try testPeerResolveArrayConstSlice(true); | |
| 5502 | 5503 | } |
| 5503 | fn testPeerResolveArrayConstSlice(b: bool) void { | |
| 5504 | fn testPeerResolveArrayConstSlice(b: bool) !void { | |
| 5504 | 5505 | const value1 = if (b) "aoeu" else @as([]const u8, "zz"); |
| 5505 | 5506 | const value2 = if (b) @as([]const u8, "zz") else "aoeu"; |
| 5506 | expect(mem.eql(u8, value1, "aoeu")); | |
| 5507 | expect(mem.eql(u8, value2, "zz")); | |
| 5507 | try expect(mem.eql(u8, value1, "aoeu")); | |
| 5508 | try expect(mem.eql(u8, value2, "zz")); | |
| 5508 | 5509 | } |
| 5509 | 5510 | |
| 5510 | 5511 | test "peer type resolution: ?T and T" { |
| 5511 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 5512 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 5512 | try expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 5513 | try expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 5513 | 5514 | comptime { |
| 5514 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 5515 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 5515 | try expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 5516 | try expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 5516 | 5517 | } |
| 5517 | 5518 | } |
| 5518 | 5519 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| ... | ... | @@ -5524,11 +5525,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 5524 | 5525 | } |
| 5525 | 5526 | |
| 5526 | 5527 | test "peer type resolution: *[0]u8 and []const u8" { |
| 5527 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 5528 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 5528 | try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 5529 | try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 5529 | 5530 | comptime { |
| 5530 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 5531 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 5531 | try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 5532 | try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 5532 | 5533 | } |
| 5533 | 5534 | } |
| 5534 | 5535 | fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| ... | ... | @@ -5542,14 +5543,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" { |
| 5542 | 5543 | { |
| 5543 | 5544 | var data = "hi".*; |
| 5544 | 5545 | const slice = data[0..]; |
| 5545 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 5546 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 5546 | try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 5547 | try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 5547 | 5548 | } |
| 5548 | 5549 | comptime { |
| 5549 | 5550 | var data = "hi".*; |
| 5550 | 5551 | const slice = data[0..]; |
| 5551 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 5552 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 5552 | try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 5553 | try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 5553 | 5554 | } |
| 5554 | 5555 | } |
| 5555 | 5556 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| ... | ... | @@ -5563,8 +5564,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| 5563 | 5564 | test "peer type resolution: *const T and ?*T" { |
| 5564 | 5565 | const a = @intToPtr(*const usize, 0x123456780); |
| 5565 | 5566 | const b = @intToPtr(?*usize, 0x123456780); |
| 5566 | expect(a == b); | |
| 5567 | expect(b == a); | |
| 5567 | try expect(a == b); | |
| 5568 | try expect(b == a); | |
| 5568 | 5569 | } |
| 5569 | 5570 | {#code_end#} |
| 5570 | 5571 | {#header_close#} |
| ... | ... | @@ -5620,11 +5621,11 @@ test "turn HashMap into a set with void" { |
| 5620 | 5621 | try map.put(1, {}); |
| 5621 | 5622 | try map.put(2, {}); |
| 5622 | 5623 | |
| 5623 | expect(map.contains(2)); | |
| 5624 | expect(!map.contains(3)); | |
| 5624 | try expect(map.contains(2)); | |
| 5625 | try expect(!map.contains(3)); | |
| 5625 | 5626 | |
| 5626 | 5627 | _ = map.remove(2); |
| 5627 | expect(!map.contains(2)); | |
| 5628 | try expect(!map.contains(2)); | |
| 5628 | 5629 | } |
| 5629 | 5630 | {#code_end#} |
| 5630 | 5631 | <p>Note that this is different from using a dummy value for the hash map value. |
| ... | ... | @@ -5679,7 +5680,7 @@ test "pointer to empty struct" { |
| 5679 | 5680 | var b = Empty{}; |
| 5680 | 5681 | var ptr_a = &a; |
| 5681 | 5682 | var ptr_b = &b; |
| 5682 | comptime expect(ptr_a == ptr_b); | |
| 5683 | comptime try expect(ptr_a == ptr_b); | |
| 5683 | 5684 | } |
| 5684 | 5685 | {#code_end#} |
| 5685 | 5686 | <p>The type being pointed to can only ever be one value; therefore loads and stores are |
| ... | ... | @@ -5714,7 +5715,7 @@ test "@intToPtr for pointer to zero bit type" { |
| 5714 | 5715 | usingnamespace @import("std"); |
| 5715 | 5716 | |
| 5716 | 5717 | test "using std namespace" { |
| 5717 | testing.expect(true); | |
| 5718 | try testing.expect(true); | |
| 5718 | 5719 | } |
| 5719 | 5720 | {#code_end#} |
| 5720 | 5721 | <p> |
| ... | ... | @@ -5826,7 +5827,7 @@ fn max(comptime T: type, a: T, b: T) T { |
| 5826 | 5827 | } |
| 5827 | 5828 | } |
| 5828 | 5829 | test "try to compare bools" { |
| 5829 | @import("std").testing.expect(max(bool, false, true) == true); | |
| 5830 | try @import("std").testing.expect(max(bool, false, true) == true); | |
| 5830 | 5831 | } |
| 5831 | 5832 | {#code_end#} |
| 5832 | 5833 | <p> |
| ... | ... | @@ -5894,9 +5895,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 5894 | 5895 | } |
| 5895 | 5896 | |
| 5896 | 5897 | test "perform fn" { |
| 5897 | expect(performFn('t', 1) == 6); | |
| 5898 | expect(performFn('o', 0) == 1); | |
| 5899 | expect(performFn('w', 99) == 99); | |
| 5898 | try expect(performFn('t', 1) == 6); | |
| 5899 | try expect(performFn('o', 0) == 1); | |
| 5900 | try expect(performFn('w', 99) == 99); | |
| 5900 | 5901 | } |
| 5901 | 5902 | {#code_end#} |
| 5902 | 5903 | <p> |
| ... | ... | @@ -5988,11 +5989,11 @@ fn fibonacci(index: u32) u32 { |
| 5988 | 5989 | |
| 5989 | 5990 | test "fibonacci" { |
| 5990 | 5991 | // test fibonacci at run-time |
| 5991 | expect(fibonacci(7) == 13); | |
| 5992 | try expect(fibonacci(7) == 13); | |
| 5992 | 5993 | |
| 5993 | 5994 | // test fibonacci at compile-time |
| 5994 | 5995 | comptime { |
| 5995 | expect(fibonacci(7) == 13); | |
| 5996 | try expect(fibonacci(7) == 13); | |
| 5996 | 5997 | } |
| 5997 | 5998 | } |
| 5998 | 5999 | {#code_end#} |
| ... | ... | @@ -6009,7 +6010,7 @@ fn fibonacci(index: u32) u32 { |
| 6009 | 6010 | |
| 6010 | 6011 | test "fibonacci" { |
| 6011 | 6012 | comptime { |
| 6012 | expect(fibonacci(7) == 13); | |
| 6013 | try expect(fibonacci(7) == 13); | |
| 6013 | 6014 | } |
| 6014 | 6015 | } |
| 6015 | 6016 | {#code_end#} |
| ... | ... | @@ -6032,7 +6033,7 @@ fn fibonacci(index: i32) i32 { |
| 6032 | 6033 | |
| 6033 | 6034 | test "fibonacci" { |
| 6034 | 6035 | comptime { |
| 6035 | expect(fibonacci(7) == 13); | |
| 6036 | try expect(fibonacci(7) == 13); | |
| 6036 | 6037 | } |
| 6037 | 6038 | } |
| 6038 | 6039 | {#code_end#} |
| ... | ... | @@ -6045,7 +6046,7 @@ test "fibonacci" { |
| 6045 | 6046 | <p> |
| 6046 | 6047 | What if we fix the base case, but put the wrong value in the {#syntax#}expect{#endsyntax#} line? |
| 6047 | 6048 | </p> |
| 6048 | {#code_begin|test_err|encountered @panic at compile-time#} | |
| 6049 | {#code_begin|test_err|test "fibonacci"... FAIL (TestUnexpectedResult)#} | |
| 6049 | 6050 | const expect = @import("std").testing.expect; |
| 6050 | 6051 | |
| 6051 | 6052 | fn fibonacci(index: i32) i32 { |
| ... | ... | @@ -6055,7 +6056,7 @@ fn fibonacci(index: i32) i32 { |
| 6055 | 6056 | |
| 6056 | 6057 | test "fibonacci" { |
| 6057 | 6058 | comptime { |
| 6058 | expect(fibonacci(7) == 99999); | |
| 6059 | try expect(fibonacci(7) == 99999); | |
| 6059 | 6060 | } |
| 6060 | 6061 | } |
| 6061 | 6062 | {#code_end#} |
| ... | ... | @@ -6105,7 +6106,7 @@ fn sum(numbers: []const i32) i32 { |
| 6105 | 6106 | } |
| 6106 | 6107 | |
| 6107 | 6108 | test "variable values" { |
| 6108 | @import("std").testing.expect(sum_of_first_25_primes == 1060); | |
| 6109 | try @import("std").testing.expect(sum_of_first_25_primes == 1060); | |
| 6109 | 6110 | } |
| 6110 | 6111 | {#code_end#} |
| 6111 | 6112 | <p> |
| ... | ... | @@ -6513,7 +6514,7 @@ comptime { |
| 6513 | 6514 | extern fn my_func(a: i32, b: i32) i32; |
| 6514 | 6515 | |
| 6515 | 6516 | test "global assembly" { |
| 6516 | expect(my_func(12, 34) == 46); | |
| 6517 | try expect(my_func(12, 34) == 46); | |
| 6517 | 6518 | } |
| 6518 | 6519 | {#code_end#} |
| 6519 | 6520 | {#header_close#} |
| ... | ... | @@ -6554,7 +6555,7 @@ var x: i32 = 1; |
| 6554 | 6555 | |
| 6555 | 6556 | test "suspend with no resume" { |
| 6556 | 6557 | var frame = async func(); |
| 6557 | expect(x == 2); | |
| 6558 | try expect(x == 2); | |
| 6558 | 6559 | } |
| 6559 | 6560 | |
| 6560 | 6561 | fn func() void { |
| ... | ... | @@ -6581,14 +6582,14 @@ var result = false; |
| 6581 | 6582 | |
| 6582 | 6583 | test "async function suspend with block" { |
| 6583 | 6584 | _ = async testSuspendBlock(); |
| 6584 | expect(!result); | |
| 6585 | try expect(!result); | |
| 6585 | 6586 | resume the_frame; |
| 6586 | expect(result); | |
| 6587 | try expect(result); | |
| 6587 | 6588 | } |
| 6588 | 6589 | |
| 6589 | 6590 | fn testSuspendBlock() void { |
| 6590 | 6591 | suspend { |
| 6591 | comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 6592 | comptime try expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 6592 | 6593 | the_frame = @frame(); |
| 6593 | 6594 | } |
| 6594 | 6595 | result = true; |
| ... | ... | @@ -6617,7 +6618,7 @@ const expect = std.testing.expect; |
| 6617 | 6618 | test "resume from suspend" { |
| 6618 | 6619 | var my_result: i32 = 1; |
| 6619 | 6620 | _ = async testResumeFromSuspend(&my_result); |
| 6620 | std.testing.expect(my_result == 2); | |
| 6621 | try std.testing.expect(my_result == 2); | |
| 6621 | 6622 | } |
| 6622 | 6623 | fn testResumeFromSuspend(my_result: *i32) void { |
| 6623 | 6624 | suspend { |
| ... | ... | @@ -6653,7 +6654,7 @@ test "async and await" { |
| 6653 | 6654 | |
| 6654 | 6655 | fn amain() void { |
| 6655 | 6656 | var frame = async func(); |
| 6656 | comptime expect(@TypeOf(frame) == @Frame(func)); | |
| 6657 | comptime try expect(@TypeOf(frame) == @Frame(func)); | |
| 6657 | 6658 | |
| 6658 | 6659 | const ptr: anyframe->void = &frame; |
| 6659 | 6660 | const any_ptr: anyframe = ptr; |
| ... | ... | @@ -6694,8 +6695,8 @@ test "async function await" { |
| 6694 | 6695 | seq('f'); |
| 6695 | 6696 | resume the_frame; |
| 6696 | 6697 | seq('i'); |
| 6697 | expect(final_result == 1234); | |
| 6698 | expect(std.mem.eql(u8, &seq_points, "abcdefghi")); | |
| 6698 | try expect(final_result == 1234); | |
| 6699 | try expect(std.mem.eql(u8, &seq_points, "abcdefghi")); | |
| 6699 | 6700 | } |
| 6700 | 6701 | fn amain() void { |
| 6701 | 6702 | seq('b'); |
| ... | ... | @@ -6909,9 +6910,9 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6909 | 6910 | for the current target to match the C ABI. When the child type of a pointer has |
| 6910 | 6911 | this alignment, the alignment can be omitted from the type. |
| 6911 | 6912 | </p> |
| 6912 | <pre>{#syntax#}const expect = @import("std").testing.expect; | |
| 6913 | <pre>{#syntax#}const expect = @import("std").debug.assert; | |
| 6913 | 6914 | comptime { |
| 6914 | expect(*u32 == *align(@alignOf(u32)) u32); | |
| 6915 | assert(*u32 == *align(@alignOf(u32)) u32); | |
| 6915 | 6916 | }{#endsyntax#}</pre> |
| 6916 | 6917 | <p> |
| 6917 | 6918 | The result is a target-specific compile time constant. It is guaranteed to be |
| ... | ... | @@ -6957,9 +6958,9 @@ test "async fn pointer in a struct field" { |
| 6957 | 6958 | var foo = Foo{ .bar = func }; |
| 6958 | 6959 | var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined; |
| 6959 | 6960 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 6960 | expect(data == 2); | |
| 6961 | try expect(data == 2); | |
| 6961 | 6962 | resume f; |
| 6962 | expect(data == 4); | |
| 6963 | try expect(data == 4); | |
| 6963 | 6964 | } |
| 6964 | 6965 | |
| 6965 | 6966 | fn func(y: *i32) void { |
| ... | ... | @@ -7146,7 +7147,7 @@ fn func(y: *i32) void { |
| 7146 | 7147 | const expect = @import("std").testing.expect; |
| 7147 | 7148 | |
| 7148 | 7149 | test "noinline function call" { |
| 7149 | expect(@call(.{}, add, .{3, 9}) == 12); | |
| 7150 | try expect(@call(.{}, add, .{3, 9}) == 12); | |
| 7150 | 7151 | } |
| 7151 | 7152 | |
| 7152 | 7153 | fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -7621,17 +7622,17 @@ test "field access by string" { |
| 7621 | 7622 | @field(p, "x") = 4; |
| 7622 | 7623 | @field(p, "y") = @field(p, "x") + 1; |
| 7623 | 7624 | |
| 7624 | expect(@field(p, "x") == 4); | |
| 7625 | expect(@field(p, "y") == 5); | |
| 7625 | try expect(@field(p, "x") == 4); | |
| 7626 | try expect(@field(p, "y") == 5); | |
| 7626 | 7627 | } |
| 7627 | 7628 | |
| 7628 | 7629 | test "decl access by string" { |
| 7629 | 7630 | const expect = std.testing.expect; |
| 7630 | 7631 | |
| 7631 | expect(@field(Point, "z") == 1); | |
| 7632 | try expect(@field(Point, "z") == 1); | |
| 7632 | 7633 | |
| 7633 | 7634 | @field(Point, "z") = 2; |
| 7634 | expect(@field(Point, "z") == 2); | |
| 7635 | try expect(@field(Point, "z") == 2); | |
| 7635 | 7636 | } |
| 7636 | 7637 | {#code_end#} |
| 7637 | 7638 | |
| ... | ... | @@ -7747,16 +7748,16 @@ const Foo = struct { |
| 7747 | 7748 | }; |
| 7748 | 7749 | |
| 7749 | 7750 | test "@hasDecl" { |
| 7750 | expect(@hasDecl(Foo, "blah")); | |
| 7751 | try expect(@hasDecl(Foo, "blah")); | |
| 7751 | 7752 | |
| 7752 | 7753 | // Even though `hi` is private, @hasDecl returns true because this test is |
| 7753 | 7754 | // in the same file scope as Foo. It would return false if Foo was declared |
| 7754 | 7755 | // in a different file. |
| 7755 | expect(@hasDecl(Foo, "hi")); | |
| 7756 | try expect(@hasDecl(Foo, "hi")); | |
| 7756 | 7757 | |
| 7757 | 7758 | // @hasDecl is for declarations; not fields. |
| 7758 | expect(!@hasDecl(Foo, "nope")); | |
| 7759 | expect(!@hasDecl(Foo, "nope1234")); | |
| 7759 | try expect(!@hasDecl(Foo, "nope")); | |
| 7760 | try expect(!@hasDecl(Foo, "nope1234")); | |
| 7760 | 7761 | } |
| 7761 | 7762 | {#code_end#} |
| 7762 | 7763 | {#see_also|@hasField#} |
| ... | ... | @@ -7937,8 +7938,8 @@ test "@wasmMemoryGrow" { |
| 7937 | 7938 | if (builtin.arch != .wasm32) return error.SkipZigTest; |
| 7938 | 7939 | |
| 7939 | 7940 | var prev = @wasmMemorySize(0); |
| 7940 | expect(prev == @wasmMemoryGrow(0, 1)); | |
| 7941 | expect(prev + 1 == @wasmMemorySize(0)); | |
| 7941 | try expect(prev == @wasmMemoryGrow(0, 1)); | |
| 7942 | try expect(prev + 1 == @wasmMemorySize(0)); | |
| 7942 | 7943 | } |
| 7943 | 7944 | {#code_end#} |
| 7944 | 7945 | {#see_also|@wasmMemorySize#} |
| ... | ... | @@ -8279,8 +8280,8 @@ const expect = std.testing.expect; |
| 8279 | 8280 | test "vector @splat" { |
| 8280 | 8281 | const scalar: u32 = 5; |
| 8281 | 8282 | const result = @splat(4, scalar); |
| 8282 | comptime expect(@TypeOf(result) == std.meta.Vector(4, u32)); | |
| 8283 | expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); | |
| 8283 | comptime try expect(@TypeOf(result) == std.meta.Vector(4, u32)); | |
| 8284 | try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); | |
| 8284 | 8285 | } |
| 8285 | 8286 | {#code_end#} |
| 8286 | 8287 | <p> |
| ... | ... | @@ -8322,10 +8323,10 @@ test "vector @reduce" { |
| 8322 | 8323 | const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 }; |
| 8323 | 8324 | const result = value > @splat(4, @as(i32, 0)); |
| 8324 | 8325 | // result is { true, false, true, false }; |
| 8325 | comptime expect(@TypeOf(result) == std.meta.Vector(4, bool)); | |
| 8326 | comptime try expect(@TypeOf(result) == std.meta.Vector(4, bool)); | |
| 8326 | 8327 | const is_all_true = @reduce(.And, result); |
| 8327 | comptime expect(@TypeOf(is_all_true) == bool); | |
| 8328 | expect(is_all_true == false); | |
| 8328 | comptime try expect(@TypeOf(is_all_true) == bool); | |
| 8329 | try expect(is_all_true == false); | |
| 8329 | 8330 | } |
| 8330 | 8331 | {#code_end#} |
| 8331 | 8332 | {#see_also|Vectors|@setFloatMode#} |
| ... | ... | @@ -8341,16 +8342,16 @@ const std = @import("std"); |
| 8341 | 8342 | const expect = std.testing.expect; |
| 8342 | 8343 | |
| 8343 | 8344 | test "@src" { |
| 8344 | doTheTest(); | |
| 8345 | try doTheTest(); | |
| 8345 | 8346 | } |
| 8346 | 8347 | |
| 8347 | fn doTheTest() void { | |
| 8348 | fn doTheTest() !void { | |
| 8348 | 8349 | const src = @src(); |
| 8349 | 8350 | |
| 8350 | expect(src.line == 9); | |
| 8351 | expect(src.column == 17); | |
| 8352 | expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); | |
| 8353 | expect(std.mem.endsWith(u8, src.file, "test.zig")); | |
| 8351 | try expect(src.line == 9); | |
| 8352 | try expect(src.column == 17); | |
| 8353 | try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); | |
| 8354 | try expect(std.mem.endsWith(u8, src.file, "test.zig")); | |
| 8354 | 8355 | } |
| 8355 | 8356 | {#code_end#} |
| 8356 | 8357 | {#header_close#} |
| ... | ... | @@ -8527,7 +8528,7 @@ const expect = std.testing.expect; |
| 8527 | 8528 | test "@This()" { |
| 8528 | 8529 | var items = [_]i32{ 1, 2, 3, 4 }; |
| 8529 | 8530 | const list = List(i32){ .items = items[0..] }; |
| 8530 | expect(list.length() == 4); | |
| 8531 | try expect(list.length() == 4); | |
| 8531 | 8532 | } |
| 8532 | 8533 | |
| 8533 | 8534 | fn List(comptime T: type) type { |
| ... | ... | @@ -8573,7 +8574,7 @@ const expect = std.testing.expect; |
| 8573 | 8574 | test "integer truncation" { |
| 8574 | 8575 | var a: u16 = 0xabcd; |
| 8575 | 8576 | var b: u8 = @truncate(u8, a); |
| 8576 | expect(b == 0xcd); | |
| 8577 | try expect(b == 0xcd); | |
| 8577 | 8578 | } |
| 8578 | 8579 | {#code_end#} |
| 8579 | 8580 | <p> |
| ... | ... | @@ -8661,8 +8662,8 @@ const expect = std.testing.expect; |
| 8661 | 8662 | test "no runtime side effects" { |
| 8662 | 8663 | var data: i32 = 0; |
| 8663 | 8664 | const T = @TypeOf(foo(i32, &data)); |
| 8664 | comptime expect(T == i32); | |
| 8665 | expect(data == 0); | |
| 8665 | comptime try expect(T == i32); | |
| 8666 | try expect(data == 0); | |
| 8666 | 8667 | } |
| 8667 | 8668 | |
| 8668 | 8669 | fn foo(comptime T: type, ptr: *T) T { |
| ... | ... | @@ -8972,9 +8973,9 @@ const maxInt = std.math.maxInt; |
| 8972 | 8973 | test "wraparound addition and subtraction" { |
| 8973 | 8974 | const x: i32 = maxInt(i32); |
| 8974 | 8975 | const min_val = x +% 1; |
| 8975 | expect(min_val == minInt(i32)); | |
| 8976 | try expect(min_val == minInt(i32)); | |
| 8976 | 8977 | const max_val = min_val -% 1; |
| 8977 | expect(max_val == maxInt(i32)); | |
| 8978 | try expect(max_val == maxInt(i32)); | |
| 8978 | 8979 | } |
| 8979 | 8980 | {#code_end#} |
| 8980 | 8981 | {#header_close#} |
| ... | ... | @@ -9405,7 +9406,7 @@ test "using an allocator" { |
| 9405 | 9406 | var buffer: [100]u8 = undefined; |
| 9406 | 9407 | const allocator = &std.heap.FixedBufferAllocator.init(&buffer).allocator; |
| 9407 | 9408 | const result = try concat(allocator, "foo", "bar"); |
| 9408 | expect(std.mem.eql(u8, "foobar", result)); | |
| 9409 | try expect(std.mem.eql(u8, "foobar", result)); | |
| 9409 | 9410 | } |
| 9410 | 9411 | |
| 9411 | 9412 | fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 { |
| ... | ... | @@ -9675,7 +9676,7 @@ const builtin = std.builtin; |
| 9675 | 9676 | const expect = std.testing.expect; |
| 9676 | 9677 | |
| 9677 | 9678 | test "builtin.is_test" { |
| 9678 | expect(builtin.is_test); | |
| 9679 | try expect(builtin.is_test); | |
| 9679 | 9680 | } |
| 9680 | 9681 | {#code_end#} |
| 9681 | 9682 | <p> |
| ... | ... | @@ -9720,13 +9721,13 @@ test "assert in release fast mode" { |
| 9720 | 9721 | <p> |
| 9721 | 9722 | Better practice for checking the output when testing is to use {#syntax#}std.testing.expect{#endsyntax#}: |
| 9722 | 9723 | </p> |
| 9723 | {#code_begin|test_err|test failure#} | |
| 9724 | {#code_begin|test_err|test "expect in release fast mode"... FAIL (TestUnexpectedResult)#} | |
| 9724 | 9725 | {#code_release_fast#} |
| 9725 | 9726 | const std = @import("std"); |
| 9726 | 9727 | const expect = std.testing.expect; |
| 9727 | 9728 | |
| 9728 | 9729 | test "expect in release fast mode" { |
| 9729 | expect(false); | |
| 9730 | try expect(false); | |
| 9730 | 9731 | } |
| 9731 | 9732 | {#code_end#} |
| 9732 | 9733 | <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 | 249 | "+justmeta", |
| 250 | 250 | "9.8.7+meta+meta", |
| 251 | 251 | "9.8.7-whatever+meta+meta", |
| 252 | }) |invalid| expectError(error.InvalidVersion, parse(invalid)); | |
| 252 | }) |invalid| try expectError(error.InvalidVersion, parse(invalid)); | |
| 253 | 253 | |
| 254 | 254 | // Valid version string that may overflow. |
| 255 | 255 | const big_valid = "99999999999999999999999.999999999999999999.99999999999999999"; |
| 256 | 256 | if (parse(big_valid)) |ver| { |
| 257 | 257 | try std.testing.expectFmt(big_valid, "{}", .{ver}); |
| 258 | } else |err| expect(err == error.Overflow); | |
| 258 | } else |err| try expect(err == error.Overflow); | |
| 259 | 259 | |
| 260 | 260 | // Invalid version string that may overflow. |
| 261 | 261 | const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12"; |
| ... | ... | @@ -264,22 +264,22 @@ test "SemanticVersion format" { |
| 264 | 264 | |
| 265 | 265 | test "SemanticVersion precedence" { |
| 266 | 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); | |
| 268 | expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt); | |
| 269 | expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt); | |
| 267 | try expect(order(try parse("1.0.0"), try parse("2.0.0")) == .lt); | |
| 268 | try expect(order(try parse("2.0.0"), try parse("2.1.0")) == .lt); | |
| 269 | try expect(order(try parse("2.1.0"), try parse("2.1.1")) == .lt); | |
| 270 | 270 | |
| 271 | 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); | |
| 273 | 273 | |
| 274 | 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 | 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); | |
| 277 | expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt); | |
| 278 | expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt); | |
| 279 | expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt); | |
| 280 | expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt); | |
| 281 | expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt); | |
| 282 | expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt); | |
| 276 | try expect(order(try parse("1.0.0-alpha"), try parse("1.0.0-alpha.1")) == .lt); | |
| 277 | try expect(order(try parse("1.0.0-alpha.1"), try parse("1.0.0-alpha.beta")) == .lt); | |
| 278 | try expect(order(try parse("1.0.0-alpha.beta"), try parse("1.0.0-beta")) == .lt); | |
| 279 | try expect(order(try parse("1.0.0-beta"), try parse("1.0.0-beta.2")) == .lt); | |
| 280 | try expect(order(try parse("1.0.0-beta.2"), try parse("1.0.0-beta.11")) == .lt); | |
| 281 | try expect(order(try parse("1.0.0-beta.11"), try parse("1.0.0-rc.1")) == .lt); | |
| 282 | try expect(order(try parse("1.0.0-rc.1"), try parse("1.0.0")) == .lt); | |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | test "zig_version" { |
lib/std/Thread/AutoResetEvent.zig+8-8| ... | ... | @@ -176,7 +176,7 @@ test "basic usage" { |
| 176 | 176 | // test local code paths |
| 177 | 177 | { |
| 178 | 178 | var event = AutoResetEvent{}; |
| 179 | testing.expectError(error.TimedOut, event.timedWait(1)); | |
| 179 | try testing.expectError(error.TimedOut, event.timedWait(1)); | |
| 180 | 180 | event.set(); |
| 181 | 181 | event.wait(); |
| 182 | 182 | } |
| ... | ... | @@ -192,28 +192,28 @@ test "basic usage" { |
| 192 | 192 | |
| 193 | 193 | const Self = @This(); |
| 194 | 194 | |
| 195 | fn sender(self: *Self) void { | |
| 196 | testing.expect(self.value == 0); | |
| 195 | fn sender(self: *Self) !void { | |
| 196 | try testing.expect(self.value == 0); | |
| 197 | 197 | self.value = 1; |
| 198 | 198 | self.out.set(); |
| 199 | 199 | |
| 200 | 200 | self.in.wait(); |
| 201 | testing.expect(self.value == 2); | |
| 201 | try testing.expect(self.value == 2); | |
| 202 | 202 | self.value = 3; |
| 203 | 203 | self.out.set(); |
| 204 | 204 | |
| 205 | 205 | self.in.wait(); |
| 206 | testing.expect(self.value == 4); | |
| 206 | try testing.expect(self.value == 4); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | fn receiver(self: *Self) void { | |
| 209 | fn receiver(self: *Self) !void { | |
| 210 | 210 | self.out.wait(); |
| 211 | testing.expect(self.value == 1); | |
| 211 | try testing.expect(self.value == 1); | |
| 212 | 212 | self.value = 2; |
| 213 | 213 | self.in.set(); |
| 214 | 214 | |
| 215 | 215 | self.out.wait(); |
| 216 | testing.expect(self.value == 3); | |
| 216 | try testing.expect(self.value == 3); | |
| 217 | 217 | self.value = 4; |
| 218 | 218 | self.in.set(); |
| 219 | 219 | } |
lib/std/Thread/Mutex.zig+2-2| ... | ... | @@ -294,7 +294,7 @@ test "basic usage" { |
| 294 | 294 | |
| 295 | 295 | if (builtin.single_threaded) { |
| 296 | 296 | worker(&context); |
| 297 | testing.expect(context.data == TestContext.incr_count); | |
| 297 | try testing.expect(context.data == TestContext.incr_count); | |
| 298 | 298 | } else { |
| 299 | 299 | const thread_count = 10; |
| 300 | 300 | var threads: [thread_count]*std.Thread = undefined; |
| ... | ... | @@ -304,7 +304,7 @@ test "basic usage" { |
| 304 | 304 | for (threads) |t| |
| 305 | 305 | t.wait(); |
| 306 | 306 | |
| 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 | } |
| 310 | 310 |
lib/std/Thread/ResetEvent.zig+10-10| ... | ... | @@ -204,7 +204,7 @@ test "basic usage" { |
| 204 | 204 | event.reset(); |
| 205 | 205 | |
| 206 | 206 | event.set(); |
| 207 | testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1)); | |
| 207 | try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1)); | |
| 208 | 208 | |
| 209 | 209 | // test cross-thread signaling |
| 210 | 210 | if (builtin.single_threaded) |
| ... | ... | @@ -233,25 +233,25 @@ test "basic usage" { |
| 233 | 233 | self.* = undefined; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | fn sender(self: *Self) void { | |
| 236 | fn sender(self: *Self) !void { | |
| 237 | 237 | // update value and signal input |
| 238 | testing.expect(self.value == 0); | |
| 238 | try testing.expect(self.value == 0); | |
| 239 | 239 | self.value = 1; |
| 240 | 240 | self.in.set(); |
| 241 | 241 | |
| 242 | 242 | // wait for receiver to update value and signal output |
| 243 | 243 | self.out.wait(); |
| 244 | testing.expect(self.value == 2); | |
| 244 | try testing.expect(self.value == 2); | |
| 245 | 245 | |
| 246 | 246 | // update value and signal final input |
| 247 | 247 | self.value = 3; |
| 248 | 248 | self.in.set(); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | fn receiver(self: *Self) void { | |
| 251 | fn receiver(self: *Self) !void { | |
| 252 | 252 | // wait for sender to update value and signal input |
| 253 | 253 | self.in.wait(); |
| 254 | assert(self.value == 1); | |
| 254 | try testing.expect(self.value == 1); | |
| 255 | 255 | |
| 256 | 256 | // update value and signal output |
| 257 | 257 | self.in.reset(); |
| ... | ... | @@ -260,7 +260,7 @@ test "basic usage" { |
| 260 | 260 | |
| 261 | 261 | // wait for sender to update value and signal final input |
| 262 | 262 | self.in.wait(); |
| 263 | assert(self.value == 3); | |
| 263 | try testing.expect(self.value == 3); | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | fn sleeper(self: *Self) void { |
| ... | ... | @@ -272,9 +272,9 @@ test "basic usage" { |
| 272 | 272 | |
| 273 | 273 | fn timedWaiter(self: *Self) !void { |
| 274 | 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 | 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 | }; |
| 280 | 280 | |
| ... | ... | @@ -283,7 +283,7 @@ test "basic usage" { |
| 283 | 283 | defer context.deinit(); |
| 284 | 284 | const receiver = try std.Thread.spawn(Context.receiver, &context); |
| 285 | 285 | defer receiver.wait(); |
| 286 | context.sender(); | |
| 286 | try context.sender(); | |
| 287 | 287 | |
| 288 | 288 | if (false) { |
| 289 | 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 | 320 | event.reset(); |
| 321 | 321 | |
| 322 | 322 | event.set(); |
| 323 | testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1)); | |
| 323 | try testing.expectEqual(TimedWaitResult.event_set, event.timedWait(1)); | |
| 324 | 324 | |
| 325 | 325 | // test cross-thread signaling |
| 326 | 326 | if (std.builtin.single_threaded) |
| ... | ... | @@ -333,25 +333,25 @@ test "basic usage" { |
| 333 | 333 | in: StaticResetEvent = .{}, |
| 334 | 334 | out: StaticResetEvent = .{}, |
| 335 | 335 | |
| 336 | fn sender(self: *Self) void { | |
| 336 | fn sender(self: *Self) !void { | |
| 337 | 337 | // update value and signal input |
| 338 | testing.expect(self.value == 0); | |
| 338 | try testing.expect(self.value == 0); | |
| 339 | 339 | self.value = 1; |
| 340 | 340 | self.in.set(); |
| 341 | 341 | |
| 342 | 342 | // wait for receiver to update value and signal output |
| 343 | 343 | self.out.wait(); |
| 344 | testing.expect(self.value == 2); | |
| 344 | try testing.expect(self.value == 2); | |
| 345 | 345 | |
| 346 | 346 | // update value and signal final input |
| 347 | 347 | self.value = 3; |
| 348 | 348 | self.in.set(); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | fn receiver(self: *Self) void { | |
| 351 | fn receiver(self: *Self) !void { | |
| 352 | 352 | // wait for sender to update value and signal input |
| 353 | 353 | self.in.wait(); |
| 354 | assert(self.value == 1); | |
| 354 | try testing.expect(self.value == 1); | |
| 355 | 355 | |
| 356 | 356 | // update value and signal output |
| 357 | 357 | self.in.reset(); |
| ... | ... | @@ -360,7 +360,7 @@ test "basic usage" { |
| 360 | 360 | |
| 361 | 361 | // wait for sender to update value and signal final input |
| 362 | 362 | self.in.wait(); |
| 363 | assert(self.value == 3); | |
| 363 | try testing.expect(self.value == 3); | |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | fn sleeper(self: *Self) void { |
| ... | ... | @@ -372,16 +372,16 @@ test "basic usage" { |
| 372 | 372 | |
| 373 | 373 | fn timedWaiter(self: *Self) !void { |
| 374 | 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 | 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 | }; |
| 380 | 380 | |
| 381 | 381 | var context = Context{}; |
| 382 | 382 | const receiver = try std.Thread.spawn(Context.receiver, &context); |
| 383 | 383 | defer receiver.wait(); |
| 384 | context.sender(); | |
| 384 | try context.sender(); | |
| 385 | 385 | |
| 386 | 386 | if (false) { |
| 387 | 387 | // I have now observed this fail on macOS, Windows, and Linux. |
lib/std/array_hash_map.zig+68-68| ... | ... | @@ -1064,63 +1064,63 @@ test "basic hash map usage" { |
| 1064 | 1064 | var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); |
| 1065 | 1065 | defer map.deinit(); |
| 1066 | 1066 | |
| 1067 | testing.expect((try map.fetchPut(1, 11)) == null); | |
| 1068 | testing.expect((try map.fetchPut(2, 22)) == null); | |
| 1069 | testing.expect((try map.fetchPut(3, 33)) == null); | |
| 1070 | testing.expect((try map.fetchPut(4, 44)) == null); | |
| 1067 | try testing.expect((try map.fetchPut(1, 11)) == null); | |
| 1068 | try testing.expect((try map.fetchPut(2, 22)) == null); | |
| 1069 | try testing.expect((try map.fetchPut(3, 33)) == null); | |
| 1070 | try testing.expect((try map.fetchPut(4, 44)) == null); | |
| 1071 | 1071 | |
| 1072 | 1072 | try map.putNoClobber(5, 55); |
| 1073 | testing.expect((try map.fetchPut(5, 66)).?.value == 55); | |
| 1074 | testing.expect((try map.fetchPut(5, 55)).?.value == 66); | |
| 1073 | try testing.expect((try map.fetchPut(5, 66)).?.value == 55); | |
| 1074 | try testing.expect((try map.fetchPut(5, 55)).?.value == 66); | |
| 1075 | 1075 | |
| 1076 | 1076 | const gop1 = try map.getOrPut(5); |
| 1077 | testing.expect(gop1.found_existing == true); | |
| 1078 | testing.expect(gop1.entry.value == 55); | |
| 1079 | testing.expect(gop1.index == 4); | |
| 1077 | try testing.expect(gop1.found_existing == true); | |
| 1078 | try testing.expect(gop1.entry.value == 55); | |
| 1079 | try testing.expect(gop1.index == 4); | |
| 1080 | 1080 | gop1.entry.value = 77; |
| 1081 | testing.expect(map.getEntry(5).?.value == 77); | |
| 1081 | try testing.expect(map.getEntry(5).?.value == 77); | |
| 1082 | 1082 | |
| 1083 | 1083 | const gop2 = try map.getOrPut(99); |
| 1084 | testing.expect(gop2.found_existing == false); | |
| 1085 | testing.expect(gop2.index == 5); | |
| 1084 | try testing.expect(gop2.found_existing == false); | |
| 1085 | try testing.expect(gop2.index == 5); | |
| 1086 | 1086 | gop2.entry.value = 42; |
| 1087 | testing.expect(map.getEntry(99).?.value == 42); | |
| 1087 | try testing.expect(map.getEntry(99).?.value == 42); | |
| 1088 | 1088 | |
| 1089 | 1089 | const gop3 = try map.getOrPutValue(5, 5); |
| 1090 | testing.expect(gop3.value == 77); | |
| 1090 | try testing.expect(gop3.value == 77); | |
| 1091 | 1091 | |
| 1092 | 1092 | const gop4 = try map.getOrPutValue(100, 41); |
| 1093 | testing.expect(gop4.value == 41); | |
| 1093 | try testing.expect(gop4.value == 41); | |
| 1094 | 1094 | |
| 1095 | testing.expect(map.contains(2)); | |
| 1096 | testing.expect(map.getEntry(2).?.value == 22); | |
| 1097 | testing.expect(map.get(2).? == 22); | |
| 1095 | try testing.expect(map.contains(2)); | |
| 1096 | try testing.expect(map.getEntry(2).?.value == 22); | |
| 1097 | try testing.expect(map.get(2).? == 22); | |
| 1098 | 1098 | |
| 1099 | 1099 | const rmv1 = map.swapRemove(2); |
| 1100 | testing.expect(rmv1.?.key == 2); | |
| 1101 | testing.expect(rmv1.?.value == 22); | |
| 1102 | testing.expect(map.swapRemove(2) == null); | |
| 1103 | testing.expect(map.getEntry(2) == null); | |
| 1104 | testing.expect(map.get(2) == null); | |
| 1100 | try testing.expect(rmv1.?.key == 2); | |
| 1101 | try testing.expect(rmv1.?.value == 22); | |
| 1102 | try testing.expect(map.swapRemove(2) == null); | |
| 1103 | try testing.expect(map.getEntry(2) == null); | |
| 1104 | try testing.expect(map.get(2) == null); | |
| 1105 | 1105 | |
| 1106 | 1106 | // Since we've used `swapRemove` above, the index of this entry should remain unchanged. |
| 1107 | testing.expect(map.getIndex(100).? == 1); | |
| 1107 | try testing.expect(map.getIndex(100).? == 1); | |
| 1108 | 1108 | const gop5 = try map.getOrPut(5); |
| 1109 | testing.expect(gop5.found_existing == true); | |
| 1110 | testing.expect(gop5.entry.value == 77); | |
| 1111 | testing.expect(gop5.index == 4); | |
| 1109 | try testing.expect(gop5.found_existing == true); | |
| 1110 | try testing.expect(gop5.entry.value == 77); | |
| 1111 | try testing.expect(gop5.index == 4); | |
| 1112 | 1112 | |
| 1113 | 1113 | // Whereas, if we do an `orderedRemove`, it should move the index forward one spot. |
| 1114 | 1114 | const rmv2 = map.orderedRemove(100); |
| 1115 | testing.expect(rmv2.?.key == 100); | |
| 1116 | testing.expect(rmv2.?.value == 41); | |
| 1117 | testing.expect(map.orderedRemove(100) == null); | |
| 1118 | testing.expect(map.getEntry(100) == null); | |
| 1119 | testing.expect(map.get(100) == null); | |
| 1115 | try testing.expect(rmv2.?.key == 100); | |
| 1116 | try testing.expect(rmv2.?.value == 41); | |
| 1117 | try testing.expect(map.orderedRemove(100) == null); | |
| 1118 | try testing.expect(map.getEntry(100) == null); | |
| 1119 | try testing.expect(map.get(100) == null); | |
| 1120 | 1120 | const gop6 = try map.getOrPut(5); |
| 1121 | testing.expect(gop6.found_existing == true); | |
| 1122 | testing.expect(gop6.entry.value == 77); | |
| 1123 | testing.expect(gop6.index == 3); | |
| 1121 | try testing.expect(gop6.found_existing == true); | |
| 1122 | try testing.expect(gop6.entry.value == 77); | |
| 1123 | try testing.expect(gop6.index == 3); | |
| 1124 | 1124 | |
| 1125 | 1125 | map.removeAssertDiscard(3); |
| 1126 | 1126 | } |
| ... | ... | @@ -1156,11 +1156,11 @@ test "iterator hash map" { |
| 1156 | 1156 | while (it.next()) |entry| : (count += 1) { |
| 1157 | 1157 | buffer[@intCast(usize, entry.key)] = entry.value; |
| 1158 | 1158 | } |
| 1159 | testing.expect(count == 3); | |
| 1160 | testing.expect(it.next() == null); | |
| 1159 | try testing.expect(count == 3); | |
| 1160 | try testing.expect(it.next() == null); | |
| 1161 | 1161 | |
| 1162 | 1162 | for (buffer) |v, i| { |
| 1163 | testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | |
| 1163 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | it.reset(); |
| ... | ... | @@ -1172,13 +1172,13 @@ test "iterator hash map" { |
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | for (buffer[0..2]) |v, i| { |
| 1175 | testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | |
| 1175 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | it.reset(); |
| 1179 | 1179 | var entry = it.next().?; |
| 1180 | testing.expect(entry.key == first_entry.key); | |
| 1181 | testing.expect(entry.value == first_entry.value); | |
| 1180 | try testing.expect(entry.key == first_entry.key); | |
| 1181 | try testing.expect(entry.value == first_entry.value); | |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | test "ensure capacity" { |
| ... | ... | @@ -1187,13 +1187,13 @@ test "ensure capacity" { |
| 1187 | 1187 | |
| 1188 | 1188 | try map.ensureCapacity(20); |
| 1189 | 1189 | const initial_capacity = map.capacity(); |
| 1190 | testing.expect(initial_capacity >= 20); | |
| 1190 | try testing.expect(initial_capacity >= 20); | |
| 1191 | 1191 | var i: i32 = 0; |
| 1192 | 1192 | while (i < 20) : (i += 1) { |
| 1193 | testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null); | |
| 1193 | try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null); | |
| 1194 | 1194 | } |
| 1195 | 1195 | // shouldn't resize from putAssumeCapacity |
| 1196 | testing.expect(initial_capacity == map.capacity()); | |
| 1196 | try testing.expect(initial_capacity == map.capacity()); | |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | test "clone" { |
| ... | ... | @@ -1211,7 +1211,7 @@ test "clone" { |
| 1211 | 1211 | |
| 1212 | 1212 | i = 0; |
| 1213 | 1213 | while (i < 10) : (i += 1) { |
| 1214 | testing.expect(copy.get(i).? == i * 10); | |
| 1214 | try testing.expect(copy.get(i).? == i * 10); | |
| 1215 | 1215 | } |
| 1216 | 1216 | } |
| 1217 | 1217 | |
| ... | ... | @@ -1223,35 +1223,35 @@ test "shrink" { |
| 1223 | 1223 | const num_entries = 20; |
| 1224 | 1224 | var i: i32 = 0; |
| 1225 | 1225 | while (i < num_entries) : (i += 1) |
| 1226 | testing.expect((try map.fetchPut(i, i * 10)) == null); | |
| 1226 | try testing.expect((try map.fetchPut(i, i * 10)) == null); | |
| 1227 | 1227 | |
| 1228 | testing.expect(map.unmanaged.index_header != null); | |
| 1229 | testing.expect(map.count() == num_entries); | |
| 1228 | try testing.expect(map.unmanaged.index_header != null); | |
| 1229 | try testing.expect(map.count() == num_entries); | |
| 1230 | 1230 | |
| 1231 | 1231 | // Test `shrinkRetainingCapacity`. |
| 1232 | 1232 | map.shrinkRetainingCapacity(17); |
| 1233 | testing.expect(map.count() == 17); | |
| 1234 | testing.expect(map.capacity() == 20); | |
| 1233 | try testing.expect(map.count() == 17); | |
| 1234 | try testing.expect(map.capacity() == 20); | |
| 1235 | 1235 | i = 0; |
| 1236 | 1236 | while (i < num_entries) : (i += 1) { |
| 1237 | 1237 | const gop = try map.getOrPut(i); |
| 1238 | 1238 | if (i < 17) { |
| 1239 | testing.expect(gop.found_existing == true); | |
| 1240 | testing.expect(gop.entry.value == i * 10); | |
| 1241 | } else testing.expect(gop.found_existing == false); | |
| 1239 | try testing.expect(gop.found_existing == true); | |
| 1240 | try testing.expect(gop.entry.value == i * 10); | |
| 1241 | } else try testing.expect(gop.found_existing == false); | |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | // Test `shrinkAndFree`. |
| 1245 | 1245 | map.shrinkAndFree(15); |
| 1246 | testing.expect(map.count() == 15); | |
| 1247 | testing.expect(map.capacity() == 15); | |
| 1246 | try testing.expect(map.count() == 15); | |
| 1247 | try testing.expect(map.capacity() == 15); | |
| 1248 | 1248 | i = 0; |
| 1249 | 1249 | while (i < num_entries) : (i += 1) { |
| 1250 | 1250 | const gop = try map.getOrPut(i); |
| 1251 | 1251 | if (i < 15) { |
| 1252 | testing.expect(gop.found_existing == true); | |
| 1253 | testing.expect(gop.entry.value == i * 10); | |
| 1254 | } else testing.expect(gop.found_existing == false); | |
| 1252 | try testing.expect(gop.found_existing == true); | |
| 1253 | try testing.expect(gop.entry.value == i * 10); | |
| 1254 | } else try testing.expect(gop.found_existing == false); | |
| 1255 | 1255 | } |
| 1256 | 1256 | } |
| 1257 | 1257 | |
| ... | ... | @@ -1264,12 +1264,12 @@ test "pop" { |
| 1264 | 1264 | |
| 1265 | 1265 | var i: i32 = 0; |
| 1266 | 1266 | while (i < 9) : (i += 1) { |
| 1267 | testing.expect((try map.fetchPut(i, i)) == null); | |
| 1267 | try testing.expect((try map.fetchPut(i, i)) == null); | |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | while (i > 0) : (i -= 1) { |
| 1271 | 1271 | const pop = map.pop(); |
| 1272 | testing.expect(pop.key == i - 1 and pop.value == i - 1); | |
| 1272 | try testing.expect(pop.key == i - 1 and pop.value == i - 1); | |
| 1273 | 1273 | } |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| ... | ... | @@ -1281,10 +1281,10 @@ test "reIndex" { |
| 1281 | 1281 | const num_indexed_entries = 20; |
| 1282 | 1282 | var i: i32 = 0; |
| 1283 | 1283 | while (i < num_indexed_entries) : (i += 1) |
| 1284 | testing.expect((try map.fetchPut(i, i * 10)) == null); | |
| 1284 | try testing.expect((try map.fetchPut(i, i * 10)) == null); | |
| 1285 | 1285 | |
| 1286 | 1286 | // Make sure we allocated an index header. |
| 1287 | testing.expect(map.unmanaged.index_header != null); | |
| 1287 | try testing.expect(map.unmanaged.index_header != null); | |
| 1288 | 1288 | |
| 1289 | 1289 | // Now write to the underlying array list directly. |
| 1290 | 1290 | const num_unindexed_entries = 20; |
| ... | ... | @@ -1303,9 +1303,9 @@ test "reIndex" { |
| 1303 | 1303 | i = 0; |
| 1304 | 1304 | while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) { |
| 1305 | 1305 | const gop = try map.getOrPut(i); |
| 1306 | testing.expect(gop.found_existing == true); | |
| 1307 | testing.expect(gop.entry.value == i * 10); | |
| 1308 | testing.expect(gop.index == i); | |
| 1306 | try testing.expect(gop.found_existing == true); | |
| 1307 | try testing.expect(gop.entry.value == i * 10); | |
| 1308 | try testing.expect(gop.index == i); | |
| 1309 | 1309 | } |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| ... | ... | @@ -1332,9 +1332,9 @@ test "fromOwnedArrayList" { |
| 1332 | 1332 | i = 0; |
| 1333 | 1333 | while (i < num_entries) : (i += 1) { |
| 1334 | 1334 | const gop = try map.getOrPut(i); |
| 1335 | testing.expect(gop.found_existing == true); | |
| 1336 | testing.expect(gop.entry.value == i * 10); | |
| 1337 | testing.expect(gop.index == i); | |
| 1335 | try testing.expect(gop.found_existing == true); | |
| 1336 | try testing.expect(gop.entry.value == i * 10); | |
| 1337 | try testing.expect(gop.index == i); | |
| 1338 | 1338 | } |
| 1339 | 1339 | } |
| 1340 | 1340 |
lib/std/array_list.zig+116-116| ... | ... | @@ -695,15 +695,15 @@ test "std.ArrayList/ArrayListUnmanaged.init" { |
| 695 | 695 | var list = ArrayList(i32).init(testing.allocator); |
| 696 | 696 | defer list.deinit(); |
| 697 | 697 | |
| 698 | testing.expect(list.items.len == 0); | |
| 699 | testing.expect(list.capacity == 0); | |
| 698 | try testing.expect(list.items.len == 0); | |
| 699 | try testing.expect(list.capacity == 0); | |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | { |
| 703 | 703 | var list = ArrayListUnmanaged(i32){}; |
| 704 | 704 | |
| 705 | testing.expect(list.items.len == 0); | |
| 706 | testing.expect(list.capacity == 0); | |
| 705 | try testing.expect(list.items.len == 0); | |
| 706 | try testing.expect(list.capacity == 0); | |
| 707 | 707 | } |
| 708 | 708 | } |
| 709 | 709 | |
| ... | ... | @@ -712,14 +712,14 @@ test "std.ArrayList/ArrayListUnmanaged.initCapacity" { |
| 712 | 712 | { |
| 713 | 713 | var list = try ArrayList(i8).initCapacity(a, 200); |
| 714 | 714 | defer list.deinit(); |
| 715 | testing.expect(list.items.len == 0); | |
| 716 | testing.expect(list.capacity >= 200); | |
| 715 | try testing.expect(list.items.len == 0); | |
| 716 | try testing.expect(list.capacity >= 200); | |
| 717 | 717 | } |
| 718 | 718 | { |
| 719 | 719 | var list = try ArrayListUnmanaged(i8).initCapacity(a, 200); |
| 720 | 720 | defer list.deinit(a); |
| 721 | testing.expect(list.items.len == 0); | |
| 722 | testing.expect(list.capacity >= 200); | |
| 721 | try testing.expect(list.items.len == 0); | |
| 722 | try testing.expect(list.capacity >= 200); | |
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | |
| ... | ... | @@ -739,33 +739,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { |
| 739 | 739 | { |
| 740 | 740 | var i: usize = 0; |
| 741 | 741 | while (i < 10) : (i += 1) { |
| 742 | testing.expect(list.items[i] == @intCast(i32, i + 1)); | |
| 742 | try testing.expect(list.items[i] == @intCast(i32, i + 1)); | |
| 743 | 743 | } |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | for (list.items) |v, i| { |
| 747 | testing.expect(v == @intCast(i32, i + 1)); | |
| 747 | try testing.expect(v == @intCast(i32, i + 1)); | |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | testing.expect(list.pop() == 10); | |
| 751 | testing.expect(list.items.len == 9); | |
| 750 | try testing.expect(list.pop() == 10); | |
| 751 | try testing.expect(list.items.len == 9); | |
| 752 | 752 | |
| 753 | 753 | list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable; |
| 754 | testing.expect(list.items.len == 12); | |
| 755 | testing.expect(list.pop() == 3); | |
| 756 | testing.expect(list.pop() == 2); | |
| 757 | testing.expect(list.pop() == 1); | |
| 758 | testing.expect(list.items.len == 9); | |
| 754 | try testing.expect(list.items.len == 12); | |
| 755 | try testing.expect(list.pop() == 3); | |
| 756 | try testing.expect(list.pop() == 2); | |
| 757 | try testing.expect(list.pop() == 1); | |
| 758 | try testing.expect(list.items.len == 9); | |
| 759 | 759 | |
| 760 | 760 | list.appendSlice(&[_]i32{}) catch unreachable; |
| 761 | testing.expect(list.items.len == 9); | |
| 761 | try testing.expect(list.items.len == 9); | |
| 762 | 762 | |
| 763 | 763 | // can only set on indices < self.items.len |
| 764 | 764 | list.items[7] = 33; |
| 765 | 765 | list.items[8] = 42; |
| 766 | 766 | |
| 767 | testing.expect(list.pop() == 42); | |
| 768 | testing.expect(list.pop() == 33); | |
| 767 | try testing.expect(list.pop() == 42); | |
| 768 | try testing.expect(list.pop() == 33); | |
| 769 | 769 | } |
| 770 | 770 | { |
| 771 | 771 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -781,33 +781,33 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { |
| 781 | 781 | { |
| 782 | 782 | var i: usize = 0; |
| 783 | 783 | while (i < 10) : (i += 1) { |
| 784 | testing.expect(list.items[i] == @intCast(i32, i + 1)); | |
| 784 | try testing.expect(list.items[i] == @intCast(i32, i + 1)); | |
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | for (list.items) |v, i| { |
| 789 | testing.expect(v == @intCast(i32, i + 1)); | |
| 789 | try testing.expect(v == @intCast(i32, i + 1)); | |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | testing.expect(list.pop() == 10); | |
| 793 | testing.expect(list.items.len == 9); | |
| 792 | try testing.expect(list.pop() == 10); | |
| 793 | try testing.expect(list.items.len == 9); | |
| 794 | 794 | |
| 795 | 795 | list.appendSlice(a, &[_]i32{ 1, 2, 3 }) catch unreachable; |
| 796 | testing.expect(list.items.len == 12); | |
| 797 | testing.expect(list.pop() == 3); | |
| 798 | testing.expect(list.pop() == 2); | |
| 799 | testing.expect(list.pop() == 1); | |
| 800 | testing.expect(list.items.len == 9); | |
| 796 | try testing.expect(list.items.len == 12); | |
| 797 | try testing.expect(list.pop() == 3); | |
| 798 | try testing.expect(list.pop() == 2); | |
| 799 | try testing.expect(list.pop() == 1); | |
| 800 | try testing.expect(list.items.len == 9); | |
| 801 | 801 | |
| 802 | 802 | list.appendSlice(a, &[_]i32{}) catch unreachable; |
| 803 | testing.expect(list.items.len == 9); | |
| 803 | try testing.expect(list.items.len == 9); | |
| 804 | 804 | |
| 805 | 805 | // can only set on indices < self.items.len |
| 806 | 806 | list.items[7] = 33; |
| 807 | 807 | list.items[8] = 42; |
| 808 | 808 | |
| 809 | testing.expect(list.pop() == 42); | |
| 810 | testing.expect(list.pop() == 33); | |
| 809 | try testing.expect(list.pop() == 42); | |
| 810 | try testing.expect(list.pop() == 33); | |
| 811 | 811 | } |
| 812 | 812 | } |
| 813 | 813 | |
| ... | ... | @@ -818,9 +818,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" { |
| 818 | 818 | defer list.deinit(); |
| 819 | 819 | |
| 820 | 820 | try list.appendNTimes(2, 10); |
| 821 | testing.expectEqual(@as(usize, 10), list.items.len); | |
| 821 | try testing.expectEqual(@as(usize, 10), list.items.len); | |
| 822 | 822 | for (list.items) |element| { |
| 823 | testing.expectEqual(@as(i32, 2), element); | |
| 823 | try testing.expectEqual(@as(i32, 2), element); | |
| 824 | 824 | } |
| 825 | 825 | } |
| 826 | 826 | { |
| ... | ... | @@ -828,9 +828,9 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes" { |
| 828 | 828 | defer list.deinit(a); |
| 829 | 829 | |
| 830 | 830 | try list.appendNTimes(a, 2, 10); |
| 831 | testing.expectEqual(@as(usize, 10), list.items.len); | |
| 831 | try testing.expectEqual(@as(usize, 10), list.items.len); | |
| 832 | 832 | for (list.items) |element| { |
| 833 | testing.expectEqual(@as(i32, 2), element); | |
| 833 | try testing.expectEqual(@as(i32, 2), element); | |
| 834 | 834 | } |
| 835 | 835 | } |
| 836 | 836 | } |
| ... | ... | @@ -840,12 +840,12 @@ test "std.ArrayList/ArrayListUnmanaged.appendNTimes with failing allocator" { |
| 840 | 840 | { |
| 841 | 841 | var list = ArrayList(i32).init(a); |
| 842 | 842 | defer list.deinit(); |
| 843 | testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10)); | |
| 843 | try testing.expectError(error.OutOfMemory, list.appendNTimes(2, 10)); | |
| 844 | 844 | } |
| 845 | 845 | { |
| 846 | 846 | var list = ArrayListUnmanaged(i32){}; |
| 847 | 847 | defer list.deinit(a); |
| 848 | testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10)); | |
| 848 | try testing.expectError(error.OutOfMemory, list.appendNTimes(a, 2, 10)); | |
| 849 | 849 | } |
| 850 | 850 | } |
| 851 | 851 | |
| ... | ... | @@ -864,18 +864,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" { |
| 864 | 864 | try list.append(7); |
| 865 | 865 | |
| 866 | 866 | //remove from middle |
| 867 | testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); | |
| 868 | testing.expectEqual(@as(i32, 5), list.items[3]); | |
| 869 | testing.expectEqual(@as(usize, 6), list.items.len); | |
| 867 | try testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); | |
| 868 | try testing.expectEqual(@as(i32, 5), list.items[3]); | |
| 869 | try testing.expectEqual(@as(usize, 6), list.items.len); | |
| 870 | 870 | |
| 871 | 871 | //remove from end |
| 872 | testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); | |
| 873 | testing.expectEqual(@as(usize, 5), list.items.len); | |
| 872 | try testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); | |
| 873 | try testing.expectEqual(@as(usize, 5), list.items.len); | |
| 874 | 874 | |
| 875 | 875 | //remove from front |
| 876 | testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); | |
| 877 | testing.expectEqual(@as(i32, 2), list.items[0]); | |
| 878 | testing.expectEqual(@as(usize, 4), list.items.len); | |
| 876 | try testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); | |
| 877 | try testing.expectEqual(@as(i32, 2), list.items[0]); | |
| 878 | try testing.expectEqual(@as(usize, 4), list.items.len); | |
| 879 | 879 | } |
| 880 | 880 | { |
| 881 | 881 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -890,18 +890,18 @@ test "std.ArrayList/ArrayListUnmanaged.orderedRemove" { |
| 890 | 890 | try list.append(a, 7); |
| 891 | 891 | |
| 892 | 892 | //remove from middle |
| 893 | testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); | |
| 894 | testing.expectEqual(@as(i32, 5), list.items[3]); | |
| 895 | testing.expectEqual(@as(usize, 6), list.items.len); | |
| 893 | try testing.expectEqual(@as(i32, 4), list.orderedRemove(3)); | |
| 894 | try testing.expectEqual(@as(i32, 5), list.items[3]); | |
| 895 | try testing.expectEqual(@as(usize, 6), list.items.len); | |
| 896 | 896 | |
| 897 | 897 | //remove from end |
| 898 | testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); | |
| 899 | testing.expectEqual(@as(usize, 5), list.items.len); | |
| 898 | try testing.expectEqual(@as(i32, 7), list.orderedRemove(5)); | |
| 899 | try testing.expectEqual(@as(usize, 5), list.items.len); | |
| 900 | 900 | |
| 901 | 901 | //remove from front |
| 902 | testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); | |
| 903 | testing.expectEqual(@as(i32, 2), list.items[0]); | |
| 904 | testing.expectEqual(@as(usize, 4), list.items.len); | |
| 902 | try testing.expectEqual(@as(i32, 1), list.orderedRemove(0)); | |
| 903 | try testing.expectEqual(@as(i32, 2), list.items[0]); | |
| 904 | try testing.expectEqual(@as(usize, 4), list.items.len); | |
| 905 | 905 | } |
| 906 | 906 | } |
| 907 | 907 | |
| ... | ... | @@ -920,18 +920,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" { |
| 920 | 920 | try list.append(7); |
| 921 | 921 | |
| 922 | 922 | //remove from middle |
| 923 | testing.expect(list.swapRemove(3) == 4); | |
| 924 | testing.expect(list.items[3] == 7); | |
| 925 | testing.expect(list.items.len == 6); | |
| 923 | try testing.expect(list.swapRemove(3) == 4); | |
| 924 | try testing.expect(list.items[3] == 7); | |
| 925 | try testing.expect(list.items.len == 6); | |
| 926 | 926 | |
| 927 | 927 | //remove from end |
| 928 | testing.expect(list.swapRemove(5) == 6); | |
| 929 | testing.expect(list.items.len == 5); | |
| 928 | try testing.expect(list.swapRemove(5) == 6); | |
| 929 | try testing.expect(list.items.len == 5); | |
| 930 | 930 | |
| 931 | 931 | //remove from front |
| 932 | testing.expect(list.swapRemove(0) == 1); | |
| 933 | testing.expect(list.items[0] == 5); | |
| 934 | testing.expect(list.items.len == 4); | |
| 932 | try testing.expect(list.swapRemove(0) == 1); | |
| 933 | try testing.expect(list.items[0] == 5); | |
| 934 | try testing.expect(list.items.len == 4); | |
| 935 | 935 | } |
| 936 | 936 | { |
| 937 | 937 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -946,18 +946,18 @@ test "std.ArrayList/ArrayListUnmanaged.swapRemove" { |
| 946 | 946 | try list.append(a, 7); |
| 947 | 947 | |
| 948 | 948 | //remove from middle |
| 949 | testing.expect(list.swapRemove(3) == 4); | |
| 950 | testing.expect(list.items[3] == 7); | |
| 951 | testing.expect(list.items.len == 6); | |
| 949 | try testing.expect(list.swapRemove(3) == 4); | |
| 950 | try testing.expect(list.items[3] == 7); | |
| 951 | try testing.expect(list.items.len == 6); | |
| 952 | 952 | |
| 953 | 953 | //remove from end |
| 954 | testing.expect(list.swapRemove(5) == 6); | |
| 955 | testing.expect(list.items.len == 5); | |
| 954 | try testing.expect(list.swapRemove(5) == 6); | |
| 955 | try testing.expect(list.items.len == 5); | |
| 956 | 956 | |
| 957 | 957 | //remove from front |
| 958 | testing.expect(list.swapRemove(0) == 1); | |
| 959 | testing.expect(list.items[0] == 5); | |
| 960 | testing.expect(list.items.len == 4); | |
| 958 | try testing.expect(list.swapRemove(0) == 1); | |
| 959 | try testing.expect(list.items[0] == 5); | |
| 960 | try testing.expect(list.items.len == 4); | |
| 961 | 961 | } |
| 962 | 962 | } |
| 963 | 963 | |
| ... | ... | @@ -971,10 +971,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" { |
| 971 | 971 | try list.append(2); |
| 972 | 972 | try list.append(3); |
| 973 | 973 | try list.insert(0, 5); |
| 974 | testing.expect(list.items[0] == 5); | |
| 975 | testing.expect(list.items[1] == 1); | |
| 976 | testing.expect(list.items[2] == 2); | |
| 977 | testing.expect(list.items[3] == 3); | |
| 974 | try testing.expect(list.items[0] == 5); | |
| 975 | try testing.expect(list.items[1] == 1); | |
| 976 | try testing.expect(list.items[2] == 2); | |
| 977 | try testing.expect(list.items[3] == 3); | |
| 978 | 978 | } |
| 979 | 979 | { |
| 980 | 980 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -984,10 +984,10 @@ test "std.ArrayList/ArrayListUnmanaged.insert" { |
| 984 | 984 | try list.append(a, 2); |
| 985 | 985 | try list.append(a, 3); |
| 986 | 986 | try list.insert(a, 0, 5); |
| 987 | testing.expect(list.items[0] == 5); | |
| 988 | testing.expect(list.items[1] == 1); | |
| 989 | testing.expect(list.items[2] == 2); | |
| 990 | testing.expect(list.items[3] == 3); | |
| 987 | try testing.expect(list.items[0] == 5); | |
| 988 | try testing.expect(list.items[1] == 1); | |
| 989 | try testing.expect(list.items[2] == 2); | |
| 990 | try testing.expect(list.items[3] == 3); | |
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | 993 | |
| ... | ... | @@ -1002,17 +1002,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" { |
| 1002 | 1002 | try list.append(3); |
| 1003 | 1003 | try list.append(4); |
| 1004 | 1004 | try list.insertSlice(1, &[_]i32{ 9, 8 }); |
| 1005 | testing.expect(list.items[0] == 1); | |
| 1006 | testing.expect(list.items[1] == 9); | |
| 1007 | testing.expect(list.items[2] == 8); | |
| 1008 | testing.expect(list.items[3] == 2); | |
| 1009 | testing.expect(list.items[4] == 3); | |
| 1010 | testing.expect(list.items[5] == 4); | |
| 1005 | try testing.expect(list.items[0] == 1); | |
| 1006 | try testing.expect(list.items[1] == 9); | |
| 1007 | try testing.expect(list.items[2] == 8); | |
| 1008 | try testing.expect(list.items[3] == 2); | |
| 1009 | try testing.expect(list.items[4] == 3); | |
| 1010 | try testing.expect(list.items[5] == 4); | |
| 1011 | 1011 | |
| 1012 | 1012 | const items = [_]i32{1}; |
| 1013 | 1013 | try list.insertSlice(0, items[0..0]); |
| 1014 | testing.expect(list.items.len == 6); | |
| 1015 | testing.expect(list.items[0] == 1); | |
| 1014 | try testing.expect(list.items.len == 6); | |
| 1015 | try testing.expect(list.items[0] == 1); | |
| 1016 | 1016 | } |
| 1017 | 1017 | { |
| 1018 | 1018 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -1023,17 +1023,17 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" { |
| 1023 | 1023 | try list.append(a, 3); |
| 1024 | 1024 | try list.append(a, 4); |
| 1025 | 1025 | try list.insertSlice(a, 1, &[_]i32{ 9, 8 }); |
| 1026 | testing.expect(list.items[0] == 1); | |
| 1027 | testing.expect(list.items[1] == 9); | |
| 1028 | testing.expect(list.items[2] == 8); | |
| 1029 | testing.expect(list.items[3] == 2); | |
| 1030 | testing.expect(list.items[4] == 3); | |
| 1031 | testing.expect(list.items[5] == 4); | |
| 1026 | try testing.expect(list.items[0] == 1); | |
| 1027 | try testing.expect(list.items[1] == 9); | |
| 1028 | try testing.expect(list.items[2] == 8); | |
| 1029 | try testing.expect(list.items[3] == 2); | |
| 1030 | try testing.expect(list.items[4] == 3); | |
| 1031 | try testing.expect(list.items[5] == 4); | |
| 1032 | 1032 | |
| 1033 | 1033 | const items = [_]i32{1}; |
| 1034 | 1034 | try list.insertSlice(a, 0, items[0..0]); |
| 1035 | testing.expect(list.items.len == 6); | |
| 1036 | testing.expect(list.items[0] == 1); | |
| 1035 | try testing.expect(list.items.len == 6); | |
| 1036 | try testing.expect(list.items[0] == 1); | |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| ... | ... | @@ -1066,13 +1066,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" { |
| 1066 | 1066 | try list_lt.replaceRange(1, 2, &new); |
| 1067 | 1067 | |
| 1068 | 1068 | // after_range > new_items.len in function body |
| 1069 | testing.expect(1 + 4 > new.len); | |
| 1069 | try testing.expect(1 + 4 > new.len); | |
| 1070 | 1070 | try list_gt.replaceRange(1, 4, &new); |
| 1071 | 1071 | |
| 1072 | testing.expectEqualSlices(i32, list_zero.items, &result_zero); | |
| 1073 | testing.expectEqualSlices(i32, list_eq.items, &result_eq); | |
| 1074 | testing.expectEqualSlices(i32, list_lt.items, &result_le); | |
| 1075 | testing.expectEqualSlices(i32, list_gt.items, &result_gt); | |
| 1072 | try testing.expectEqualSlices(i32, list_zero.items, &result_zero); | |
| 1073 | try testing.expectEqualSlices(i32, list_eq.items, &result_eq); | |
| 1074 | try testing.expectEqualSlices(i32, list_lt.items, &result_le); | |
| 1075 | try testing.expectEqualSlices(i32, list_gt.items, &result_gt); | |
| 1076 | 1076 | } |
| 1077 | 1077 | { |
| 1078 | 1078 | var list_zero = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -1090,13 +1090,13 @@ test "std.ArrayList/ArrayListUnmanaged.replaceRange" { |
| 1090 | 1090 | try list_lt.replaceRange(a, 1, 2, &new); |
| 1091 | 1091 | |
| 1092 | 1092 | // after_range > new_items.len in function body |
| 1093 | testing.expect(1 + 4 > new.len); | |
| 1093 | try testing.expect(1 + 4 > new.len); | |
| 1094 | 1094 | try list_gt.replaceRange(a, 1, 4, &new); |
| 1095 | 1095 | |
| 1096 | testing.expectEqualSlices(i32, list_zero.items, &result_zero); | |
| 1097 | testing.expectEqualSlices(i32, list_eq.items, &result_eq); | |
| 1098 | testing.expectEqualSlices(i32, list_lt.items, &result_le); | |
| 1099 | testing.expectEqualSlices(i32, list_gt.items, &result_gt); | |
| 1096 | try testing.expectEqualSlices(i32, list_zero.items, &result_zero); | |
| 1097 | try testing.expectEqualSlices(i32, list_eq.items, &result_eq); | |
| 1098 | try testing.expectEqualSlices(i32, list_lt.items, &result_le); | |
| 1099 | try testing.expectEqualSlices(i32, list_gt.items, &result_gt); | |
| 1100 | 1100 | } |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| ... | ... | @@ -1116,13 +1116,13 @@ test "std.ArrayList/ArrayListUnmanaged: ArrayList(T) of struct T" { |
| 1116 | 1116 | var root = Item{ .integer = 1, .sub_items = ArrayList(Item).init(a) }; |
| 1117 | 1117 | defer root.sub_items.deinit(); |
| 1118 | 1118 | try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(a) }); |
| 1119 | testing.expect(root.sub_items.items[0].integer == 42); | |
| 1119 | try testing.expect(root.sub_items.items[0].integer == 42); | |
| 1120 | 1120 | } |
| 1121 | 1121 | { |
| 1122 | 1122 | var root = ItemUnmanaged{ .integer = 1, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} }; |
| 1123 | 1123 | defer root.sub_items.deinit(a); |
| 1124 | 1124 | try root.sub_items.append(a, ItemUnmanaged{ .integer = 42, .sub_items = ArrayListUnmanaged(ItemUnmanaged){} }); |
| 1125 | testing.expect(root.sub_items.items[0].integer == 42); | |
| 1125 | try testing.expect(root.sub_items.items[0].integer == 42); | |
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| ... | ... | @@ -1137,7 +1137,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" { |
| 1137 | 1137 | const y: i32 = 1234; |
| 1138 | 1138 | try buffer.writer().print("x: {}\ny: {}\n", .{ x, y }); |
| 1139 | 1139 | |
| 1140 | testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items); | |
| 1140 | try testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.items); | |
| 1141 | 1141 | } |
| 1142 | 1142 | { |
| 1143 | 1143 | var list = ArrayListAligned(u8, 2).init(a); |
| ... | ... | @@ -1149,7 +1149,7 @@ test "std.ArrayList(u8)/ArrayListAligned implements writer" { |
| 1149 | 1149 | try writer.writeAll("d"); |
| 1150 | 1150 | try writer.writeAll("efg"); |
| 1151 | 1151 | |
| 1152 | testing.expectEqualSlices(u8, list.items, "abcdefg"); | |
| 1152 | try testing.expectEqualSlices(u8, list.items, "abcdefg"); | |
| 1153 | 1153 | } |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| ... | ... | @@ -1167,7 +1167,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe |
| 1167 | 1167 | try list.append(3); |
| 1168 | 1168 | |
| 1169 | 1169 | list.shrinkAndFree(1); |
| 1170 | testing.expect(list.items.len == 1); | |
| 1170 | try testing.expect(list.items.len == 1); | |
| 1171 | 1171 | } |
| 1172 | 1172 | { |
| 1173 | 1173 | var list = ArrayListUnmanaged(i32){}; |
| ... | ... | @@ -1177,7 +1177,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe |
| 1177 | 1177 | try list.append(a, 3); |
| 1178 | 1178 | |
| 1179 | 1179 | list.shrinkAndFree(a, 1); |
| 1180 | testing.expect(list.items.len == 1); | |
| 1180 | try testing.expect(list.items.len == 1); | |
| 1181 | 1181 | } |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| ... | ... | @@ -1191,7 +1191,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" { |
| 1191 | 1191 | try list.ensureCapacity(8); |
| 1192 | 1192 | list.addManyAsArrayAssumeCapacity(4).* = "asdf".*; |
| 1193 | 1193 | |
| 1194 | testing.expectEqualSlices(u8, list.items, "aoeuasdf"); | |
| 1194 | try testing.expectEqualSlices(u8, list.items, "aoeuasdf"); | |
| 1195 | 1195 | } |
| 1196 | 1196 | { |
| 1197 | 1197 | var list = ArrayListUnmanaged(u8){}; |
| ... | ... | @@ -1201,7 +1201,7 @@ test "std.ArrayList/ArrayListUnmanaged.addManyAsArray" { |
| 1201 | 1201 | try list.ensureCapacity(a, 8); |
| 1202 | 1202 | list.addManyAsArrayAssumeCapacity(4).* = "asdf".*; |
| 1203 | 1203 | |
| 1204 | testing.expectEqualSlices(u8, list.items, "aoeuasdf"); | |
| 1204 | try testing.expectEqualSlices(u8, list.items, "aoeuasdf"); | |
| 1205 | 1205 | } |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| ... | ... | @@ -1215,7 +1215,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" { |
| 1215 | 1215 | |
| 1216 | 1216 | const result = try list.toOwnedSliceSentinel(0); |
| 1217 | 1217 | defer a.free(result); |
| 1218 | testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1218 | try testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1219 | 1219 | } |
| 1220 | 1220 | { |
| 1221 | 1221 | var list = ArrayListUnmanaged(u8){}; |
| ... | ... | @@ -1225,7 +1225,7 @@ test "std.ArrayList/ArrayListUnmanaged.toOwnedSliceSentinel" { |
| 1225 | 1225 | |
| 1226 | 1226 | const result = try list.toOwnedSliceSentinel(a, 0); |
| 1227 | 1227 | defer a.free(result); |
| 1228 | testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1228 | try testing.expectEqualStrings(result, mem.spanZ(result.ptr)); | |
| 1229 | 1229 | } |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| ... | ... | @@ -1239,7 +1239,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" { |
| 1239 | 1239 | try list.insertSlice(2, &.{ 4, 5, 6, 7 }); |
| 1240 | 1240 | try list.replaceRange(1, 3, &.{ 8, 9 }); |
| 1241 | 1241 | |
| 1242 | testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 }); | |
| 1242 | try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 }); | |
| 1243 | 1243 | } |
| 1244 | 1244 | { |
| 1245 | 1245 | var list = std.ArrayListAlignedUnmanaged(u8, 8){}; |
| ... | ... | @@ -1249,6 +1249,6 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" { |
| 1249 | 1249 | try list.insertSlice(a, 2, &.{ 4, 5, 6, 7 }); |
| 1250 | 1250 | try list.replaceRange(a, 1, 3, &.{ 8, 9 }); |
| 1251 | 1251 | |
| 1252 | testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 }); | |
| 1252 | try testing.expectEqualSlices(u8, list.items, &.{ 0, 8, 9, 6, 7, 2, 3 }); | |
| 1253 | 1253 | } |
| 1254 | 1254 | } |
lib/std/ascii.zig+23-23| ... | ... | @@ -236,11 +236,11 @@ pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.F |
| 236 | 236 | |
| 237 | 237 | test "spaces" { |
| 238 | 238 | const testing = std.testing; |
| 239 | for (spaces) |space| testing.expect(isSpace(space)); | |
| 239 | for (spaces) |space| try testing.expect(isSpace(space)); | |
| 240 | 240 | |
| 241 | 241 | var i: u8 = 0; |
| 242 | 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 | } |
| 246 | 246 | |
| ... | ... | @@ -279,13 +279,13 @@ pub fn toLower(c: u8) u8 { |
| 279 | 279 | test "ascii character classes" { |
| 280 | 280 | const testing = std.testing; |
| 281 | 281 | |
| 282 | testing.expect('C' == toUpper('c')); | |
| 283 | testing.expect(':' == toUpper(':')); | |
| 284 | testing.expect('\xab' == toUpper('\xab')); | |
| 285 | testing.expect('c' == toLower('C')); | |
| 286 | testing.expect(isAlpha('c')); | |
| 287 | testing.expect(!isAlpha('5')); | |
| 288 | testing.expect(isSpace(' ')); | |
| 282 | try testing.expect('C' == toUpper('c')); | |
| 283 | try testing.expect(':' == toUpper(':')); | |
| 284 | try testing.expect('\xab' == toUpper('\xab')); | |
| 285 | try testing.expect('c' == toLower('C')); | |
| 286 | try testing.expect(isAlpha('c')); | |
| 287 | try testing.expect(!isAlpha('5')); | |
| 288 | try testing.expect(isSpace(' ')); | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 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 | 301 | test "allocLowerString" { |
| 302 | 302 | const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!"); |
| 303 | 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 | } |
| 306 | 306 | |
| 307 | 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 | 317 | test "allocUpperString" { |
| 318 | 318 | const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+💩!"); |
| 319 | 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 | } |
| 322 | 322 | |
| 323 | 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 | 330 | } |
| 331 | 331 | |
| 332 | 332 | test "eqlIgnoreCase" { |
| 333 | std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!")); | |
| 334 | std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! ")); | |
| 335 | std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!")); | |
| 333 | try std.testing.expect(eqlIgnoreCase("HEl💩Lo!", "hel💩lo!")); | |
| 334 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! ")); | |
| 335 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!")); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | 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 | } |
| 341 | 341 | |
| 342 | 342 | test "ascii.startsWithIgnoreCase" { |
| 343 | std.testing.expect(startsWithIgnoreCase("boB", "Bo")); | |
| 344 | std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack")); | |
| 343 | try std.testing.expect(startsWithIgnoreCase("boB", "Bo")); | |
| 344 | try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack")); | |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | 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 | } |
| 350 | 350 | |
| 351 | 351 | test "ascii.endsWithIgnoreCase" { |
| 352 | std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack")); | |
| 353 | std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); | |
| 352 | try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack")); | |
| 353 | try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); | |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 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 | 372 | } |
| 373 | 373 | |
| 374 | 374 | test "indexOfIgnoreCase" { |
| 375 | std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14); | |
| 376 | std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null); | |
| 377 | std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0); | |
| 378 | std.testing.expect(indexOfIgnoreCase("foo", "fool") == null); | |
| 375 | try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14); | |
| 376 | try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null); | |
| 377 | try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0); | |
| 378 | try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null); | |
| 379 | 379 | |
| 380 | std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0); | |
| 380 | try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0); | |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 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 | 47 | |
| 48 | 48 | test "std.atomic.Bool" { |
| 49 | 49 | var a = Bool.init(false); |
| 50 | testing.expectEqual(false, a.xchg(false, .SeqCst)); | |
| 51 | testing.expectEqual(false, a.load(.SeqCst)); | |
| 50 | try testing.expectEqual(false, a.xchg(false, .SeqCst)); | |
| 51 | try testing.expectEqual(false, a.load(.SeqCst)); | |
| 52 | 52 | a.store(true, .SeqCst); |
| 53 | testing.expectEqual(true, a.xchg(false, .SeqCst)); | |
| 54 | testing.expectEqual(false, a.load(.SeqCst)); | |
| 53 | try testing.expectEqual(true, a.xchg(false, .SeqCst)); | |
| 54 | try testing.expectEqual(false, a.load(.SeqCst)); | |
| 55 | 55 | } |
lib/std/atomic/int.zig+6-6| ... | ... | @@ -81,12 +81,12 @@ pub fn Int(comptime T: type) type { |
| 81 | 81 | |
| 82 | 82 | test "std.atomic.Int" { |
| 83 | 83 | var a = Int(u8).init(0); |
| 84 | testing.expectEqual(@as(u8, 0), a.incr()); | |
| 85 | testing.expectEqual(@as(u8, 1), a.load(.SeqCst)); | |
| 84 | try testing.expectEqual(@as(u8, 0), a.incr()); | |
| 85 | try testing.expectEqual(@as(u8, 1), a.load(.SeqCst)); | |
| 86 | 86 | a.store(42, .SeqCst); |
| 87 | testing.expectEqual(@as(u8, 42), a.decr()); | |
| 88 | testing.expectEqual(@as(u8, 41), a.xchg(100)); | |
| 89 | testing.expectEqual(@as(u8, 100), a.fetchAdd(5)); | |
| 90 | testing.expectEqual(@as(u8, 105), a.get()); | |
| 87 | try testing.expectEqual(@as(u8, 42), a.decr()); | |
| 88 | try testing.expectEqual(@as(u8, 41), a.xchg(100)); | |
| 89 | try testing.expectEqual(@as(u8, 100), a.fetchAdd(5)); | |
| 90 | try testing.expectEqual(@as(u8, 105), a.get()); | |
| 91 | 91 | a.set(200); |
| 92 | 92 | } |
lib/std/atomic/queue.zig+28-28| ... | ... | @@ -195,24 +195,24 @@ test "std.atomic.Queue" { |
| 195 | 195 | }; |
| 196 | 196 | |
| 197 | 197 | if (builtin.single_threaded) { |
| 198 | expect(context.queue.isEmpty()); | |
| 198 | try expect(context.queue.isEmpty()); | |
| 199 | 199 | { |
| 200 | 200 | var i: usize = 0; |
| 201 | 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 | 206 | context.puts_done = true; |
| 207 | 207 | { |
| 208 | 208 | var i: usize = 0; |
| 209 | 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 | 214 | } else { |
| 215 | expect(context.queue.isEmpty()); | |
| 215 | try expect(context.queue.isEmpty()); | |
| 216 | 216 | |
| 217 | 217 | var putters: [put_thread_count]*std.Thread = undefined; |
| 218 | 218 | for (putters) |*t| { |
| ... | ... | @@ -229,7 +229,7 @@ test "std.atomic.Queue" { |
| 229 | 229 | for (getters) |t| |
| 230 | 230 | t.wait(); |
| 231 | 231 | |
| 232 | expect(context.queue.isEmpty()); | |
| 232 | try expect(context.queue.isEmpty()); | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | if (context.put_sum != context.get_sum) { |
| ... | ... | @@ -279,7 +279,7 @@ fn startGets(ctx: *Context) u8 { |
| 279 | 279 | |
| 280 | 280 | test "std.atomic.Queue single-threaded" { |
| 281 | 281 | var queue = Queue(i32).init(); |
| 282 | expect(queue.isEmpty()); | |
| 282 | try expect(queue.isEmpty()); | |
| 283 | 283 | |
| 284 | 284 | var node_0 = Queue(i32).Node{ |
| 285 | 285 | .data = 0, |
| ... | ... | @@ -287,7 +287,7 @@ test "std.atomic.Queue single-threaded" { |
| 287 | 287 | .prev = undefined, |
| 288 | 288 | }; |
| 289 | 289 | queue.put(&node_0); |
| 290 | expect(!queue.isEmpty()); | |
| 290 | try expect(!queue.isEmpty()); | |
| 291 | 291 | |
| 292 | 292 | var node_1 = Queue(i32).Node{ |
| 293 | 293 | .data = 1, |
| ... | ... | @@ -295,10 +295,10 @@ test "std.atomic.Queue single-threaded" { |
| 295 | 295 | .prev = undefined, |
| 296 | 296 | }; |
| 297 | 297 | queue.put(&node_1); |
| 298 | expect(!queue.isEmpty()); | |
| 298 | try expect(!queue.isEmpty()); | |
| 299 | 299 | |
| 300 | expect(queue.get().?.data == 0); | |
| 301 | expect(!queue.isEmpty()); | |
| 300 | try expect(queue.get().?.data == 0); | |
| 301 | try expect(!queue.isEmpty()); | |
| 302 | 302 | |
| 303 | 303 | var node_2 = Queue(i32).Node{ |
| 304 | 304 | .data = 2, |
| ... | ... | @@ -306,7 +306,7 @@ test "std.atomic.Queue single-threaded" { |
| 306 | 306 | .prev = undefined, |
| 307 | 307 | }; |
| 308 | 308 | queue.put(&node_2); |
| 309 | expect(!queue.isEmpty()); | |
| 309 | try expect(!queue.isEmpty()); | |
| 310 | 310 | |
| 311 | 311 | var node_3 = Queue(i32).Node{ |
| 312 | 312 | .data = 3, |
| ... | ... | @@ -314,13 +314,13 @@ test "std.atomic.Queue single-threaded" { |
| 314 | 314 | .prev = undefined, |
| 315 | 315 | }; |
| 316 | 316 | queue.put(&node_3); |
| 317 | expect(!queue.isEmpty()); | |
| 317 | try expect(!queue.isEmpty()); | |
| 318 | 318 | |
| 319 | expect(queue.get().?.data == 1); | |
| 320 | expect(!queue.isEmpty()); | |
| 319 | try expect(queue.get().?.data == 1); | |
| 320 | try expect(!queue.isEmpty()); | |
| 321 | 321 | |
| 322 | expect(queue.get().?.data == 2); | |
| 323 | expect(!queue.isEmpty()); | |
| 322 | try expect(queue.get().?.data == 2); | |
| 323 | try expect(!queue.isEmpty()); | |
| 324 | 324 | |
| 325 | 325 | var node_4 = Queue(i32).Node{ |
| 326 | 326 | .data = 4, |
| ... | ... | @@ -328,17 +328,17 @@ test "std.atomic.Queue single-threaded" { |
| 328 | 328 | .prev = undefined, |
| 329 | 329 | }; |
| 330 | 330 | queue.put(&node_4); |
| 331 | expect(!queue.isEmpty()); | |
| 331 | try expect(!queue.isEmpty()); | |
| 332 | 332 | |
| 333 | expect(queue.get().?.data == 3); | |
| 333 | try expect(queue.get().?.data == 3); | |
| 334 | 334 | node_3.next = null; |
| 335 | expect(!queue.isEmpty()); | |
| 335 | try expect(!queue.isEmpty()); | |
| 336 | 336 | |
| 337 | expect(queue.get().?.data == 4); | |
| 338 | expect(queue.isEmpty()); | |
| 337 | try expect(queue.get().?.data == 4); | |
| 338 | try expect(queue.isEmpty()); | |
| 339 | 339 | |
| 340 | expect(queue.get() == null); | |
| 341 | expect(queue.isEmpty()); | |
| 340 | try expect(queue.get() == null); | |
| 341 | try expect(queue.isEmpty()); | |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | test "std.atomic.Queue dump" { |
| ... | ... | @@ -352,7 +352,7 @@ test "std.atomic.Queue dump" { |
| 352 | 352 | // Test empty stream |
| 353 | 353 | fbs.reset(); |
| 354 | 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 | 356 | \\head: (null) |
| 357 | 357 | \\tail: (null) |
| 358 | 358 | \\ |
| ... | ... | @@ -376,7 +376,7 @@ test "std.atomic.Queue dump" { |
| 376 | 376 | \\ (null) |
| 377 | 377 | \\ |
| 378 | 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)); | |
| 380 | 380 | |
| 381 | 381 | // Test a stream with two elements |
| 382 | 382 | var node_1 = Queue(i32).Node{ |
| ... | ... | @@ -397,5 +397,5 @@ test "std.atomic.Queue dump" { |
| 397 | 397 | \\ (null) |
| 398 | 398 | \\ |
| 399 | 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 | 110 | { |
| 111 | 111 | var i: usize = 0; |
| 112 | 112 | while (i < put_thread_count) : (i += 1) { |
| 113 | expect(startPuts(&context) == 0); | |
| 113 | try expect(startPuts(&context) == 0); | |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | context.puts_done = true; |
| 117 | 117 | { |
| 118 | 118 | var i: usize = 0; |
| 119 | 119 | while (i < put_thread_count) : (i += 1) { |
| 120 | expect(startGets(&context) == 0); | |
| 120 | try expect(startGets(&context) == 0); | |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | } else { |
lib/std/base64.zig+9-9| ... | ... | @@ -318,14 +318,14 @@ pub const Base64DecoderWithIgnore = struct { |
| 318 | 318 | |
| 319 | 319 | test "base64" { |
| 320 | 320 | @setEvalBranchQuota(8000); |
| 321 | testBase64() catch unreachable; | |
| 322 | comptime testAllApis(standard, "comptime", "Y29tcHRpbWU=") catch unreachable; | |
| 321 | try testBase64(); | |
| 322 | comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU="); | |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | test "base64 url_safe_no_pad" { |
| 326 | 326 | @setEvalBranchQuota(8000); |
| 327 | testBase64UrlSafeNoPad() catch unreachable; | |
| 328 | comptime testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU") catch unreachable; | |
| 327 | try testBase64UrlSafeNoPad(); | |
| 328 | comptime try testAllApis(url_safe_no_pad, "comptime", "Y29tcHRpbWU"); | |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | fn testBase64() !void { |
| ... | ... | @@ -404,7 +404,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 404 | 404 | { |
| 405 | 405 | var buffer: [0x100]u8 = undefined; |
| 406 | 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 | } |
| 409 | 409 | |
| 410 | 410 | // Base64Decoder |
| ... | ... | @@ -412,7 +412,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 412 | 412 | var buffer: [0x100]u8 = undefined; |
| 413 | 413 | var decoded = buffer[0..try codecs.Decoder.calcSizeForSlice(expected_encoded)]; |
| 414 | 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 | } |
| 417 | 417 | |
| 418 | 418 | // Base64DecoderWithIgnore |
| ... | ... | @@ -421,8 +421,8 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ |
| 421 | 421 | var buffer: [0x100]u8 = undefined; |
| 422 | 422 | var decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; |
| 423 | 423 | var written = try decoder_ignore_nothing.decode(decoded, expected_encoded); |
| 424 | testing.expect(written <= decoded.len); | |
| 425 | testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | |
| 424 | try testing.expect(written <= decoded.len); | |
| 425 | try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); | |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | |
| ... | ... | @@ -431,7 +431,7 @@ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: |
| 431 | 431 | var buffer: [0x100]u8 = undefined; |
| 432 | 432 | var decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; |
| 433 | 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 | } |
| 436 | 436 | |
| 437 | 437 | fn 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 | 998 | |
| 999 | 999 | const testing = std.testing; |
| 1000 | 1000 | |
| 1001 | fn testBitSet(a: anytype, b: anytype, len: usize) void { | |
| 1002 | testing.expectEqual(len, a.capacity()); | |
| 1003 | testing.expectEqual(len, b.capacity()); | |
| 1001 | fn testBitSet(a: anytype, b: anytype, len: usize) !void { | |
| 1002 | try testing.expectEqual(len, a.capacity()); | |
| 1003 | try testing.expectEqual(len, b.capacity()); | |
| 1004 | 1004 | |
| 1005 | 1005 | { |
| 1006 | 1006 | var i: usize = 0; |
| ... | ... | @@ -1010,50 +1010,50 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1010 | 1010 | } |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | testing.expectEqual((len + 1) / 2, a.count()); | |
| 1014 | testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count()); | |
| 1013 | try testing.expectEqual((len + 1) / 2, a.count()); | |
| 1014 | try testing.expectEqual((len + 3) / 4 + (len + 2) / 4, b.count()); | |
| 1015 | 1015 | |
| 1016 | 1016 | { |
| 1017 | 1017 | var iter = a.iterator(.{}); |
| 1018 | 1018 | var i: usize = 0; |
| 1019 | 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()); | |
| 1023 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1024 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1022 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1023 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1024 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1025 | 1025 | } |
| 1026 | 1026 | a.toggleAll(); |
| 1027 | 1027 | { |
| 1028 | 1028 | var iter = a.iterator(.{}); |
| 1029 | 1029 | var i: usize = 1; |
| 1030 | 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()); | |
| 1034 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1035 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1033 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1034 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1035 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | 1038 | { |
| 1039 | 1039 | var iter = b.iterator(.{ .kind = .unset }); |
| 1040 | 1040 | var i: usize = 2; |
| 1041 | 1041 | while (i < len) : (i += 4) { |
| 1042 | testing.expectEqual(@as(?usize, i), iter.next()); | |
| 1042 | try testing.expectEqual(@as(?usize, i), iter.next()); | |
| 1043 | 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()); | |
| 1048 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1049 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1047 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1048 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1049 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | { |
| 1053 | 1053 | var i: usize = 0; |
| 1054 | 1054 | while (i < len) : (i += 1) { |
| 1055 | testing.expectEqual(i & 1 != 0, a.isSet(i)); | |
| 1056 | testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1055 | try testing.expectEqual(i & 1 != 0, a.isSet(i)); | |
| 1056 | try testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1057 | 1057 | } |
| 1058 | 1058 | } |
| 1059 | 1059 | |
| ... | ... | @@ -1061,8 +1061,8 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1061 | 1061 | { |
| 1062 | 1062 | var i: usize = 0; |
| 1063 | 1063 | while (i < len) : (i += 1) { |
| 1064 | testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i)); | |
| 1065 | testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1064 | try testing.expectEqual(i & 1 != 0 or i & 2 == 0, a.isSet(i)); | |
| 1065 | try testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | i = len; |
| ... | ... | @@ -1071,27 +1071,27 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1071 | 1071 | while (i > 0) { |
| 1072 | 1072 | i -= 1; |
| 1073 | 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 | 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()); | |
| 1080 | testing.expectEqual(@as(?usize, null), set.next()); | |
| 1081 | testing.expectEqual(@as(?usize, null), set.next()); | |
| 1082 | testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1083 | testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1084 | testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1079 | try testing.expectEqual(@as(?usize, null), set.next()); | |
| 1080 | try testing.expectEqual(@as(?usize, null), set.next()); | |
| 1081 | try testing.expectEqual(@as(?usize, null), set.next()); | |
| 1082 | try testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1083 | try testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1084 | try testing.expectEqual(@as(?usize, null), unset.next()); | |
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | a.toggleSet(b.*); |
| 1088 | 1088 | { |
| 1089 | testing.expectEqual(len / 4, a.count()); | |
| 1089 | try testing.expectEqual(len / 4, a.count()); | |
| 1090 | 1090 | |
| 1091 | 1091 | var i: usize = 0; |
| 1092 | 1092 | while (i < len) : (i += 1) { |
| 1093 | testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i)); | |
| 1094 | testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1093 | try testing.expectEqual(i & 1 != 0 and i & 2 != 0, a.isSet(i)); | |
| 1094 | try testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1095 | 1095 | if (i & 1 == 0) { |
| 1096 | 1096 | a.set(i); |
| 1097 | 1097 | } else { |
| ... | ... | @@ -1102,29 +1102,29 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1102 | 1102 | |
| 1103 | 1103 | a.setIntersection(b.*); |
| 1104 | 1104 | { |
| 1105 | testing.expectEqual((len + 3) / 4, a.count()); | |
| 1105 | try testing.expectEqual((len + 3) / 4, a.count()); | |
| 1106 | 1106 | |
| 1107 | 1107 | var i: usize = 0; |
| 1108 | 1108 | while (i < len) : (i += 1) { |
| 1109 | testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i)); | |
| 1110 | testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1109 | try testing.expectEqual(i & 1 == 0 and i & 2 == 0, a.isSet(i)); | |
| 1110 | try testing.expectEqual(i & 2 == 0, b.isSet(i)); | |
| 1111 | 1111 | } |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | a.toggleSet(a.*); |
| 1115 | 1115 | { |
| 1116 | 1116 | var iter = a.iterator(.{}); |
| 1117 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1118 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1119 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1120 | testing.expectEqual(@as(usize, 0), a.count()); | |
| 1117 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1118 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1119 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1120 | try testing.expectEqual(@as(usize, 0), a.count()); | |
| 1121 | 1121 | } |
| 1122 | 1122 | { |
| 1123 | 1123 | var iter = a.iterator(.{ .direction = .reverse }); |
| 1124 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1125 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1126 | testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1127 | testing.expectEqual(@as(usize, 0), a.count()); | |
| 1124 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1125 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1126 | try testing.expectEqual(@as(?usize, null), iter.next()); | |
| 1127 | try testing.expectEqual(@as(usize, 0), a.count()); | |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | const test_bits = [_]usize{ |
| ... | ... | @@ -1139,51 +1139,51 @@ fn testBitSet(a: anytype, b: anytype, len: usize) void { |
| 1139 | 1139 | |
| 1140 | 1140 | for (test_bits) |i| { |
| 1141 | 1141 | if (i < a.capacity()) { |
| 1142 | testing.expectEqual(@as(?usize, i), a.findFirstSet()); | |
| 1143 | testing.expectEqual(@as(?usize, i), a.toggleFirstSet()); | |
| 1142 | try testing.expectEqual(@as(?usize, i), a.findFirstSet()); | |
| 1143 | try testing.expectEqual(@as(?usize, i), a.toggleFirstSet()); | |
| 1144 | 1144 | } |
| 1145 | 1145 | } |
| 1146 | testing.expectEqual(@as(?usize, null), a.findFirstSet()); | |
| 1147 | testing.expectEqual(@as(?usize, null), a.toggleFirstSet()); | |
| 1148 | testing.expectEqual(@as(?usize, null), a.findFirstSet()); | |
| 1149 | testing.expectEqual(@as(?usize, null), a.toggleFirstSet()); | |
| 1150 | testing.expectEqual(@as(usize, 0), a.count()); | |
| 1146 | try testing.expectEqual(@as(?usize, null), a.findFirstSet()); | |
| 1147 | try testing.expectEqual(@as(?usize, null), a.toggleFirstSet()); | |
| 1148 | try testing.expectEqual(@as(?usize, null), a.findFirstSet()); | |
| 1149 | try testing.expectEqual(@as(?usize, null), a.toggleFirstSet()); | |
| 1150 | try testing.expectEqual(@as(usize, 0), a.count()); | |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | fn testStaticBitSet(comptime Set: type) void { | |
| 1153 | fn testStaticBitSet(comptime Set: type) !void { | |
| 1154 | 1154 | var a = Set.initEmpty(); |
| 1155 | 1155 | var b = Set.initFull(); |
| 1156 | testing.expectEqual(@as(usize, 0), a.count()); | |
| 1157 | testing.expectEqual(@as(usize, Set.bit_length), b.count()); | |
| 1156 | try testing.expectEqual(@as(usize, 0), a.count()); | |
| 1157 | try testing.expectEqual(@as(usize, Set.bit_length), b.count()); | |
| 1158 | 1158 | |
| 1159 | testBitSet(&a, &b, Set.bit_length); | |
| 1159 | try testBitSet(&a, &b, Set.bit_length); | |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | test "IntegerBitSet" { |
| 1163 | testStaticBitSet(IntegerBitSet(0)); | |
| 1164 | testStaticBitSet(IntegerBitSet(1)); | |
| 1165 | testStaticBitSet(IntegerBitSet(2)); | |
| 1166 | testStaticBitSet(IntegerBitSet(5)); | |
| 1167 | testStaticBitSet(IntegerBitSet(8)); | |
| 1168 | testStaticBitSet(IntegerBitSet(32)); | |
| 1169 | testStaticBitSet(IntegerBitSet(64)); | |
| 1170 | testStaticBitSet(IntegerBitSet(127)); | |
| 1163 | try testStaticBitSet(IntegerBitSet(0)); | |
| 1164 | try testStaticBitSet(IntegerBitSet(1)); | |
| 1165 | try testStaticBitSet(IntegerBitSet(2)); | |
| 1166 | try testStaticBitSet(IntegerBitSet(5)); | |
| 1167 | try testStaticBitSet(IntegerBitSet(8)); | |
| 1168 | try testStaticBitSet(IntegerBitSet(32)); | |
| 1169 | try testStaticBitSet(IntegerBitSet(64)); | |
| 1170 | try testStaticBitSet(IntegerBitSet(127)); | |
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | test "ArrayBitSet" { |
| 1174 | 1174 | inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| { |
| 1175 | testStaticBitSet(ArrayBitSet(u8, size)); | |
| 1176 | testStaticBitSet(ArrayBitSet(u16, size)); | |
| 1177 | testStaticBitSet(ArrayBitSet(u32, size)); | |
| 1178 | testStaticBitSet(ArrayBitSet(u64, size)); | |
| 1179 | testStaticBitSet(ArrayBitSet(u128, size)); | |
| 1175 | try testStaticBitSet(ArrayBitSet(u8, size)); | |
| 1176 | try testStaticBitSet(ArrayBitSet(u16, size)); | |
| 1177 | try testStaticBitSet(ArrayBitSet(u32, size)); | |
| 1178 | try testStaticBitSet(ArrayBitSet(u64, size)); | |
| 1179 | try testStaticBitSet(ArrayBitSet(u128, size)); | |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | 1183 | test "DynamicBitSetUnmanaged" { |
| 1184 | 1184 | const allocator = std.testing.allocator; |
| 1185 | 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 | 1187 | a.deinit(allocator); |
| 1188 | 1188 | |
| 1189 | 1189 | a = try DynamicBitSetUnmanaged.initEmpty(0, allocator); |
| ... | ... | @@ -1193,10 +1193,10 @@ test "DynamicBitSetUnmanaged" { |
| 1193 | 1193 | |
| 1194 | 1194 | var tmp = try a.clone(allocator); |
| 1195 | 1195 | defer tmp.deinit(allocator); |
| 1196 | testing.expectEqual(old_len, tmp.capacity()); | |
| 1196 | try testing.expectEqual(old_len, tmp.capacity()); | |
| 1197 | 1197 | var i: usize = 0; |
| 1198 | 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 | } |
| 1201 | 1201 | |
| 1202 | 1202 | a.toggleSet(a); // zero a |
| ... | ... | @@ -1206,24 +1206,24 @@ test "DynamicBitSetUnmanaged" { |
| 1206 | 1206 | try tmp.resize(size, false, allocator); |
| 1207 | 1207 | |
| 1208 | 1208 | if (size > old_len) { |
| 1209 | testing.expectEqual(size - old_len, a.count()); | |
| 1209 | try testing.expectEqual(size - old_len, a.count()); | |
| 1210 | 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()); | |
| 1214 | 1214 | |
| 1215 | 1215 | var b = try DynamicBitSetUnmanaged.initFull(size, allocator); |
| 1216 | 1216 | defer b.deinit(allocator); |
| 1217 | testing.expectEqual(@as(usize, size), b.count()); | |
| 1217 | try testing.expectEqual(@as(usize, size), b.count()); | |
| 1218 | 1218 | |
| 1219 | testBitSet(&a, &b, size); | |
| 1219 | try testBitSet(&a, &b, size); | |
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | test "DynamicBitSet" { |
| 1224 | 1224 | const allocator = std.testing.allocator; |
| 1225 | 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 | 1227 | a.deinit(); |
| 1228 | 1228 | |
| 1229 | 1229 | a = try DynamicBitSet.initEmpty(0, allocator); |
| ... | ... | @@ -1233,10 +1233,10 @@ test "DynamicBitSet" { |
| 1233 | 1233 | |
| 1234 | 1234 | var tmp = try a.clone(allocator); |
| 1235 | 1235 | defer tmp.deinit(); |
| 1236 | testing.expectEqual(old_len, tmp.capacity()); | |
| 1236 | try testing.expectEqual(old_len, tmp.capacity()); | |
| 1237 | 1237 | var i: usize = 0; |
| 1238 | 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 | } |
| 1241 | 1241 | |
| 1242 | 1242 | a.toggleSet(a); // zero a |
| ... | ... | @@ -1246,24 +1246,24 @@ test "DynamicBitSet" { |
| 1246 | 1246 | try tmp.resize(size, false); |
| 1247 | 1247 | |
| 1248 | 1248 | if (size > old_len) { |
| 1249 | testing.expectEqual(size - old_len, a.count()); | |
| 1249 | try testing.expectEqual(size - old_len, a.count()); | |
| 1250 | 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()); | |
| 1254 | 1254 | |
| 1255 | 1255 | var b = try DynamicBitSet.initFull(size, allocator); |
| 1256 | 1256 | defer b.deinit(); |
| 1257 | testing.expectEqual(@as(usize, size), b.count()); | |
| 1257 | try testing.expectEqual(@as(usize, size), b.count()); | |
| 1258 | 1258 | |
| 1259 | testBitSet(&a, &b, size); | |
| 1259 | try testBitSet(&a, &b, size); | |
| 1260 | 1260 | } |
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | test "StaticBitSet" { |
| 1264 | testing.expectEqual(IntegerBitSet(0), StaticBitSet(0)); | |
| 1265 | testing.expectEqual(IntegerBitSet(5), StaticBitSet(5)); | |
| 1266 | testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize))); | |
| 1267 | testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1)); | |
| 1268 | testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500)); | |
| 1264 | try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0)); | |
| 1265 | try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5)); | |
| 1266 | try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize))); | |
| 1267 | try testing.expectEqual(ArrayBitSet(usize, @bitSizeOf(usize) + 1), StaticBitSet(@bitSizeOf(usize) + 1)); | |
| 1268 | try testing.expectEqual(ArrayBitSet(usize, 500), StaticBitSet(500)); | |
| 1269 | 1269 | } |
lib/std/buf_map.zig+7-7| ... | ... | @@ -94,19 +94,19 @@ test "BufMap" { |
| 94 | 94 | defer bufmap.deinit(); |
| 95 | 95 | |
| 96 | 96 | try bufmap.set("x", "1"); |
| 97 | testing.expect(mem.eql(u8, bufmap.get("x").?, "1")); | |
| 98 | testing.expect(1 == bufmap.count()); | |
| 97 | try testing.expect(mem.eql(u8, bufmap.get("x").?, "1")); | |
| 98 | try testing.expect(1 == bufmap.count()); | |
| 99 | 99 | |
| 100 | 100 | try bufmap.set("x", "2"); |
| 101 | testing.expect(mem.eql(u8, bufmap.get("x").?, "2")); | |
| 102 | testing.expect(1 == bufmap.count()); | |
| 101 | try testing.expect(mem.eql(u8, bufmap.get("x").?, "2")); | |
| 102 | try testing.expect(1 == bufmap.count()); | |
| 103 | 103 | |
| 104 | 104 | try bufmap.set("x", "3"); |
| 105 | testing.expect(mem.eql(u8, bufmap.get("x").?, "3")); | |
| 106 | testing.expect(1 == bufmap.count()); | |
| 105 | try testing.expect(mem.eql(u8, bufmap.get("x").?, "3")); | |
| 106 | try testing.expect(1 == bufmap.count()); | |
| 107 | 107 | |
| 108 | 108 | bufmap.delete("x"); |
| 109 | testing.expect(0 == bufmap.count()); | |
| 109 | try testing.expect(0 == bufmap.count()); | |
| 110 | 110 | |
| 111 | 111 | try bufmap.setMove(try allocator.dupe(u8, "k"), try allocator.dupe(u8, "v1")); |
| 112 | 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 | 73 | defer bufset.deinit(); |
| 74 | 74 | |
| 75 | 75 | try bufset.put("x"); |
| 76 | testing.expect(bufset.count() == 1); | |
| 76 | try testing.expect(bufset.count() == 1); | |
| 77 | 77 | bufset.delete("x"); |
| 78 | testing.expect(bufset.count() == 0); | |
| 78 | try testing.expect(bufset.count() == 0); | |
| 79 | 79 | |
| 80 | 80 | try bufset.put("x"); |
| 81 | 81 | try bufset.put("y"); |
lib/std/build.zig+11-11| ... | ... | @@ -3060,19 +3060,19 @@ test "Builder.dupePkg()" { |
| 3060 | 3060 | const dupe_deps = dupe.dependencies.?; |
| 3061 | 3061 | |
| 3062 | 3062 | // 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); | |
| 3064 | 3064 | |
| 3065 | 3065 | // probably the same dependencies |
| 3066 | std.testing.expectEqual(original_deps.len, dupe_deps.len); | |
| 3067 | std.testing.expectEqual(original_deps[0].name, pkg_dep.name); | |
| 3066 | try std.testing.expectEqual(original_deps.len, dupe_deps.len); | |
| 3067 | try std.testing.expectEqual(original_deps[0].name, pkg_dep.name); | |
| 3068 | 3068 | |
| 3069 | 3069 | // could segfault otherwise if pointers in duplicated package's fields are |
| 3070 | 3070 | // the same as those in stack allocated package's fields |
| 3071 | std.testing.expect(dupe_deps.ptr != original_deps.ptr); | |
| 3072 | std.testing.expect(dupe.name.ptr != pkg_top.name.ptr); | |
| 3073 | std.testing.expect(dupe.path.ptr != pkg_top.path.ptr); | |
| 3074 | std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr); | |
| 3075 | std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr); | |
| 3071 | try std.testing.expect(dupe_deps.ptr != original_deps.ptr); | |
| 3072 | try std.testing.expect(dupe.name.ptr != pkg_top.name.ptr); | |
| 3073 | try std.testing.expect(dupe.path.ptr != pkg_top.path.ptr); | |
| 3074 | try std.testing.expect(dupe_deps[0].name.ptr != pkg_dep.name.ptr); | |
| 3075 | try std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr); | |
| 3076 | 3076 | } |
| 3077 | 3077 | |
| 3078 | 3078 | test "LibExeObjStep.addBuildOption" { |
| ... | ... | @@ -3096,7 +3096,7 @@ test "LibExeObjStep.addBuildOption" { |
| 3096 | 3096 | exe.addBuildOption(?[]const u8, "optional_string", null); |
| 3097 | 3097 | exe.addBuildOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar")); |
| 3098 | 3098 | |
| 3099 | std.testing.expectEqualStrings( | |
| 3099 | try std.testing.expectEqualStrings( | |
| 3100 | 3100 | \\pub const option1: usize = 1; |
| 3101 | 3101 | \\pub const option2: ?usize = null; |
| 3102 | 3102 | \\pub const string: []const u8 = "zigisthebest"; |
| ... | ... | @@ -3140,10 +3140,10 @@ test "LibExeObjStep.addPackage" { |
| 3140 | 3140 | var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig"); |
| 3141 | 3141 | exe.addPackage(pkg_top); |
| 3142 | 3142 | |
| 3143 | std.testing.expectEqual(@as(usize, 1), exe.packages.items.len); | |
| 3143 | try std.testing.expectEqual(@as(usize, 1), exe.packages.items.len); | |
| 3144 | 3144 | |
| 3145 | 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 | } |
| 3148 | 3148 | |
| 3149 | 3149 | test { |
lib/std/builtin.zig+1-1| ... | ... | @@ -546,7 +546,7 @@ pub fn testVersionParse() !void { |
| 546 | 546 | const f = struct { |
| 547 | 547 | fn eql(text: []const u8, v1: u32, v2: u32, v3: u32) !void { |
| 548 | 548 | const v = try Version.parse(text); |
| 549 | std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3); | |
| 549 | try std.testing.expect(v.major == v1 and v.minor == v2 and v.patch == v3); | |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | 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 | 1310 | }; |
| 1311 | 1311 | |
| 1312 | 1312 | test "operators" { |
| 1313 | expectTokens( | |
| 1313 | try expectTokens( | |
| 1314 | 1314 | \\ ! != | || |= = == |
| 1315 | 1315 | \\ ( ) { } [ ] . .. ... |
| 1316 | 1316 | \\ ^ ^= + ++ += - -- -= |
| ... | ... | @@ -1379,7 +1379,7 @@ test "operators" { |
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | 1381 | test "keywords" { |
| 1382 | expectTokens( | |
| 1382 | try expectTokens( | |
| 1383 | 1383 | \\auto break case char const continue default do |
| 1384 | 1384 | \\double else enum extern float for goto if int |
| 1385 | 1385 | \\long register return short signed sizeof static |
| ... | ... | @@ -1442,7 +1442,7 @@ test "keywords" { |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | test "preprocessor keywords" { |
| 1445 | expectTokens( | |
| 1445 | try expectTokens( | |
| 1446 | 1446 | \\#include <test> |
| 1447 | 1447 | \\#define #include <1 |
| 1448 | 1448 | \\#ifdef |
| ... | ... | @@ -1478,7 +1478,7 @@ test "preprocessor keywords" { |
| 1478 | 1478 | } |
| 1479 | 1479 | |
| 1480 | 1480 | test "line continuation" { |
| 1481 | expectTokens( | |
| 1481 | try expectTokens( | |
| 1482 | 1482 | \\#define foo \ |
| 1483 | 1483 | \\ bar |
| 1484 | 1484 | \\"foo\ |
| ... | ... | @@ -1509,7 +1509,7 @@ test "line continuation" { |
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | test "string prefix" { |
| 1512 | expectTokens( | |
| 1512 | try expectTokens( | |
| 1513 | 1513 | \\"foo" |
| 1514 | 1514 | \\u"foo" |
| 1515 | 1515 | \\u8"foo" |
| ... | ... | @@ -1543,7 +1543,7 @@ test "string prefix" { |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | test "num suffixes" { |
| 1546 | expectTokens( | |
| 1546 | try expectTokens( | |
| 1547 | 1547 | \\ 1.0f 1.0L 1.0 .0 1. |
| 1548 | 1548 | \\ 0l 0lu 0ll 0llu 0 |
| 1549 | 1549 | \\ 1u 1ul 1ull 1 |
| ... | ... | @@ -1573,7 +1573,7 @@ test "num suffixes" { |
| 1573 | 1573 | }); |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void { | |
| 1576 | fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) !void { | |
| 1577 | 1577 | var tokenizer = Tokenizer{ |
| 1578 | 1578 | .buffer = source, |
| 1579 | 1579 | }; |
| ... | ... | @@ -1584,5 +1584,5 @@ fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void { |
| 1584 | 1584 | } |
| 1585 | 1585 | } |
| 1586 | 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 | 1005 | defer arena.deinit(); |
| 1006 | 1006 | const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap); |
| 1007 | 1007 | |
| 1008 | testing.expectEqual(@as(usize, 5), environ.len); | |
| 1008 | try testing.expectEqual(@as(usize, 5), environ.len); | |
| 1009 | 1009 | |
| 1010 | 1010 | inline for (.{ |
| 1011 | 1011 | "HOME=/home/ifreund", |
| ... | ... | @@ -1017,7 +1017,7 @@ test "createNullDelimitedEnvMap" { |
| 1017 | 1017 | for (environ) |variable| { |
| 1018 | 1018 | if (mem.eql(u8, mem.span(variable orelse continue), target)) break; |
| 1019 | 1019 | } else { |
| 1020 | testing.expect(false); // Environment variable not found | |
| 1020 | 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 | 669 | var inflate = inflateStream(reader, &window); |
| 670 | 670 | |
| 671 | 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 | 172 | var hash: [32]u8 = undefined; |
| 173 | 173 | std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{}); |
| 174 | 174 | |
| 175 | assertEqual(expected, &hash); | |
| 175 | try assertEqual(expected, &hash); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Assert `expected` == `input` where `input` is a bytestring. |
| 179 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) void { | |
| 179 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void { | |
| 180 | 180 | var expected_bytes: [expected.len / 2]u8 = undefined; |
| 181 | 181 | for (expected_bytes) |*r, i| { |
| 182 | 182 | r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | testing.expectEqualSlices(u8, &expected_bytes, input); | |
| 185 | try testing.expectEqualSlices(u8, &expected_bytes, input); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // All the test cases are obtained by compressing the RFC1952 text |
| ... | ... | @@ -198,12 +198,12 @@ test "compressed data" { |
| 198 | 198 | |
| 199 | 199 | test "sanity checks" { |
| 200 | 200 | // Truncated header |
| 201 | testing.expectError( | |
| 201 | try testing.expectError( | |
| 202 | 202 | error.EndOfStream, |
| 203 | 203 | testReader(&[_]u8{ 0x1f, 0x8B }, ""), |
| 204 | 204 | ); |
| 205 | 205 | // Wrong CM |
| 206 | testing.expectError( | |
| 206 | try testing.expectError( | |
| 207 | 207 | error.InvalidCompression, |
| 208 | 208 | testReader(&[_]u8{ |
| 209 | 209 | 0x1f, 0x8b, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, |
| ... | ... | @@ -211,7 +211,7 @@ test "sanity checks" { |
| 211 | 211 | }, ""), |
| 212 | 212 | ); |
| 213 | 213 | // Wrong checksum |
| 214 | testing.expectError( | |
| 214 | try testing.expectError( | |
| 215 | 215 | error.WrongChecksum, |
| 216 | 216 | testReader(&[_]u8{ |
| 217 | 217 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| ... | ... | @@ -220,7 +220,7 @@ test "sanity checks" { |
| 220 | 220 | }, ""), |
| 221 | 221 | ); |
| 222 | 222 | // Truncated checksum |
| 223 | testing.expectError( | |
| 223 | try testing.expectError( | |
| 224 | 224 | error.EndOfStream, |
| 225 | 225 | testReader(&[_]u8{ |
| 226 | 226 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| ... | ... | @@ -228,7 +228,7 @@ test "sanity checks" { |
| 228 | 228 | }, ""), |
| 229 | 229 | ); |
| 230 | 230 | // Wrong initial size |
| 231 | testing.expectError( | |
| 231 | try testing.expectError( | |
| 232 | 232 | error.CorruptedData, |
| 233 | 233 | testReader(&[_]u8{ |
| 234 | 234 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, |
| ... | ... | @@ -237,7 +237,7 @@ test "sanity checks" { |
| 237 | 237 | }, ""), |
| 238 | 238 | ); |
| 239 | 239 | // Truncated initial size field |
| 240 | testing.expectError( | |
| 240 | try testing.expectError( | |
| 241 | 241 | error.EndOfStream, |
| 242 | 242 | testReader(&[_]u8{ |
| 243 | 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 | 109 | var hash: [32]u8 = undefined; |
| 110 | 110 | std.crypto.hash.sha2.Sha256.hash(buf, hash[0..], .{}); |
| 111 | 111 | |
| 112 | assertEqual(expected, &hash); | |
| 112 | try assertEqual(expected, &hash); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Assert `expected` == `input` where `input` is a bytestring. |
| 116 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) void { | |
| 116 | pub fn assertEqual(comptime expected: []const u8, input: []const u8) !void { | |
| 117 | 117 | var expected_bytes: [expected.len / 2]u8 = undefined; |
| 118 | 118 | for (expected_bytes) |*r, i| { |
| 119 | 119 | r.* = std.fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | testing.expectEqualSlices(u8, &expected_bytes, input); | |
| 122 | try testing.expectEqualSlices(u8, &expected_bytes, input); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // 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 | 159 | |
| 160 | 160 | test "sanity checks" { |
| 161 | 161 | // Truncated header |
| 162 | testing.expectError( | |
| 162 | try testing.expectError( | |
| 163 | 163 | error.EndOfStream, |
| 164 | 164 | testReader(&[_]u8{0x78}, ""), |
| 165 | 165 | ); |
| 166 | 166 | // Failed FCHECK check |
| 167 | testing.expectError( | |
| 167 | try testing.expectError( | |
| 168 | 168 | error.BadHeader, |
| 169 | 169 | testReader(&[_]u8{ 0x78, 0x9D }, ""), |
| 170 | 170 | ); |
| 171 | 171 | // Wrong CM |
| 172 | testing.expectError( | |
| 172 | try testing.expectError( | |
| 173 | 173 | error.InvalidCompression, |
| 174 | 174 | testReader(&[_]u8{ 0x79, 0x94 }, ""), |
| 175 | 175 | ); |
| 176 | 176 | // Wrong CINFO |
| 177 | testing.expectError( | |
| 177 | try testing.expectError( | |
| 178 | 178 | error.InvalidWindowSize, |
| 179 | 179 | testReader(&[_]u8{ 0x88, 0x98 }, ""), |
| 180 | 180 | ); |
| 181 | 181 | // Wrong checksum |
| 182 | testing.expectError( | |
| 182 | try testing.expectError( | |
| 183 | 183 | error.WrongChecksum, |
| 184 | 184 | testReader(&[_]u8{ 0x78, 0xda, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, ""), |
| 185 | 185 | ); |
| 186 | 186 | // Truncated checksum |
| 187 | testing.expectError( | |
| 187 | try testing.expectError( | |
| 188 | 188 | error.EndOfStream, |
| 189 | 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 | 95 | .{ "samelen", .E }, |
| 96 | 96 | }); |
| 97 | 97 | |
| 98 | testMap(map); | |
| 98 | try testMap(map); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | test "ComptimeStringMap array of structs" { |
| ... | ... | @@ -111,7 +111,7 @@ test "ComptimeStringMap array of structs" { |
| 111 | 111 | .{ .@"0" = "samelen", .@"1" = .E }, |
| 112 | 112 | }); |
| 113 | 113 | |
| 114 | testMap(map); | |
| 114 | try testMap(map); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "ComptimeStringMap slice of structs" { |
| ... | ... | @@ -128,18 +128,18 @@ test "ComptimeStringMap slice of structs" { |
| 128 | 128 | }; |
| 129 | 129 | const map = ComptimeStringMap(TestEnum, slice); |
| 130 | 130 | |
| 131 | testMap(map); | |
| 131 | try testMap(map); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | fn testMap(comptime map: anytype) void { | |
| 135 | std.testing.expectEqual(TestEnum.A, map.get("have").?); | |
| 136 | std.testing.expectEqual(TestEnum.B, map.get("nothing").?); | |
| 137 | std.testing.expect(null == map.get("missing")); | |
| 138 | std.testing.expectEqual(TestEnum.D, map.get("these").?); | |
| 139 | std.testing.expectEqual(TestEnum.E, map.get("samelen").?); | |
| 134 | fn testMap(comptime map: anytype) !void { | |
| 135 | try std.testing.expectEqual(TestEnum.A, map.get("have").?); | |
| 136 | try std.testing.expectEqual(TestEnum.B, map.get("nothing").?); | |
| 137 | try std.testing.expect(null == map.get("missing")); | |
| 138 | try std.testing.expectEqual(TestEnum.D, map.get("these").?); | |
| 139 | try std.testing.expectEqual(TestEnum.E, map.get("samelen").?); | |
| 140 | 140 | |
| 141 | std.testing.expect(!map.has("missing")); | |
| 142 | std.testing.expect(map.has("these")); | |
| 141 | try std.testing.expect(!map.has("missing")); | |
| 142 | try std.testing.expect(map.has("these")); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "ComptimeStringMap void value type, slice of structs" { |
| ... | ... | @@ -155,7 +155,7 @@ test "ComptimeStringMap void value type, slice of structs" { |
| 155 | 155 | }; |
| 156 | 156 | const map = ComptimeStringMap(void, slice); |
| 157 | 157 | |
| 158 | testSet(map); | |
| 158 | try testSet(map); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | 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 | 167 | .{"samelen"}, |
| 168 | 168 | }); |
| 169 | 169 | |
| 170 | testSet(map); | |
| 170 | try testSet(map); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | fn testSet(comptime map: anytype) void { | |
| 174 | std.testing.expectEqual({}, map.get("have").?); | |
| 175 | std.testing.expectEqual({}, map.get("nothing").?); | |
| 176 | std.testing.expect(null == map.get("missing")); | |
| 177 | std.testing.expectEqual({}, map.get("these").?); | |
| 178 | std.testing.expectEqual({}, map.get("samelen").?); | |
| 173 | fn testSet(comptime map: anytype) !void { | |
| 174 | try std.testing.expectEqual({}, map.get("have").?); | |
| 175 | try std.testing.expectEqual({}, map.get("nothing").?); | |
| 176 | try std.testing.expect(null == map.get("missing")); | |
| 177 | try std.testing.expectEqual({}, map.get("these").?); | |
| 178 | try std.testing.expectEqual({}, map.get("samelen").?); | |
| 179 | 179 | |
| 180 | std.testing.expect(!map.has("missing")); | |
| 181 | std.testing.expect(map.has("these")); | |
| 180 | try std.testing.expect(!map.has("missing")); | |
| 181 | try std.testing.expect(map.has("these")); | |
| 182 | 182 | } |
lib/std/crypto.zig+2-2| ... | ... | @@ -188,7 +188,7 @@ test "CSPRNG" { |
| 188 | 188 | const a = random.int(u64); |
| 189 | 189 | const b = random.int(u64); |
| 190 | 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 | } |
| 193 | 193 | |
| 194 | 194 | test "issue #4532: no index out of bounds" { |
| ... | ... | @@ -226,6 +226,6 @@ test "issue #4532: no index out of bounds" { |
| 226 | 226 | h.update(block[1..]); |
| 227 | 227 | h.final(&out2); |
| 228 | 228 | |
| 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 | 120 | const p = try Curve25519.basePoint.clampedMul(s); |
| 121 | 121 | try p.rejectIdentity(); |
| 122 | 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 | 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"); | |
| 126 | 126 | |
| 127 | 127 | try Curve25519.rejectNonCanonical(s); |
| 128 | 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 | } |
| 131 | 131 | |
| 132 | 132 | test "curve25519 small order check" { |
| ... | ... | @@ -155,13 +155,13 @@ test "curve25519 small order check" { |
| 155 | 155 | }, |
| 156 | 156 | }; |
| 157 | 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 | 159 | var extra = small_order_s; |
| 160 | 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 | 162 | var valid = small_order_s; |
| 163 | 163 | valid[31] = 0x40; |
| 164 | 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 | 219 | _ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); |
| 220 | 220 | const key_pair = try Ed25519.KeyPair.create(seed); |
| 221 | 221 | var buf: [256]u8 = undefined; |
| 222 | std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083"); | |
| 223 | std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083"); | |
| 222 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083"); | |
| 223 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083"); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | test "ed25519 signature" { |
| ... | ... | @@ -230,9 +230,9 @@ test "ed25519 signature" { |
| 230 | 230 | |
| 231 | 231 | const sig = try Ed25519.sign("test", key_pair, null); |
| 232 | 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 | 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 | } |
| 237 | 237 | |
| 238 | 238 | test "ed25519 batch verification" { |
| ... | ... | @@ -260,7 +260,7 @@ test "ed25519 batch verification" { |
| 260 | 260 | try Ed25519.verifyBatch(2, signature_batch); |
| 261 | 261 | |
| 262 | 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 | } |
| 266 | 266 | |
| ... | ... | @@ -354,7 +354,7 @@ test "ed25519 test vectors" { |
| 354 | 354 | var sig: [64]u8 = undefined; |
| 355 | 355 | _ = try fmt.hexToBytes(&sig, entry.sig_hex); |
| 356 | 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 | 358 | } else { |
| 359 | 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 | 491 | var b = Edwards25519.basePoint; |
| 492 | 492 | const pk = try b.mul(s); |
| 493 | 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"); | |
| 495 | 495 | |
| 496 | 496 | const small_order_ss: [7][32]u8 = .{ |
| 497 | 497 | .{ |
| ... | ... | @@ -518,7 +518,7 @@ test "edwards25519 packing/unpacking" { |
| 518 | 518 | }; |
| 519 | 519 | for (small_order_ss) |small_order_s| { |
| 520 | 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 | } |
| 524 | 524 | |
| ... | ... | @@ -531,26 +531,26 @@ test "edwards25519 point addition/substraction" { |
| 531 | 531 | const q = try Edwards25519.basePoint.clampedMul(s2); |
| 532 | 532 | const r = p.add(q).add(q).sub(q).sub(q); |
| 533 | 533 | try r.rejectIdentity(); |
| 534 | std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity()); | |
| 535 | std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity()); | |
| 536 | std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity()); | |
| 534 | try std.testing.expectError(error.IdentityElement, r.sub(p).rejectIdentity()); | |
| 535 | try std.testing.expectError(error.IdentityElement, p.sub(p).rejectIdentity()); | |
| 536 | try std.testing.expectError(error.IdentityElement, p.sub(q).add(q).sub(p).rejectIdentity()); | |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | test "edwards25519 uniform-to-point" { |
| 540 | 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 | 541 | var p = Edwards25519.fromUniform(r); |
| 542 | htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]); | |
| 542 | try htest.assertEqual("0691eee3cf70a0056df6bfa03120635636581b5c4ea571dfc680f78c7e0b4137", p.toBytes()[0..]); | |
| 543 | 543 | |
| 544 | 544 | r[31] = 0xff; |
| 545 | 545 | p = Edwards25519.fromUniform(r); |
| 546 | htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]); | |
| 546 | try htest.assertEqual("f70718e68ef42d90ca1d936bb2d7e159be6c01d8095d39bd70487c82fe5c973a", p.toBytes()[0..]); | |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | // Test vectors from draft-irtf-cfrg-hash-to-curve-10 |
| 550 | 550 | test "edwards25519 hash-to-curve operation" { |
| 551 | 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..]); | |
| 553 | 553 | |
| 554 | 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 | 175 | test "ristretto255" { |
| 176 | 176 | const p = Ristretto255.basePoint; |
| 177 | 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"); | |
| 179 | 179 | |
| 180 | 180 | var r: [Ristretto255.encoded_length]u8 = undefined; |
| 181 | 181 | _ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919"); |
| 182 | 182 | var q = try Ristretto255.fromBytes(r); |
| 183 | 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"); | |
| 185 | 185 | |
| 186 | 186 | const s = [_]u8{15} ++ [_]u8{0} ** 31; |
| 187 | 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"); | |
| 189 | 189 | |
| 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))); | |
| 191 | 191 | |
| 192 | 192 | const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32; |
| 193 | 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 | 773 | var y = x.toBytes(); |
| 774 | 774 | try rejectNonCanonical(y); |
| 775 | 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"); | |
| 777 | 777 | |
| 778 | 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 | } |
| 781 | 781 | |
| 782 | 782 | test "non-canonical scalar25519" { |
| 783 | 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 | } |
| 786 | 786 | |
| 787 | 787 | test "mulAdd overflow check" { |
| ... | ... | @@ -790,5 +790,5 @@ test "mulAdd overflow check" { |
| 790 | 790 | const c: [32]u8 = [_]u8{0xff} ** 32; |
| 791 | 791 | const x = mulAdd(a, b, c); |
| 792 | 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 | 92 | _ = try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); |
| 93 | 93 | _ = try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50"); |
| 94 | 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 | } |
| 97 | 97 | |
| 98 | 98 | test "x25519 rfc7748 vector1" { |
| ... | ... | @@ -102,7 +102,7 @@ test "x25519 rfc7748 vector1" { |
| 102 | 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 }; |
| 103 | 103 | |
| 104 | 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 | } |
| 107 | 107 | |
| 108 | 108 | test "x25519 rfc7748 vector2" { |
| ... | ... | @@ -112,7 +112,7 @@ test "x25519 rfc7748 vector2" { |
| 112 | 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 }; |
| 113 | 113 | |
| 114 | 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 | } |
| 117 | 117 | |
| 118 | 118 | test "x25519 rfc7748 one iteration" { |
| ... | ... | @@ -129,7 +129,7 @@ test "x25519 rfc7748 one iteration" { |
| 129 | 129 | mem.copy(u8, k[0..], output[0..]); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | std.testing.expectEqual(k, expected_output); | |
| 132 | try std.testing.expectEqual(k, expected_output); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | test "x25519 rfc7748 1,000 iterations" { |
| ... | ... | @@ -151,7 +151,7 @@ test "x25519 rfc7748 1,000 iterations" { |
| 151 | 151 | mem.copy(u8, k[0..], output[0..]); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | std.testing.expectEqual(k, expected_output); | |
| 154 | try std.testing.expectEqual(k, expected_output); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | test "x25519 rfc7748 1,000,000 iterations" { |
| ... | ... | @@ -172,12 +172,12 @@ test "x25519 rfc7748 1,000,000 iterations" { |
| 172 | 172 | mem.copy(u8, k[0..], output[0..]); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | std.testing.expectEqual(k[0..], expected_output); | |
| 175 | try std.testing.expectEqual(k[0..], expected_output); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | test "edwards25519 -> curve25519 map" { |
| 179 | 179 | const ed_kp = try crypto.sign.Ed25519.KeyPair.create([_]u8{0x42} ** 32); |
| 180 | 180 | const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); |
| 181 | htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); | |
| 182 | htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); | |
| 181 | try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); | |
| 182 | try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); | |
| 183 | 183 | } |
lib/std/crypto/aegis.zig+20-20| ... | ... | @@ -352,16 +352,16 @@ test "Aegis128L test vector 1" { |
| 352 | 352 | |
| 353 | 353 | Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 354 | 354 | try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 355 | testing.expectEqualSlices(u8, &m, &m2); | |
| 355 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 356 | 356 | |
| 357 | htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c); | |
| 358 | htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag); | |
| 357 | try htest.assertEqual("79d94593d8c2119d7e8fd9b8fc77845c5c077a05b2528b6ac54b563aed8efe84", &c); | |
| 358 | try htest.assertEqual("cc6f3372f6aa1bb82388d695c3962d9a", &tag); | |
| 359 | 359 | |
| 360 | 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 | 362 | c[0] -%= 1; |
| 363 | 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 | } |
| 366 | 366 | |
| 367 | 367 | test "Aegis128L test vector 2" { |
| ... | ... | @@ -375,10 +375,10 @@ test "Aegis128L test vector 2" { |
| 375 | 375 | |
| 376 | 376 | Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 377 | 377 | try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 378 | testing.expectEqualSlices(u8, &m, &m2); | |
| 378 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 379 | 379 | |
| 380 | htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c); | |
| 381 | htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag); | |
| 380 | try htest.assertEqual("41de9000a7b5e40e2d68bb64d99ebb19", &c); | |
| 381 | try htest.assertEqual("f4d997cc9b94227ada4fe4165422b1c8", &tag); | |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | test "Aegis128L test vector 3" { |
| ... | ... | @@ -392,9 +392,9 @@ test "Aegis128L test vector 3" { |
| 392 | 392 | |
| 393 | 393 | Aegis128L.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 394 | 394 | try Aegis128L.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 395 | testing.expectEqualSlices(u8, &m, &m2); | |
| 395 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 396 | 396 | |
| 397 | htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag); | |
| 397 | try htest.assertEqual("83cc600dc4e3e7e62d4055826174f149", &tag); | |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | test "Aegis256 test vector 1" { |
| ... | ... | @@ -408,16 +408,16 @@ test "Aegis256 test vector 1" { |
| 408 | 408 | |
| 409 | 409 | Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 410 | 410 | try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 411 | testing.expectEqualSlices(u8, &m, &m2); | |
| 411 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 412 | 412 | |
| 413 | htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c); | |
| 414 | htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag); | |
| 413 | try htest.assertEqual("f373079ed84b2709faee373584585d60accd191db310ef5d8b11833df9dec711", &c); | |
| 414 | try htest.assertEqual("8d86f91ee606e9ff26a01b64ccbdd91d", &tag); | |
| 415 | 415 | |
| 416 | 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 | 418 | c[0] -%= 1; |
| 419 | 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 | } |
| 422 | 422 | |
| 423 | 423 | test "Aegis256 test vector 2" { |
| ... | ... | @@ -431,10 +431,10 @@ test "Aegis256 test vector 2" { |
| 431 | 431 | |
| 432 | 432 | Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 433 | 433 | try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 434 | testing.expectEqualSlices(u8, &m, &m2); | |
| 434 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 435 | 435 | |
| 436 | htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c); | |
| 437 | htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag); | |
| 436 | try htest.assertEqual("b98f03a947807713d75a4fff9fc277a6", &c); | |
| 437 | try htest.assertEqual("478f3b50dc478ef7d5cf2d0f7cc13180", &tag); | |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | test "Aegis256 test vector 3" { |
| ... | ... | @@ -448,7 +448,7 @@ test "Aegis256 test vector 3" { |
| 448 | 448 | |
| 449 | 449 | Aegis256.encrypt(&c, &tag, &m, &ad, nonce, key); |
| 450 | 450 | try Aegis256.decrypt(&m2, &c, tag, &ad, nonce, key); |
| 451 | testing.expectEqualSlices(u8, &m, &m2); | |
| 451 | try testing.expectEqualSlices(u8, &m, &m2); | |
| 452 | 452 | |
| 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 | 48 | var out: [exp_out.len]u8 = undefined; |
| 49 | 49 | var ctx = Aes128.initEnc(key); |
| 50 | 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 | } |
| 53 | 53 | |
| 54 | 54 | test "encrypt" { |
| ... | ... | @@ -61,7 +61,7 @@ test "encrypt" { |
| 61 | 61 | var out: [exp_out.len]u8 = undefined; |
| 62 | 62 | var ctx = Aes128.initEnc(key); |
| 63 | 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 | } |
| 66 | 66 | |
| 67 | 67 | // Appendix C.3 |
| ... | ... | @@ -76,7 +76,7 @@ test "encrypt" { |
| 76 | 76 | var out: [exp_out.len]u8 = undefined; |
| 77 | 77 | var ctx = Aes256.initEnc(key); |
| 78 | 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 | } |
| 82 | 82 | |
| ... | ... | @@ -90,7 +90,7 @@ test "decrypt" { |
| 90 | 90 | var out: [exp_out.len]u8 = undefined; |
| 91 | 91 | var ctx = Aes128.initDec(key); |
| 92 | 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 | } |
| 95 | 95 | |
| 96 | 96 | // Appendix C.3 |
| ... | ... | @@ -105,7 +105,7 @@ test "decrypt" { |
| 105 | 105 | var out: [exp_out.len]u8 = undefined; |
| 106 | 106 | var ctx = Aes256.initDec(key); |
| 107 | 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 | } |
| 111 | 111 | |
| ... | ... | @@ -123,11 +123,11 @@ test "expand 128-bit key" { |
| 123 | 123 | |
| 124 | 124 | for (enc.key_schedule.round_keys) |round_key, i| { |
| 125 | 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 | 128 | for (enc.key_schedule.round_keys) |round_key, i| { |
| 129 | 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 | } |
| 133 | 133 | |
| ... | ... | @@ -145,10 +145,10 @@ test "expand 256-bit key" { |
| 145 | 145 | |
| 146 | 146 | for (enc.key_schedule.round_keys) |round_key, i| { |
| 147 | 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 | 150 | for (dec.key_schedule.round_keys) |round_key, i| { |
| 151 | 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 | 118 | var tag: [Aes256Gcm.tag_length]u8 = undefined; |
| 119 | 119 | |
| 120 | 120 | Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key); |
| 121 | htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag); | |
| 121 | try htest.assertEqual("6b6ff610a16fa4cd59f1fb7903154e92", &tag); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | test "Aes256Gcm - Associated data only" { |
| ... | ... | @@ -130,7 +130,7 @@ test "Aes256Gcm - Associated data only" { |
| 130 | 130 | var tag: [Aes256Gcm.tag_length]u8 = undefined; |
| 131 | 131 | |
| 132 | 132 | Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key); |
| 133 | htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag); | |
| 133 | try htest.assertEqual("262ed164c2dfb26e080a9d108dd9dd4c", &tag); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "Aes256Gcm - Message only" { |
| ... | ... | @@ -144,10 +144,10 @@ test "Aes256Gcm - Message only" { |
| 144 | 144 | |
| 145 | 145 | Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key); |
| 146 | 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..]); | |
| 148 | 148 | |
| 149 | htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c); | |
| 150 | htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag); | |
| 149 | try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01d539472f7c", &c); | |
| 150 | try htest.assertEqual("07cd7fc9103e2f9e9bf2dfaa319caff4", &tag); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | test "Aes256Gcm - Message and associated data" { |
| ... | ... | @@ -161,8 +161,8 @@ test "Aes256Gcm - Message and associated data" { |
| 161 | 161 | |
| 162 | 162 | Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key); |
| 163 | 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..]); | |
| 165 | 165 | |
| 166 | htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c); | |
| 167 | htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag); | |
| 166 | try htest.assertEqual("5ca1642d90009fea33d01f78cf6eefaf01", &c); | |
| 167 | try htest.assertEqual("64accec679d444e2373bd9f6796c0d2c", &tag); | |
| 168 | 168 | } |
lib/std/crypto/bcrypt.zig+2-2| ... | ... | @@ -281,13 +281,13 @@ test "bcrypt codec" { |
| 281 | 281 | Codec.encode(salt_str[0..], salt[0..]); |
| 282 | 282 | var salt2: [salt_length]u8 = undefined; |
| 283 | 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 | } |
| 286 | 286 | |
| 287 | 287 | test "bcrypt" { |
| 288 | 288 | const s = try strHash("password", 5); |
| 289 | 289 | try strVerify(s, "password"); |
| 290 | testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password")); | |
| 290 | try testing.expectError(error.PasswordVerificationFailed, strVerify(s, "invalid password")); | |
| 291 | 291 | |
| 292 | 292 | const long_s = try strHash("password" ** 100, 5); |
| 293 | 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 | 194 | |
| 195 | 195 | test "blake2s160 single" { |
| 196 | 196 | const h1 = "354c9c33f735962418bdacb9479873429c34916f"; |
| 197 | htest.assertEqualHash(Blake2s160, h1, ""); | |
| 197 | try htest.assertEqualHash(Blake2s160, h1, ""); | |
| 198 | 198 | |
| 199 | 199 | const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17"; |
| 200 | htest.assertEqualHash(Blake2s160, h2, "abc"); | |
| 200 | try htest.assertEqualHash(Blake2s160, h2, "abc"); | |
| 201 | 201 | |
| 202 | 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"); | |
| 204 | 204 | |
| 205 | 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 | } |
| 208 | 208 | |
| 209 | 209 | test "blake2s160 streaming" { |
| ... | ... | @@ -213,21 +213,21 @@ test "blake2s160 streaming" { |
| 213 | 213 | const h1 = "354c9c33f735962418bdacb9479873429c34916f"; |
| 214 | 214 | |
| 215 | 215 | h.final(out[0..]); |
| 216 | htest.assertEqual(h1, out[0..]); | |
| 216 | try htest.assertEqual(h1, out[0..]); | |
| 217 | 217 | |
| 218 | 218 | const h2 = "5ae3b99be29b01834c3b508521ede60438f8de17"; |
| 219 | 219 | |
| 220 | 220 | h = Blake2s160.init(.{}); |
| 221 | 221 | h.update("abc"); |
| 222 | 222 | h.final(out[0..]); |
| 223 | htest.assertEqual(h2, out[0..]); | |
| 223 | try htest.assertEqual(h2, out[0..]); | |
| 224 | 224 | |
| 225 | 225 | h = Blake2s160.init(.{}); |
| 226 | 226 | h.update("a"); |
| 227 | 227 | h.update("b"); |
| 228 | 228 | h.update("c"); |
| 229 | 229 | h.final(out[0..]); |
| 230 | htest.assertEqual(h2, out[0..]); | |
| 230 | try htest.assertEqual(h2, out[0..]); | |
| 231 | 231 | |
| 232 | 232 | const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; |
| 233 | 233 | |
| ... | ... | @@ -235,12 +235,12 @@ test "blake2s160 streaming" { |
| 235 | 235 | h.update("a" ** 32); |
| 236 | 236 | h.update("b" ** 32); |
| 237 | 237 | h.final(out[0..]); |
| 238 | htest.assertEqual(h3, out[0..]); | |
| 238 | try htest.assertEqual(h3, out[0..]); | |
| 239 | 239 | |
| 240 | 240 | h = Blake2s160.init(.{}); |
| 241 | 241 | h.update("a" ** 32 ++ "b" ** 32); |
| 242 | 242 | h.final(out[0..]); |
| 243 | htest.assertEqual(h3, out[0..]); | |
| 243 | try htest.assertEqual(h3, out[0..]); | |
| 244 | 244 | |
| 245 | 245 | const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68"; |
| 246 | 246 | |
| ... | ... | @@ -248,12 +248,12 @@ test "blake2s160 streaming" { |
| 248 | 248 | h.update("a" ** 32); |
| 249 | 249 | h.update("b" ** 32); |
| 250 | 250 | h.final(out[0..]); |
| 251 | htest.assertEqual(h4, out[0..]); | |
| 251 | try htest.assertEqual(h4, out[0..]); | |
| 252 | 252 | |
| 253 | 253 | h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); |
| 254 | 254 | h.update("a" ** 32 ++ "b" ** 32); |
| 255 | 255 | h.final(out[0..]); |
| 256 | htest.assertEqual(h4, out[0..]); | |
| 256 | try htest.assertEqual(h4, out[0..]); | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | test "comptime blake2s160" { |
| ... | ... | @@ -265,28 +265,28 @@ test "comptime blake2s160" { |
| 265 | 265 | |
| 266 | 266 | const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f"; |
| 267 | 267 | |
| 268 | htest.assertEqualHash(Blake2s160, h1, block[0..]); | |
| 268 | try htest.assertEqualHash(Blake2s160, h1, block[0..]); | |
| 269 | 269 | |
| 270 | 270 | var h = Blake2s160.init(.{}); |
| 271 | 271 | h.update(&block); |
| 272 | 272 | h.final(out[0..]); |
| 273 | 273 | |
| 274 | htest.assertEqual(h1, out[0..]); | |
| 274 | try htest.assertEqual(h1, out[0..]); | |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | test "blake2s224 single" { |
| 279 | 279 | const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4"; |
| 280 | htest.assertEqualHash(Blake2s224, h1, ""); | |
| 280 | try htest.assertEqualHash(Blake2s224, h1, ""); | |
| 281 | 281 | |
| 282 | 282 | const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55"; |
| 283 | htest.assertEqualHash(Blake2s224, h2, "abc"); | |
| 283 | try htest.assertEqualHash(Blake2s224, h2, "abc"); | |
| 284 | 284 | |
| 285 | 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"); | |
| 287 | 287 | |
| 288 | 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 | } |
| 291 | 291 | |
| 292 | 292 | test "blake2s224 streaming" { |
| ... | ... | @@ -296,21 +296,21 @@ test "blake2s224 streaming" { |
| 296 | 296 | const h1 = "1fa1291e65248b37b3433475b2a0dd63d54a11ecc4e3e034e7bc1ef4"; |
| 297 | 297 | |
| 298 | 298 | h.final(out[0..]); |
| 299 | htest.assertEqual(h1, out[0..]); | |
| 299 | try htest.assertEqual(h1, out[0..]); | |
| 300 | 300 | |
| 301 | 301 | const h2 = "0b033fc226df7abde29f67a05d3dc62cf271ef3dfea4d387407fbd55"; |
| 302 | 302 | |
| 303 | 303 | h = Blake2s224.init(.{}); |
| 304 | 304 | h.update("abc"); |
| 305 | 305 | h.final(out[0..]); |
| 306 | htest.assertEqual(h2, out[0..]); | |
| 306 | try htest.assertEqual(h2, out[0..]); | |
| 307 | 307 | |
| 308 | 308 | h = Blake2s224.init(.{}); |
| 309 | 309 | h.update("a"); |
| 310 | 310 | h.update("b"); |
| 311 | 311 | h.update("c"); |
| 312 | 312 | h.final(out[0..]); |
| 313 | htest.assertEqual(h2, out[0..]); | |
| 313 | try htest.assertEqual(h2, out[0..]); | |
| 314 | 314 | |
| 315 | 315 | const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; |
| 316 | 316 | |
| ... | ... | @@ -318,12 +318,12 @@ test "blake2s224 streaming" { |
| 318 | 318 | h.update("a" ** 32); |
| 319 | 319 | h.update("b" ** 32); |
| 320 | 320 | h.final(out[0..]); |
| 321 | htest.assertEqual(h3, out[0..]); | |
| 321 | try htest.assertEqual(h3, out[0..]); | |
| 322 | 322 | |
| 323 | 323 | h = Blake2s224.init(.{}); |
| 324 | 324 | h.update("a" ** 32 ++ "b" ** 32); |
| 325 | 325 | h.final(out[0..]); |
| 326 | htest.assertEqual(h3, out[0..]); | |
| 326 | try htest.assertEqual(h3, out[0..]); | |
| 327 | 327 | |
| 328 | 328 | const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3"; |
| 329 | 329 | |
| ... | ... | @@ -331,12 +331,12 @@ test "blake2s224 streaming" { |
| 331 | 331 | h.update("a" ** 32); |
| 332 | 332 | h.update("b" ** 32); |
| 333 | 333 | h.final(out[0..]); |
| 334 | htest.assertEqual(h4, out[0..]); | |
| 334 | try htest.assertEqual(h4, out[0..]); | |
| 335 | 335 | |
| 336 | 336 | h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); |
| 337 | 337 | h.update("a" ** 32 ++ "b" ** 32); |
| 338 | 338 | h.final(out[0..]); |
| 339 | htest.assertEqual(h4, out[0..]); | |
| 339 | try htest.assertEqual(h4, out[0..]); | |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | test "comptime blake2s224" { |
| ... | ... | @@ -347,28 +347,28 @@ test "comptime blake2s224" { |
| 347 | 347 | |
| 348 | 348 | const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576"; |
| 349 | 349 | |
| 350 | htest.assertEqualHash(Blake2s224, h1, block[0..]); | |
| 350 | try htest.assertEqualHash(Blake2s224, h1, block[0..]); | |
| 351 | 351 | |
| 352 | 352 | var h = Blake2s224.init(.{}); |
| 353 | 353 | h.update(&block); |
| 354 | 354 | h.final(out[0..]); |
| 355 | 355 | |
| 356 | htest.assertEqual(h1, out[0..]); | |
| 356 | try htest.assertEqual(h1, out[0..]); | |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | test "blake2s256 single" { |
| 361 | 361 | const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9"; |
| 362 | htest.assertEqualHash(Blake2s256, h1, ""); | |
| 362 | try htest.assertEqualHash(Blake2s256, h1, ""); | |
| 363 | 363 | |
| 364 | 364 | const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982"; |
| 365 | htest.assertEqualHash(Blake2s256, h2, "abc"); | |
| 365 | try htest.assertEqualHash(Blake2s256, h2, "abc"); | |
| 366 | 366 | |
| 367 | 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"); | |
| 369 | 369 | |
| 370 | 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 | } |
| 373 | 373 | |
| 374 | 374 | test "blake2s256 streaming" { |
| ... | ... | @@ -378,21 +378,21 @@ test "blake2s256 streaming" { |
| 378 | 378 | const h1 = "69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9"; |
| 379 | 379 | |
| 380 | 380 | h.final(out[0..]); |
| 381 | htest.assertEqual(h1, out[0..]); | |
| 381 | try htest.assertEqual(h1, out[0..]); | |
| 382 | 382 | |
| 383 | 383 | const h2 = "508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982"; |
| 384 | 384 | |
| 385 | 385 | h = Blake2s256.init(.{}); |
| 386 | 386 | h.update("abc"); |
| 387 | 387 | h.final(out[0..]); |
| 388 | htest.assertEqual(h2, out[0..]); | |
| 388 | try htest.assertEqual(h2, out[0..]); | |
| 389 | 389 | |
| 390 | 390 | h = Blake2s256.init(.{}); |
| 391 | 391 | h.update("a"); |
| 392 | 392 | h.update("b"); |
| 393 | 393 | h.update("c"); |
| 394 | 394 | h.final(out[0..]); |
| 395 | htest.assertEqual(h2, out[0..]); | |
| 395 | try htest.assertEqual(h2, out[0..]); | |
| 396 | 396 | |
| 397 | 397 | const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; |
| 398 | 398 | |
| ... | ... | @@ -400,12 +400,12 @@ test "blake2s256 streaming" { |
| 400 | 400 | h.update("a" ** 32); |
| 401 | 401 | h.update("b" ** 32); |
| 402 | 402 | h.final(out[0..]); |
| 403 | htest.assertEqual(h3, out[0..]); | |
| 403 | try htest.assertEqual(h3, out[0..]); | |
| 404 | 404 | |
| 405 | 405 | h = Blake2s256.init(.{}); |
| 406 | 406 | h.update("a" ** 32 ++ "b" ** 32); |
| 407 | 407 | h.final(out[0..]); |
| 408 | htest.assertEqual(h3, out[0..]); | |
| 408 | try htest.assertEqual(h3, out[0..]); | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | test "blake2s256 keyed" { |
| ... | ... | @@ -415,20 +415,20 @@ test "blake2s256 keyed" { |
| 415 | 415 | const key = "secret_key"; |
| 416 | 416 | |
| 417 | 417 | Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); |
| 418 | htest.assertEqual(h1, out[0..]); | |
| 418 | try htest.assertEqual(h1, out[0..]); | |
| 419 | 419 | |
| 420 | 420 | var h = Blake2s256.init(.{ .key = key }); |
| 421 | 421 | h.update("a" ** 64 ++ "b" ** 64); |
| 422 | 422 | h.final(out[0..]); |
| 423 | 423 | |
| 424 | htest.assertEqual(h1, out[0..]); | |
| 424 | try htest.assertEqual(h1, out[0..]); | |
| 425 | 425 | |
| 426 | 426 | h = Blake2s256.init(.{ .key = key }); |
| 427 | 427 | h.update("a" ** 64); |
| 428 | 428 | h.update("b" ** 64); |
| 429 | 429 | h.final(out[0..]); |
| 430 | 430 | |
| 431 | htest.assertEqual(h1, out[0..]); | |
| 431 | try htest.assertEqual(h1, out[0..]); | |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | test "comptime blake2s256" { |
| ... | ... | @@ -439,13 +439,13 @@ test "comptime blake2s256" { |
| 439 | 439 | |
| 440 | 440 | const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3"; |
| 441 | 441 | |
| 442 | htest.assertEqualHash(Blake2s256, h1, block[0..]); | |
| 442 | try htest.assertEqualHash(Blake2s256, h1, block[0..]); | |
| 443 | 443 | |
| 444 | 444 | var h = Blake2s256.init(.{}); |
| 445 | 445 | h.update(&block); |
| 446 | 446 | h.final(out[0..]); |
| 447 | 447 | |
| 448 | htest.assertEqual(h1, out[0..]); | |
| 448 | try htest.assertEqual(h1, out[0..]); | |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
| ... | ... | @@ -617,16 +617,16 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 617 | 617 | |
| 618 | 618 | test "blake2b160 single" { |
| 619 | 619 | const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2"; |
| 620 | htest.assertEqualHash(Blake2b160, h1, ""); | |
| 620 | try htest.assertEqualHash(Blake2b160, h1, ""); | |
| 621 | 621 | |
| 622 | 622 | const h2 = "384264f676f39536840523f284921cdc68b6846b"; |
| 623 | htest.assertEqualHash(Blake2b160, h2, "abc"); | |
| 623 | try htest.assertEqualHash(Blake2b160, h2, "abc"); | |
| 624 | 624 | |
| 625 | 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"); | |
| 627 | 627 | |
| 628 | 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 | } |
| 631 | 631 | |
| 632 | 632 | test "blake2b160 streaming" { |
| ... | ... | @@ -636,40 +636,40 @@ test "blake2b160 streaming" { |
| 636 | 636 | const h1 = "3345524abf6bbe1809449224b5972c41790b6cf2"; |
| 637 | 637 | |
| 638 | 638 | h.final(out[0..]); |
| 639 | htest.assertEqual(h1, out[0..]); | |
| 639 | try htest.assertEqual(h1, out[0..]); | |
| 640 | 640 | |
| 641 | 641 | const h2 = "384264f676f39536840523f284921cdc68b6846b"; |
| 642 | 642 | |
| 643 | 643 | h = Blake2b160.init(.{}); |
| 644 | 644 | h.update("abc"); |
| 645 | 645 | h.final(out[0..]); |
| 646 | htest.assertEqual(h2, out[0..]); | |
| 646 | try htest.assertEqual(h2, out[0..]); | |
| 647 | 647 | |
| 648 | 648 | h = Blake2b160.init(.{}); |
| 649 | 649 | h.update("a"); |
| 650 | 650 | h.update("b"); |
| 651 | 651 | h.update("c"); |
| 652 | 652 | h.final(out[0..]); |
| 653 | htest.assertEqual(h2, out[0..]); | |
| 653 | try htest.assertEqual(h2, out[0..]); | |
| 654 | 654 | |
| 655 | 655 | const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; |
| 656 | 656 | |
| 657 | 657 | h = Blake2b160.init(.{}); |
| 658 | 658 | h.update("a" ** 64 ++ "b" ** 64); |
| 659 | 659 | h.final(out[0..]); |
| 660 | htest.assertEqual(h3, out[0..]); | |
| 660 | try htest.assertEqual(h3, out[0..]); | |
| 661 | 661 | |
| 662 | 662 | h = Blake2b160.init(.{}); |
| 663 | 663 | h.update("a" ** 64); |
| 664 | 664 | h.update("b" ** 64); |
| 665 | 665 | h.final(out[0..]); |
| 666 | htest.assertEqual(h3, out[0..]); | |
| 666 | try htest.assertEqual(h3, out[0..]); | |
| 667 | 667 | |
| 668 | 668 | h = Blake2b160.init(.{}); |
| 669 | 669 | h.update("a" ** 64); |
| 670 | 670 | h.update("b" ** 64); |
| 671 | 671 | h.final(out[0..]); |
| 672 | htest.assertEqual(h3, out[0..]); | |
| 672 | try htest.assertEqual(h3, out[0..]); | |
| 673 | 673 | |
| 674 | 674 | const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc"; |
| 675 | 675 | |
| ... | ... | @@ -677,13 +677,13 @@ test "blake2b160 streaming" { |
| 677 | 677 | h.update("a" ** 64); |
| 678 | 678 | h.update("b" ** 64); |
| 679 | 679 | h.final(out[0..]); |
| 680 | htest.assertEqual(h4, out[0..]); | |
| 680 | try htest.assertEqual(h4, out[0..]); | |
| 681 | 681 | |
| 682 | 682 | h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); |
| 683 | 683 | h.update("a" ** 64); |
| 684 | 684 | h.update("b" ** 64); |
| 685 | 685 | h.final(out[0..]); |
| 686 | htest.assertEqual(h4, out[0..]); | |
| 686 | try htest.assertEqual(h4, out[0..]); | |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | test "comptime blake2b160" { |
| ... | ... | @@ -694,28 +694,28 @@ test "comptime blake2b160" { |
| 694 | 694 | |
| 695 | 695 | const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9"; |
| 696 | 696 | |
| 697 | htest.assertEqualHash(Blake2b160, h1, block[0..]); | |
| 697 | try htest.assertEqualHash(Blake2b160, h1, block[0..]); | |
| 698 | 698 | |
| 699 | 699 | var h = Blake2b160.init(.{}); |
| 700 | 700 | h.update(&block); |
| 701 | 701 | h.final(out[0..]); |
| 702 | 702 | |
| 703 | htest.assertEqual(h1, out[0..]); | |
| 703 | try htest.assertEqual(h1, out[0..]); | |
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | test "blake2b384 single" { |
| 708 | 708 | const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100"; |
| 709 | htest.assertEqualHash(Blake2b384, h1, ""); | |
| 709 | try htest.assertEqualHash(Blake2b384, h1, ""); | |
| 710 | 710 | |
| 711 | 711 | const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4"; |
| 712 | htest.assertEqualHash(Blake2b384, h2, "abc"); | |
| 712 | try htest.assertEqualHash(Blake2b384, h2, "abc"); | |
| 713 | 713 | |
| 714 | 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"); | |
| 716 | 716 | |
| 717 | 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 | } |
| 720 | 720 | |
| 721 | 721 | test "blake2b384 streaming" { |
| ... | ... | @@ -725,40 +725,40 @@ test "blake2b384 streaming" { |
| 725 | 725 | const h1 = "b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100"; |
| 726 | 726 | |
| 727 | 727 | h.final(out[0..]); |
| 728 | htest.assertEqual(h1, out[0..]); | |
| 728 | try htest.assertEqual(h1, out[0..]); | |
| 729 | 729 | |
| 730 | 730 | const h2 = "6f56a82c8e7ef526dfe182eb5212f7db9df1317e57815dbda46083fc30f54ee6c66ba83be64b302d7cba6ce15bb556f4"; |
| 731 | 731 | |
| 732 | 732 | h = Blake2b384.init(.{}); |
| 733 | 733 | h.update("abc"); |
| 734 | 734 | h.final(out[0..]); |
| 735 | htest.assertEqual(h2, out[0..]); | |
| 735 | try htest.assertEqual(h2, out[0..]); | |
| 736 | 736 | |
| 737 | 737 | h = Blake2b384.init(.{}); |
| 738 | 738 | h.update("a"); |
| 739 | 739 | h.update("b"); |
| 740 | 740 | h.update("c"); |
| 741 | 741 | h.final(out[0..]); |
| 742 | htest.assertEqual(h2, out[0..]); | |
| 742 | try htest.assertEqual(h2, out[0..]); | |
| 743 | 743 | |
| 744 | 744 | const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; |
| 745 | 745 | |
| 746 | 746 | h = Blake2b384.init(.{}); |
| 747 | 747 | h.update("a" ** 64 ++ "b" ** 64); |
| 748 | 748 | h.final(out[0..]); |
| 749 | htest.assertEqual(h3, out[0..]); | |
| 749 | try htest.assertEqual(h3, out[0..]); | |
| 750 | 750 | |
| 751 | 751 | h = Blake2b384.init(.{}); |
| 752 | 752 | h.update("a" ** 64); |
| 753 | 753 | h.update("b" ** 64); |
| 754 | 754 | h.final(out[0..]); |
| 755 | htest.assertEqual(h3, out[0..]); | |
| 755 | try htest.assertEqual(h3, out[0..]); | |
| 756 | 756 | |
| 757 | 757 | h = Blake2b384.init(.{}); |
| 758 | 758 | h.update("a" ** 64); |
| 759 | 759 | h.update("b" ** 64); |
| 760 | 760 | h.final(out[0..]); |
| 761 | htest.assertEqual(h3, out[0..]); | |
| 761 | try htest.assertEqual(h3, out[0..]); | |
| 762 | 762 | |
| 763 | 763 | const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c"; |
| 764 | 764 | |
| ... | ... | @@ -766,13 +766,13 @@ test "blake2b384 streaming" { |
| 766 | 766 | h.update("a" ** 64); |
| 767 | 767 | h.update("b" ** 64); |
| 768 | 768 | h.final(out[0..]); |
| 769 | htest.assertEqual(h4, out[0..]); | |
| 769 | try htest.assertEqual(h4, out[0..]); | |
| 770 | 770 | |
| 771 | 771 | h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); |
| 772 | 772 | h.update("a" ** 64); |
| 773 | 773 | h.update("b" ** 64); |
| 774 | 774 | h.final(out[0..]); |
| 775 | htest.assertEqual(h4, out[0..]); | |
| 775 | try htest.assertEqual(h4, out[0..]); | |
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | test "comptime blake2b384" { |
| ... | ... | @@ -783,28 +783,28 @@ test "comptime blake2b384" { |
| 783 | 783 | |
| 784 | 784 | const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d"; |
| 785 | 785 | |
| 786 | htest.assertEqualHash(Blake2b384, h1, block[0..]); | |
| 786 | try htest.assertEqualHash(Blake2b384, h1, block[0..]); | |
| 787 | 787 | |
| 788 | 788 | var h = Blake2b384.init(.{}); |
| 789 | 789 | h.update(&block); |
| 790 | 790 | h.final(out[0..]); |
| 791 | 791 | |
| 792 | htest.assertEqual(h1, out[0..]); | |
| 792 | try htest.assertEqual(h1, out[0..]); | |
| 793 | 793 | } |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | test "blake2b512 single" { |
| 797 | 797 | const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce"; |
| 798 | htest.assertEqualHash(Blake2b512, h1, ""); | |
| 798 | try htest.assertEqualHash(Blake2b512, h1, ""); | |
| 799 | 799 | |
| 800 | 800 | const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"; |
| 801 | htest.assertEqualHash(Blake2b512, h2, "abc"); | |
| 801 | try htest.assertEqualHash(Blake2b512, h2, "abc"); | |
| 802 | 802 | |
| 803 | 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"); | |
| 805 | 805 | |
| 806 | 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 | } |
| 809 | 809 | |
| 810 | 810 | test "blake2b512 streaming" { |
| ... | ... | @@ -814,34 +814,34 @@ test "blake2b512 streaming" { |
| 814 | 814 | const h1 = "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce"; |
| 815 | 815 | |
| 816 | 816 | h.final(out[0..]); |
| 817 | htest.assertEqual(h1, out[0..]); | |
| 817 | try htest.assertEqual(h1, out[0..]); | |
| 818 | 818 | |
| 819 | 819 | const h2 = "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"; |
| 820 | 820 | |
| 821 | 821 | h = Blake2b512.init(.{}); |
| 822 | 822 | h.update("abc"); |
| 823 | 823 | h.final(out[0..]); |
| 824 | htest.assertEqual(h2, out[0..]); | |
| 824 | try htest.assertEqual(h2, out[0..]); | |
| 825 | 825 | |
| 826 | 826 | h = Blake2b512.init(.{}); |
| 827 | 827 | h.update("a"); |
| 828 | 828 | h.update("b"); |
| 829 | 829 | h.update("c"); |
| 830 | 830 | h.final(out[0..]); |
| 831 | htest.assertEqual(h2, out[0..]); | |
| 831 | try htest.assertEqual(h2, out[0..]); | |
| 832 | 832 | |
| 833 | 833 | const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; |
| 834 | 834 | |
| 835 | 835 | h = Blake2b512.init(.{}); |
| 836 | 836 | h.update("a" ** 64 ++ "b" ** 64); |
| 837 | 837 | h.final(out[0..]); |
| 838 | htest.assertEqual(h3, out[0..]); | |
| 838 | try htest.assertEqual(h3, out[0..]); | |
| 839 | 839 | |
| 840 | 840 | h = Blake2b512.init(.{}); |
| 841 | 841 | h.update("a" ** 64); |
| 842 | 842 | h.update("b" ** 64); |
| 843 | 843 | h.final(out[0..]); |
| 844 | htest.assertEqual(h3, out[0..]); | |
| 844 | try htest.assertEqual(h3, out[0..]); | |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | test "blake2b512 keyed" { |
| ... | ... | @@ -851,20 +851,20 @@ test "blake2b512 keyed" { |
| 851 | 851 | const key = "secret_key"; |
| 852 | 852 | |
| 853 | 853 | Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); |
| 854 | htest.assertEqual(h1, out[0..]); | |
| 854 | try htest.assertEqual(h1, out[0..]); | |
| 855 | 855 | |
| 856 | 856 | var h = Blake2b512.init(.{ .key = key }); |
| 857 | 857 | h.update("a" ** 64 ++ "b" ** 64); |
| 858 | 858 | h.final(out[0..]); |
| 859 | 859 | |
| 860 | htest.assertEqual(h1, out[0..]); | |
| 860 | try htest.assertEqual(h1, out[0..]); | |
| 861 | 861 | |
| 862 | 862 | h = Blake2b512.init(.{ .key = key }); |
| 863 | 863 | h.update("a" ** 64); |
| 864 | 864 | h.update("b" ** 64); |
| 865 | 865 | h.final(out[0..]); |
| 866 | 866 | |
| 867 | htest.assertEqual(h1, out[0..]); | |
| 867 | try htest.assertEqual(h1, out[0..]); | |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | test "comptime blake2b512" { |
| ... | ... | @@ -875,12 +875,12 @@ test "comptime blake2b512" { |
| 875 | 875 | |
| 876 | 876 | const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41"; |
| 877 | 877 | |
| 878 | htest.assertEqualHash(Blake2b512, h1, block[0..]); | |
| 878 | try htest.assertEqualHash(Blake2b512, h1, block[0..]); | |
| 879 | 879 | |
| 880 | 880 | var h = Blake2b512.init(.{}); |
| 881 | 881 | h.update(&block); |
| 882 | 882 | h.final(out[0..]); |
| 883 | 883 | |
| 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 | 641 | }, |
| 642 | 642 | }; |
| 643 | 643 | |
| 644 | fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void { | |
| 644 | fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void { | |
| 645 | 645 | // Save initial state |
| 646 | 646 | const initial_state = hasher.*; |
| 647 | 647 | |
| ... | ... | @@ -664,7 +664,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) void { |
| 664 | 664 | // Compare to expected value |
| 665 | 665 | var expected_bytes: [expected_hex.len / 2]u8 = undefined; |
| 666 | 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); | |
| 668 | 668 | |
| 669 | 669 | // Restore initial state |
| 670 | 670 | hasher.* = initial_state; |
| ... | ... | @@ -676,8 +676,8 @@ test "BLAKE3 reference test cases" { |
| 676 | 676 | var derive_key = &Blake3.initKdf(reference_test.context_string, .{}); |
| 677 | 677 | |
| 678 | 678 | for (reference_test.cases) |t| { |
| 679 | testBlake3(hash, t.input_len, t.hash.*); | |
| 680 | testBlake3(keyed_hash, t.input_len, t.keyed_hash.*); | |
| 681 | testBlake3(derive_key, t.input_len, t.derive_key.*); | |
| 679 | try testBlake3(hash, t.input_len, t.hash.*); | |
| 680 | try testBlake3(keyed_hash, t.input_len, t.keyed_hash.*); | |
| 681 | try testBlake3(derive_key, t.input_len, t.derive_key.*); | |
| 682 | 682 | } |
| 683 | 683 | } |
lib/std/crypto/chacha20.zig+21-21| ... | ... | @@ -604,9 +604,9 @@ test "chacha20 AEAD API" { |
| 604 | 604 | |
| 605 | 605 | aead.encrypt(c[0..], tag[0..], m, ad, nonce, key); |
| 606 | 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 | 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 | } |
| 612 | 612 | |
| ... | ... | @@ -644,11 +644,11 @@ test "crypto.chacha20 test vector sunscreen" { |
| 644 | 644 | }; |
| 645 | 645 | |
| 646 | 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); | |
| 648 | 648 | |
| 649 | 649 | var m2: [114]u8 = undefined; |
| 650 | 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 | } |
| 653 | 653 | |
| 654 | 654 | // https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7 |
| ... | ... | @@ -683,7 +683,7 @@ test "crypto.chacha20 test vector 1" { |
| 683 | 683 | const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 684 | 684 | |
| 685 | 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 | } |
| 688 | 688 | |
| 689 | 689 | test "crypto.chacha20 test vector 2" { |
| ... | ... | @@ -717,7 +717,7 @@ test "crypto.chacha20 test vector 2" { |
| 717 | 717 | const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 718 | 718 | |
| 719 | 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 | } |
| 722 | 722 | |
| 723 | 723 | test "crypto.chacha20 test vector 3" { |
| ... | ... | @@ -751,7 +751,7 @@ test "crypto.chacha20 test vector 3" { |
| 751 | 751 | const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 }; |
| 752 | 752 | |
| 753 | 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 | } |
| 756 | 756 | |
| 757 | 757 | test "crypto.chacha20 test vector 4" { |
| ... | ... | @@ -785,7 +785,7 @@ test "crypto.chacha20 test vector 4" { |
| 785 | 785 | const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 }; |
| 786 | 786 | |
| 787 | 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 | } |
| 790 | 790 | |
| 791 | 791 | test "crypto.chacha20 test vector 5" { |
| ... | ... | @@ -857,7 +857,7 @@ test "crypto.chacha20 test vector 5" { |
| 857 | 857 | }; |
| 858 | 858 | |
| 859 | 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 | } |
| 862 | 862 | |
| 863 | 863 | test "seal" { |
| ... | ... | @@ -873,7 +873,7 @@ test "seal" { |
| 873 | 873 | |
| 874 | 874 | var out: [exp_out.len]u8 = undefined; |
| 875 | 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 | 879 | const m = [_]u8{ |
| ... | ... | @@ -906,7 +906,7 @@ test "seal" { |
| 906 | 906 | |
| 907 | 907 | var out: [exp_out.len]u8 = undefined; |
| 908 | 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 | } |
| 912 | 912 | |
| ... | ... | @@ -923,7 +923,7 @@ test "open" { |
| 923 | 923 | |
| 924 | 924 | var out: [exp_out.len]u8 = undefined; |
| 925 | 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 | 929 | const c = [_]u8{ |
| ... | ... | @@ -956,21 +956,21 @@ test "open" { |
| 956 | 956 | |
| 957 | 957 | var out: [exp_out.len]u8 = undefined; |
| 958 | 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..]); | |
| 960 | 960 | |
| 961 | 961 | // corrupting the ciphertext, data, key, or nonce should cause a failure |
| 962 | 962 | var bad_c = c; |
| 963 | 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 | 965 | var bad_ad = ad; |
| 966 | 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 | 968 | var bad_key = key; |
| 969 | 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 | 971 | var bad_nonce = nonce; |
| 972 | 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 | } |
| 976 | 976 | |
| ... | ... | @@ -982,7 +982,7 @@ test "crypto.xchacha20" { |
| 982 | 982 | var c: [m.len]u8 = undefined; |
| 983 | 983 | XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce); |
| 984 | 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 | 988 | const ad = "Additional data"; |
| ... | ... | @@ -991,9 +991,9 @@ test "crypto.xchacha20" { |
| 991 | 991 | var out: [m.len]u8 = undefined; |
| 992 | 992 | try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key); |
| 993 | 993 | var buf: [2 * c.len]u8 = undefined; |
| 994 | testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234"); | |
| 995 | testing.expectEqualSlices(u8, out[0..], m); | |
| 994 | try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&c)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234"); | |
| 995 | try testing.expectEqualSlices(u8, out[0..], m); | |
| 996 | 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 | 326 | st.update(&m); |
| 327 | 327 | var out: [16]u8 = undefined; |
| 328 | 328 | st.final(&out); |
| 329 | htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out); | |
| 329 | try htest.assertEqual("889295fa746e8b174bf4ec80a65dea41", &out); | |
| 330 | 330 | |
| 331 | 331 | st = Ghash.init(&key); |
| 332 | 332 | st.update(m[0..100]); |
| 333 | 333 | st.update(m[100..]); |
| 334 | 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 | 205 | while (i < 12) : (i += 1) { |
| 206 | 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 | } |
| 210 | 210 | |
| 211 | 211 | pub const Hash = struct { |
| ... | ... | @@ -274,7 +274,7 @@ test "hash" { |
| 274 | 274 | _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C"); |
| 275 | 275 | var md: [32]u8 = undefined; |
| 276 | 276 | hash(&md, &msg, .{}); |
| 277 | htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md); | |
| 277 | try htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md); | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | test "hash test vector 17" { |
| ... | ... | @@ -282,7 +282,7 @@ test "hash test vector 17" { |
| 282 | 282 | _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F"); |
| 283 | 283 | var md: [32]u8 = undefined; |
| 284 | 284 | hash(&md, &msg, .{}); |
| 285 | htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md); | |
| 285 | try htest.assertEqual("404C130AF1B9023A7908200919F690FFBB756D5176E056FFDE320016A37C7282", &md); | |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | test "hash test vector 33" { |
| ... | ... | @@ -290,7 +290,7 @@ test "hash test vector 33" { |
| 290 | 290 | _ = try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); |
| 291 | 291 | var md: [32]u8 = undefined; |
| 292 | 292 | hash(&md, &msg, .{}); |
| 293 | htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md); | |
| 293 | try htest.assertEqual("A8F4FA28708BDA7EFB4C1914CA4AFA9E475B82D588D36504F87DBB0ED9AB3C4B", &md); | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | pub const Aead = struct { |
| ... | ... | @@ -447,12 +447,12 @@ test "cipher" { |
| 447 | 447 | var ct: [pt.len]u8 = undefined; |
| 448 | 448 | var tag: [16]u8 = undefined; |
| 449 | 449 | Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key); |
| 450 | htest.assertEqual("", &ct); | |
| 451 | htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag); | |
| 450 | try htest.assertEqual("", &ct); | |
| 451 | try htest.assertEqual("14DA9BB7120BF58B985A8E00FDEBA15B", &tag); | |
| 452 | 452 | |
| 453 | 453 | var pt2: [pt.len]u8 = undefined; |
| 454 | 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 | 457 | { // test vector (34) from NIST KAT submission. |
| 458 | 458 | const ad: [0]u8 = undefined; |
| ... | ... | @@ -462,12 +462,12 @@ test "cipher" { |
| 462 | 462 | var ct: [pt.len]u8 = undefined; |
| 463 | 463 | var tag: [16]u8 = undefined; |
| 464 | 464 | Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key); |
| 465 | htest.assertEqual("7F", &ct); | |
| 466 | htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag); | |
| 465 | try htest.assertEqual("7F", &ct); | |
| 466 | try htest.assertEqual("80492C317B1CD58A1EDC3A0D3E9876FC", &tag); | |
| 467 | 467 | |
| 468 | 468 | var pt2: [pt.len]u8 = undefined; |
| 469 | 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 | 472 | { // test vector (106) from NIST KAT submission. |
| 473 | 473 | var ad: [12 / 2]u8 = undefined; |
| ... | ... | @@ -478,12 +478,12 @@ test "cipher" { |
| 478 | 478 | var ct: [pt.len]u8 = undefined; |
| 479 | 479 | var tag: [16]u8 = undefined; |
| 480 | 480 | Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key); |
| 481 | htest.assertEqual("484D35", &ct); | |
| 482 | htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag); | |
| 481 | try htest.assertEqual("484D35", &ct); | |
| 482 | try htest.assertEqual("030BBEA23B61C00CED60A923BDCF9147", &tag); | |
| 483 | 483 | |
| 484 | 484 | var pt2: [pt.len]u8 = undefined; |
| 485 | 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 | 488 | { // test vector (790) from NIST KAT submission. |
| 489 | 489 | var ad: [60 / 2]u8 = undefined; |
| ... | ... | @@ -494,12 +494,12 @@ test "cipher" { |
| 494 | 494 | var ct: [pt.len]u8 = undefined; |
| 495 | 495 | var tag: [16]u8 = undefined; |
| 496 | 496 | Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key); |
| 497 | htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct); | |
| 498 | htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag); | |
| 497 | try htest.assertEqual("6815B4A0ECDAD01596EAD87D9E690697475D234C6A13D1", &ct); | |
| 498 | try htest.assertEqual("DFE23F1642508290D68245279558B2FB", &tag); | |
| 499 | 499 | |
| 500 | 500 | var pt2: [pt.len]u8 = undefined; |
| 501 | 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 | 504 | { // test vector (1057) from NIST KAT submission. |
| 505 | 505 | const ad: [0]u8 = undefined; |
| ... | ... | @@ -509,11 +509,11 @@ test "cipher" { |
| 509 | 509 | var ct: [pt.len]u8 = undefined; |
| 510 | 510 | var tag: [16]u8 = undefined; |
| 511 | 511 | Aead.encrypt(&ct, &tag, &pt, &ad, nonce, key); |
| 512 | htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct); | |
| 513 | htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag); | |
| 512 | try htest.assertEqual("7F8A2CF4F52AA4D6B2E74105C30A2777B9D0C8AEFDD555DE35861BD3011F652F", &ct); | |
| 513 | try htest.assertEqual("7256456FA935AC34BBF55AE135F33257", &tag); | |
| 514 | 514 | |
| 515 | 515 | var pt2: [pt.len]u8 = undefined; |
| 516 | 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 | 65 | const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; |
| 66 | 66 | const kdf = HkdfSha256; |
| 67 | 67 | const prk = kdf.extract(&salt, &ikm); |
| 68 | htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk); | |
| 68 | try htest.assertEqual("077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5", &prk); | |
| 69 | 69 | var out: [42]u8 = undefined; |
| 70 | 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 | 84 | test "hmac md5" { |
| 85 | 85 | var out: [HmacMd5.mac_length]u8 = undefined; |
| 86 | 86 | HmacMd5.create(out[0..], "", ""); |
| 87 | htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]); | |
| 87 | try htest.assertEqual("74e6f7298a9c2d168935f58c001bad88", out[0..]); | |
| 88 | 88 | |
| 89 | 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 | } |
| 92 | 92 | |
| 93 | 93 | test "hmac sha1" { |
| 94 | 94 | var out: [HmacSha1.mac_length]u8 = undefined; |
| 95 | 95 | HmacSha1.create(out[0..], "", ""); |
| 96 | htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]); | |
| 96 | try htest.assertEqual("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", out[0..]); | |
| 97 | 97 | |
| 98 | 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 | } |
| 101 | 101 | |
| 102 | 102 | test "hmac sha256" { |
| 103 | 103 | var out: [sha2.HmacSha256.mac_length]u8 = undefined; |
| 104 | 104 | sha2.HmacSha256.create(out[0..], "", ""); |
| 105 | htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]); | |
| 105 | try htest.assertEqual("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", out[0..]); | |
| 106 | 106 | |
| 107 | 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 | 240 | var msg = "test"; |
| 241 | 241 | var c: [msg.len]u8 = undefined; |
| 242 | 242 | IsapA128A.encrypt(c[0..], &tag, msg[0..], ad, n, k); |
| 243 | testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..])); | |
| 244 | testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..])); | |
| 243 | try testing.expect(mem.eql(u8, &[_]u8{ 0x8f, 0x68, 0x03, 0x8d }, c[0..])); | |
| 244 | try testing.expect(mem.eql(u8, &[_]u8{ 0x6c, 0x25, 0xe8, 0xe2, 0xe1, 0x1f, 0x38, 0xe9, 0x80, 0x75, 0xde, 0xd5, 0x2d, 0xb2, 0x31, 0x82 }, tag[0..])); | |
| 245 | 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 | 241 | const htest = @import("test.zig"); |
| 242 | 242 | |
| 243 | 243 | test "md5 single" { |
| 244 | htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", ""); | |
| 245 | htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a"); | |
| 246 | htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc"); | |
| 247 | htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest"); | |
| 248 | htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz"); | |
| 249 | htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); | |
| 250 | htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); | |
| 244 | try htest.assertEqualHash(Md5, "d41d8cd98f00b204e9800998ecf8427e", ""); | |
| 245 | try htest.assertEqualHash(Md5, "0cc175b9c0f1b6a831c399e269772661", "a"); | |
| 246 | try htest.assertEqualHash(Md5, "900150983cd24fb0d6963f7d28e17f72", "abc"); | |
| 247 | try htest.assertEqualHash(Md5, "f96b697d7cb7938d525a2f31aaf161d0", "message digest"); | |
| 248 | try htest.assertEqualHash(Md5, "c3fcd3d76192e4007dfb496cca67e13b", "abcdefghijklmnopqrstuvwxyz"); | |
| 249 | try htest.assertEqualHash(Md5, "d174ab98d277d9f5a5611c2c9f419d9f", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); | |
| 250 | try htest.assertEqualHash(Md5, "57edf4a22be3c955ac49da2e2107b67a", "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | test "md5 streaming" { |
| ... | ... | @@ -255,12 +255,12 @@ test "md5 streaming" { |
| 255 | 255 | var out: [16]u8 = undefined; |
| 256 | 256 | |
| 257 | 257 | h.final(out[0..]); |
| 258 | htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]); | |
| 258 | try htest.assertEqual("d41d8cd98f00b204e9800998ecf8427e", out[0..]); | |
| 259 | 259 | |
| 260 | 260 | h = Md5.init(.{}); |
| 261 | 261 | h.update("abc"); |
| 262 | 262 | h.final(out[0..]); |
| 263 | htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]); | |
| 263 | try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]); | |
| 264 | 264 | |
| 265 | 265 | h = Md5.init(.{}); |
| 266 | 266 | h.update("a"); |
| ... | ... | @@ -268,7 +268,7 @@ test "md5 streaming" { |
| 268 | 268 | h.update("c"); |
| 269 | 269 | h.final(out[0..]); |
| 270 | 270 | |
| 271 | htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]); | |
| 271 | try htest.assertEqual("900150983cd24fb0d6963f7d28e17f72", out[0..]); | |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | test "md5 aligned final" { |
lib/std/crypto/pbkdf2.zig+6-6| ... | ... | @@ -168,7 +168,7 @@ test "RFC 6070 one iteration" { |
| 168 | 168 | |
| 169 | 169 | const expected = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; |
| 170 | 170 | |
| 171 | htest.assertEqual(expected, dk[0..]); | |
| 171 | try htest.assertEqual(expected, dk[0..]); | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | test "RFC 6070 two iterations" { |
| ... | ... | @@ -183,7 +183,7 @@ test "RFC 6070 two iterations" { |
| 183 | 183 | |
| 184 | 184 | const expected = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; |
| 185 | 185 | |
| 186 | htest.assertEqual(expected, dk[0..]); | |
| 186 | try htest.assertEqual(expected, dk[0..]); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "RFC 6070 4096 iterations" { |
| ... | ... | @@ -198,7 +198,7 @@ test "RFC 6070 4096 iterations" { |
| 198 | 198 | |
| 199 | 199 | const expected = "4b007901b765489abead49d926f721d065a429c1"; |
| 200 | 200 | |
| 201 | htest.assertEqual(expected, dk[0..]); | |
| 201 | try htest.assertEqual(expected, dk[0..]); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "RFC 6070 16,777,216 iterations" { |
| ... | ... | @@ -218,7 +218,7 @@ test "RFC 6070 16,777,216 iterations" { |
| 218 | 218 | |
| 219 | 219 | const expected = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; |
| 220 | 220 | |
| 221 | htest.assertEqual(expected, dk[0..]); | |
| 221 | try htest.assertEqual(expected, dk[0..]); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | test "RFC 6070 multi-block salt and password" { |
| ... | ... | @@ -233,7 +233,7 @@ test "RFC 6070 multi-block salt and password" { |
| 233 | 233 | |
| 234 | 234 | const expected = "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038"; |
| 235 | 235 | |
| 236 | htest.assertEqual(expected, dk[0..]); | |
| 236 | try htest.assertEqual(expected, dk[0..]); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | test "RFC 6070 embedded NUL" { |
| ... | ... | @@ -248,7 +248,7 @@ test "RFC 6070 embedded NUL" { |
| 248 | 248 | |
| 249 | 249 | const expected = "56fa6aa75548099dcc37d7f03425e0c3"; |
| 250 | 250 | |
| 251 | htest.assertEqual(expected, dk[0..]); | |
| 251 | try htest.assertEqual(expected, dk[0..]); | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | test "Very large dk_len" { |
lib/std/crypto/pcurves/tests.zig+9-9| ... | ... | @@ -17,7 +17,7 @@ test "p256 ECDH key exchange" { |
| 17 | 17 | const dhB = try P256.basePoint.mul(dhb, .Little); |
| 18 | 18 | const shareda = try dhA.mul(dhb, .Little); |
| 19 | 19 | const sharedb = try dhB.mul(dha, .Little); |
| 20 | testing.expect(shareda.equivalent(sharedb)); | |
| 20 | try testing.expect(shareda.equivalent(sharedb)); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "p256 point from affine coordinates" { |
| ... | ... | @@ -28,7 +28,7 @@ test "p256 point from affine coordinates" { |
| 28 | 28 | var ys: [32]u8 = undefined; |
| 29 | 29 | _ = try fmt.hexToBytes(&ys, yh); |
| 30 | 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 | } |
| 33 | 33 | |
| 34 | 34 | test "p256 test vectors" { |
| ... | ... | @@ -50,7 +50,7 @@ test "p256 test vectors" { |
| 50 | 50 | p = p.add(P256.basePoint); |
| 51 | 51 | var xs: [32]u8 = undefined; |
| 52 | 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 | } |
| 56 | 56 | |
| ... | ... | @@ -67,7 +67,7 @@ test "p256 test vectors - doubling" { |
| 67 | 67 | p = p.dbl(); |
| 68 | 68 | var xs: [32]u8 = undefined; |
| 69 | 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 | } |
| 73 | 73 | |
| ... | ... | @@ -75,29 +75,29 @@ test "p256 compressed sec1 encoding/decoding" { |
| 75 | 75 | const p = P256.random(); |
| 76 | 76 | const s = p.toCompressedSec1(); |
| 77 | 77 | const q = try P256.fromSec1(&s); |
| 78 | testing.expect(p.equivalent(q)); | |
| 78 | try testing.expect(p.equivalent(q)); | |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | test "p256 uncompressed sec1 encoding/decoding" { |
| 82 | 82 | const p = P256.random(); |
| 83 | 83 | const s = p.toUncompressedSec1(); |
| 84 | 84 | const q = try P256.fromSec1(&s); |
| 85 | testing.expect(p.equivalent(q)); | |
| 85 | try testing.expect(p.equivalent(q)); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | test "p256 public key is the neutral element" { |
| 89 | 89 | const n = P256.scalar.Scalar.zero.toBytes(.Little); |
| 90 | 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 | } |
| 93 | 93 | |
| 94 | 94 | test "p256 public key is the neutral element (public verification)" { |
| 95 | 95 | const n = P256.scalar.Scalar.zero.toBytes(.Little); |
| 96 | 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 | } |
| 99 | 99 | |
| 100 | 100 | test "p256 field element non-canonical encoding" { |
| 101 | 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 | 216 | var mac: [16]u8 = undefined; |
| 217 | 217 | Poly1305.create(mac[0..], msg, key); |
| 218 | 218 | |
| 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 | 561 | var c: [msg.len]u8 = undefined; |
| 562 | 562 | |
| 563 | 563 | Salsa20.xor(&c, msg[0..], 0, key, nonce); |
| 564 | htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); | |
| 564 | try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); | |
| 565 | 565 | |
| 566 | 566 | const extended_nonce = [_]u8{0x42} ** 24; |
| 567 | 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 | } |
| 570 | 570 | |
| 571 | 571 | test "xsalsa20poly1305" { |
| ... | ... | @@ -628,5 +628,5 @@ test "secretbox twoblocks" { |
| 628 | 628 | const msg = [_]u8{'a'} ** 97; |
| 629 | 629 | var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined; |
| 630 | 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 | 265 | const htest = @import("test.zig"); |
| 266 | 266 | |
| 267 | 267 | test "sha1 single" { |
| 268 | htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", ""); | |
| 269 | htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc"); | |
| 270 | htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 268 | try htest.assertEqualHash(Sha1, "da39a3ee5e6b4b0d3255bfef95601890afd80709", ""); | |
| 269 | try htest.assertEqualHash(Sha1, "a9993e364706816aba3e25717850c26c9cd0d89d", "abc"); | |
| 270 | try htest.assertEqualHash(Sha1, "a49b2446a02c645bf419f995b67091253a04a259", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | test "sha1 streaming" { |
| ... | ... | @@ -275,19 +275,19 @@ test "sha1 streaming" { |
| 275 | 275 | var out: [20]u8 = undefined; |
| 276 | 276 | |
| 277 | 277 | h.final(&out); |
| 278 | htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]); | |
| 278 | try htest.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", out[0..]); | |
| 279 | 279 | |
| 280 | 280 | h = Sha1.init(.{}); |
| 281 | 281 | h.update("abc"); |
| 282 | 282 | h.final(&out); |
| 283 | htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]); | |
| 283 | try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]); | |
| 284 | 284 | |
| 285 | 285 | h = Sha1.init(.{}); |
| 286 | 286 | h.update("a"); |
| 287 | 287 | h.update("b"); |
| 288 | 288 | h.update("c"); |
| 289 | 289 | h.final(&out); |
| 290 | htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]); | |
| 290 | try htest.assertEqual("a9993e364706816aba3e25717850c26c9cd0d89d", out[0..]); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | test "sha1 aligned final" { |
lib/std/crypto/sha2.zig+24-24| ... | ... | @@ -285,9 +285,9 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | test "sha224 single" { |
| 288 | htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", ""); | |
| 289 | htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc"); | |
| 290 | htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 288 | try htest.assertEqualHash(Sha224, "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", ""); | |
| 289 | try htest.assertEqualHash(Sha224, "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", "abc"); | |
| 290 | try htest.assertEqualHash(Sha224, "c97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | test "sha224 streaming" { |
| ... | ... | @@ -295,25 +295,25 @@ test "sha224 streaming" { |
| 295 | 295 | var out: [28]u8 = undefined; |
| 296 | 296 | |
| 297 | 297 | h.final(out[0..]); |
| 298 | htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]); | |
| 298 | try htest.assertEqual("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", out[0..]); | |
| 299 | 299 | |
| 300 | 300 | h = Sha224.init(.{}); |
| 301 | 301 | h.update("abc"); |
| 302 | 302 | h.final(out[0..]); |
| 303 | htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]); | |
| 303 | try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]); | |
| 304 | 304 | |
| 305 | 305 | h = Sha224.init(.{}); |
| 306 | 306 | h.update("a"); |
| 307 | 307 | h.update("b"); |
| 308 | 308 | h.update("c"); |
| 309 | 309 | h.final(out[0..]); |
| 310 | htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]); | |
| 310 | try htest.assertEqual("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", out[0..]); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | test "sha256 single" { |
| 314 | htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""); | |
| 315 | htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc"); | |
| 316 | htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 314 | try htest.assertEqualHash(Sha256, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""); | |
| 315 | try htest.assertEqualHash(Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc"); | |
| 316 | try htest.assertEqualHash(Sha256, "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | test "sha256 streaming" { |
| ... | ... | @@ -321,19 +321,19 @@ test "sha256 streaming" { |
| 321 | 321 | var out: [32]u8 = undefined; |
| 322 | 322 | |
| 323 | 323 | h.final(out[0..]); |
| 324 | htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]); | |
| 324 | try htest.assertEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", out[0..]); | |
| 325 | 325 | |
| 326 | 326 | h = Sha256.init(.{}); |
| 327 | 327 | h.update("abc"); |
| 328 | 328 | h.final(out[0..]); |
| 329 | htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]); | |
| 329 | try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]); | |
| 330 | 330 | |
| 331 | 331 | h = Sha256.init(.{}); |
| 332 | 332 | h.update("a"); |
| 333 | 333 | h.update("b"); |
| 334 | 334 | h.update("c"); |
| 335 | 335 | h.final(out[0..]); |
| 336 | htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]); | |
| 336 | try htest.assertEqual("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", out[0..]); | |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | test "sha256 aligned final" { |
| ... | ... | @@ -675,13 +675,13 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 675 | 675 | |
| 676 | 676 | test "sha384 single" { |
| 677 | 677 | const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"; |
| 678 | htest.assertEqualHash(Sha384, h1, ""); | |
| 678 | try htest.assertEqualHash(Sha384, h1, ""); | |
| 679 | 679 | |
| 680 | 680 | const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"; |
| 681 | htest.assertEqualHash(Sha384, h2, "abc"); | |
| 681 | try htest.assertEqualHash(Sha384, h2, "abc"); | |
| 682 | 682 | |
| 683 | 683 | const h3 = "09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039"; |
| 684 | htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 684 | try htest.assertEqualHash(Sha384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | test "sha384 streaming" { |
| ... | ... | @@ -690,32 +690,32 @@ test "sha384 streaming" { |
| 690 | 690 | |
| 691 | 691 | const h1 = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"; |
| 692 | 692 | h.final(out[0..]); |
| 693 | htest.assertEqual(h1, out[0..]); | |
| 693 | try htest.assertEqual(h1, out[0..]); | |
| 694 | 694 | |
| 695 | 695 | const h2 = "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7"; |
| 696 | 696 | |
| 697 | 697 | h = Sha384.init(.{}); |
| 698 | 698 | h.update("abc"); |
| 699 | 699 | h.final(out[0..]); |
| 700 | htest.assertEqual(h2, out[0..]); | |
| 700 | try htest.assertEqual(h2, out[0..]); | |
| 701 | 701 | |
| 702 | 702 | h = Sha384.init(.{}); |
| 703 | 703 | h.update("a"); |
| 704 | 704 | h.update("b"); |
| 705 | 705 | h.update("c"); |
| 706 | 706 | h.final(out[0..]); |
| 707 | htest.assertEqual(h2, out[0..]); | |
| 707 | try htest.assertEqual(h2, out[0..]); | |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | test "sha512 single" { |
| 711 | 711 | const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; |
| 712 | htest.assertEqualHash(Sha512, h1, ""); | |
| 712 | try htest.assertEqualHash(Sha512, h1, ""); | |
| 713 | 713 | |
| 714 | 714 | const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"; |
| 715 | htest.assertEqualHash(Sha512, h2, "abc"); | |
| 715 | try htest.assertEqualHash(Sha512, h2, "abc"); | |
| 716 | 716 | |
| 717 | 717 | const h3 = "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"; |
| 718 | htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 718 | try htest.assertEqualHash(Sha512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | test "sha512 streaming" { |
| ... | ... | @@ -724,21 +724,21 @@ test "sha512 streaming" { |
| 724 | 724 | |
| 725 | 725 | const h1 = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"; |
| 726 | 726 | h.final(out[0..]); |
| 727 | htest.assertEqual(h1, out[0..]); | |
| 727 | try htest.assertEqual(h1, out[0..]); | |
| 728 | 728 | |
| 729 | 729 | const h2 = "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"; |
| 730 | 730 | |
| 731 | 731 | h = Sha512.init(.{}); |
| 732 | 732 | h.update("abc"); |
| 733 | 733 | h.final(out[0..]); |
| 734 | htest.assertEqual(h2, out[0..]); | |
| 734 | try htest.assertEqual(h2, out[0..]); | |
| 735 | 735 | |
| 736 | 736 | h = Sha512.init(.{}); |
| 737 | 737 | h.update("a"); |
| 738 | 738 | h.update("b"); |
| 739 | 739 | h.update("c"); |
| 740 | 740 | h.final(out[0..]); |
| 741 | htest.assertEqual(h2, out[0..]); | |
| 741 | try htest.assertEqual(h2, out[0..]); | |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | test "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 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "sha3-224 single" { |
| 172 | htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", ""); | |
| 173 | htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc"); | |
| 174 | htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 172 | try htest.assertEqualHash(Sha3_224, "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", ""); | |
| 173 | try htest.assertEqualHash(Sha3_224, "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", "abc"); | |
| 174 | try htest.assertEqualHash(Sha3_224, "543e6868e1666c1a643630df77367ae5a62a85070a51c14cbf665cbc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "sha3-224 streaming" { |
| ... | ... | @@ -179,25 +179,25 @@ test "sha3-224 streaming" { |
| 179 | 179 | var out: [28]u8 = undefined; |
| 180 | 180 | |
| 181 | 181 | h.final(out[0..]); |
| 182 | htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]); | |
| 182 | try htest.assertEqual("6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7", out[0..]); | |
| 183 | 183 | |
| 184 | 184 | h = Sha3_224.init(.{}); |
| 185 | 185 | h.update("abc"); |
| 186 | 186 | h.final(out[0..]); |
| 187 | htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]); | |
| 187 | try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]); | |
| 188 | 188 | |
| 189 | 189 | h = Sha3_224.init(.{}); |
| 190 | 190 | h.update("a"); |
| 191 | 191 | h.update("b"); |
| 192 | 192 | h.update("c"); |
| 193 | 193 | h.final(out[0..]); |
| 194 | htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]); | |
| 194 | try htest.assertEqual("e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf", out[0..]); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | test "sha3-256 single" { |
| 198 | htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", ""); | |
| 199 | htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc"); | |
| 200 | htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 198 | try htest.assertEqualHash(Sha3_256, "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", ""); | |
| 199 | try htest.assertEqualHash(Sha3_256, "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", "abc"); | |
| 200 | try htest.assertEqualHash(Sha3_256, "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | test "sha3-256 streaming" { |
| ... | ... | @@ -205,19 +205,19 @@ test "sha3-256 streaming" { |
| 205 | 205 | var out: [32]u8 = undefined; |
| 206 | 206 | |
| 207 | 207 | h.final(out[0..]); |
| 208 | htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]); | |
| 208 | try htest.assertEqual("a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a", out[0..]); | |
| 209 | 209 | |
| 210 | 210 | h = Sha3_256.init(.{}); |
| 211 | 211 | h.update("abc"); |
| 212 | 212 | h.final(out[0..]); |
| 213 | htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]); | |
| 213 | try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]); | |
| 214 | 214 | |
| 215 | 215 | h = Sha3_256.init(.{}); |
| 216 | 216 | h.update("a"); |
| 217 | 217 | h.update("b"); |
| 218 | 218 | h.update("c"); |
| 219 | 219 | h.final(out[0..]); |
| 220 | htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]); | |
| 220 | try htest.assertEqual("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532", out[0..]); | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | test "sha3-256 aligned final" { |
| ... | ... | @@ -231,11 +231,11 @@ test "sha3-256 aligned final" { |
| 231 | 231 | |
| 232 | 232 | test "sha3-384 single" { |
| 233 | 233 | const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004"; |
| 234 | htest.assertEqualHash(Sha3_384, h1, ""); | |
| 234 | try htest.assertEqualHash(Sha3_384, h1, ""); | |
| 235 | 235 | const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25"; |
| 236 | htest.assertEqualHash(Sha3_384, h2, "abc"); | |
| 236 | try htest.assertEqualHash(Sha3_384, h2, "abc"); | |
| 237 | 237 | const h3 = "79407d3b5916b59c3e30b09822974791c313fb9ecc849e406f23592d04f625dc8c709b98b43b3852b337216179aa7fc7"; |
| 238 | htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 238 | try htest.assertEqualHash(Sha3_384, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | test "sha3-384 streaming" { |
| ... | ... | @@ -244,29 +244,29 @@ test "sha3-384 streaming" { |
| 244 | 244 | |
| 245 | 245 | const h1 = "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004"; |
| 246 | 246 | h.final(out[0..]); |
| 247 | htest.assertEqual(h1, out[0..]); | |
| 247 | try htest.assertEqual(h1, out[0..]); | |
| 248 | 248 | |
| 249 | 249 | const h2 = "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25"; |
| 250 | 250 | h = Sha3_384.init(.{}); |
| 251 | 251 | h.update("abc"); |
| 252 | 252 | h.final(out[0..]); |
| 253 | htest.assertEqual(h2, out[0..]); | |
| 253 | try htest.assertEqual(h2, out[0..]); | |
| 254 | 254 | |
| 255 | 255 | h = Sha3_384.init(.{}); |
| 256 | 256 | h.update("a"); |
| 257 | 257 | h.update("b"); |
| 258 | 258 | h.update("c"); |
| 259 | 259 | h.final(out[0..]); |
| 260 | htest.assertEqual(h2, out[0..]); | |
| 260 | try htest.assertEqual(h2, out[0..]); | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | test "sha3-512 single" { |
| 264 | 264 | const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"; |
| 265 | htest.assertEqualHash(Sha3_512, h1, ""); | |
| 265 | try htest.assertEqualHash(Sha3_512, h1, ""); | |
| 266 | 266 | const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0"; |
| 267 | htest.assertEqualHash(Sha3_512, h2, "abc"); | |
| 267 | try htest.assertEqualHash(Sha3_512, h2, "abc"); | |
| 268 | 268 | const h3 = "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185"; |
| 269 | htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 269 | try htest.assertEqualHash(Sha3_512, h3, "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | test "sha3-512 streaming" { |
| ... | ... | @@ -275,20 +275,20 @@ test "sha3-512 streaming" { |
| 275 | 275 | |
| 276 | 276 | const h1 = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"; |
| 277 | 277 | h.final(out[0..]); |
| 278 | htest.assertEqual(h1, out[0..]); | |
| 278 | try htest.assertEqual(h1, out[0..]); | |
| 279 | 279 | |
| 280 | 280 | const h2 = "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0"; |
| 281 | 281 | h = Sha3_512.init(.{}); |
| 282 | 282 | h.update("abc"); |
| 283 | 283 | h.final(out[0..]); |
| 284 | htest.assertEqual(h2, out[0..]); | |
| 284 | try htest.assertEqual(h2, out[0..]); | |
| 285 | 285 | |
| 286 | 286 | h = Sha3_512.init(.{}); |
| 287 | 287 | h.update("a"); |
| 288 | 288 | h.update("b"); |
| 289 | 289 | h.update("c"); |
| 290 | 290 | h.final(out[0..]); |
| 291 | htest.assertEqual(h2, out[0..]); | |
| 291 | try htest.assertEqual(h2, out[0..]); | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | test "sha3-512 aligned final" { |
| ... | ... | @@ -301,13 +301,13 @@ test "sha3-512 aligned final" { |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | test "keccak-256 single" { |
| 304 | htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", ""); | |
| 305 | htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc"); | |
| 306 | htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 304 | try htest.assertEqualHash(Keccak_256, "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", ""); | |
| 305 | try htest.assertEqualHash(Keccak_256, "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45", "abc"); | |
| 306 | try htest.assertEqualHash(Keccak_256, "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | test "keccak-512 single" { |
| 310 | htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", ""); | |
| 311 | htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc"); | |
| 312 | htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 310 | try htest.assertEqualHash(Keccak_512, "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", ""); | |
| 311 | try htest.assertEqualHash(Keccak_512, "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", "abc"); | |
| 312 | try htest.assertEqualHash(Keccak_512, "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"); | |
| 313 | 313 | } |
lib/std/crypto/siphash.zig+3-3| ... | ... | @@ -319,7 +319,7 @@ test "siphash64-2-4 sanity" { |
| 319 | 319 | |
| 320 | 320 | var out: [siphash.mac_length]u8 = undefined; |
| 321 | 321 | siphash.create(&out, buffer[0..i], test_key); |
| 322 | testing.expectEqual(out, vector); | |
| 322 | try testing.expectEqual(out, vector); | |
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| ... | ... | @@ -399,7 +399,7 @@ test "siphash128-2-4 sanity" { |
| 399 | 399 | |
| 400 | 400 | var out: [siphash.mac_length]u8 = undefined; |
| 401 | 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 | } |
| 405 | 405 | |
| ... | ... | @@ -423,6 +423,6 @@ test "iterative non-divisible update" { |
| 423 | 423 | } |
| 424 | 424 | const iterative_hash = siphash.finalInt(); |
| 425 | 425 | |
| 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 | 8 | const fmt = std.fmt; |
| 9 | 9 | |
| 10 | 10 | // Hash using the specified hasher `H` asserting `expected == H(input)`. |
| 11 | pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) void { | |
| 11 | pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [Hasher.digest_length * 2:0]u8, input: []const u8) !void { | |
| 12 | 12 | var h: [Hasher.digest_length]u8 = undefined; |
| 13 | 13 | Hasher.hash(input, &h, .{}); |
| 14 | 14 | |
| 15 | assertEqual(expected_hex, &h); | |
| 15 | try assertEqual(expected_hex, &h); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Assert `expected` == hex(`input`) where `input` is a bytestring |
| 19 | pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) void { | |
| 19 | pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void { | |
| 20 | 20 | var expected_bytes: [expected_hex.len / 2]u8 = undefined; |
| 21 | 21 | for (expected_bytes) |*r, i| { |
| 22 | 22 | r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable; |
| 23 | 23 | } |
| 24 | 24 | |
| 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 | 92 | var b: [100]u8 = undefined; |
| 93 | 93 | std.crypto.random.bytes(a[0..]); |
| 94 | 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 | 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 | } |
| 99 | 99 | |
| 100 | 100 | test "crypto.utils.timingSafeEql (vectors)" { |
| ... | ... | @@ -104,22 +104,22 @@ test "crypto.utils.timingSafeEql (vectors)" { |
| 104 | 104 | std.crypto.random.bytes(b[0..]); |
| 105 | 105 | const v1: std.meta.Vector(100, u8) = a; |
| 106 | 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 | 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 | } |
| 111 | 111 | |
| 112 | 112 | test "crypto.utils.timingSafeCompare" { |
| 113 | 113 | var a = [_]u8{10} ** 32; |
| 114 | 114 | var b = [_]u8{10} ** 32; |
| 115 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq); | |
| 116 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq); | |
| 115 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq); | |
| 116 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq); | |
| 117 | 117 | a[31] = 1; |
| 118 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt); | |
| 119 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | |
| 118 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt); | |
| 119 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | |
| 120 | 120 | a[0] = 20; |
| 121 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt); | |
| 122 | testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | |
| 121 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt); | |
| 122 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "crypto.utils.secureZero" { |
| ... | ... | @@ -129,5 +129,5 @@ test "crypto.utils.secureZero" { |
| 129 | 129 | mem.set(u8, a[0..], 0); |
| 130 | 130 | secureZero(u8, b[0..]); |
| 131 | 131 | |
| 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 | 27 | } |
| 28 | 28 | |
| 29 | 29 | test "cstr fns" { |
| 30 | comptime testCStrFnsImpl(); | |
| 31 | testCStrFnsImpl(); | |
| 30 | comptime try testCStrFnsImpl(); | |
| 31 | try testCStrFnsImpl(); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | fn testCStrFnsImpl() void { | |
| 35 | testing.expect(cmp("aoeu", "aoez") == -1); | |
| 36 | testing.expect(mem.len("123456789") == 9); | |
| 34 | fn testCStrFnsImpl() !void { | |
| 35 | try testing.expect(cmp("aoeu", "aoez") == -1); | |
| 36 | try testing.expect(mem.len("123456789") == 9); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 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 | 48 | test "addNullByte" { |
| 49 | 49 | const slice = try addNullByte(std.testing.allocator, "hello"[0..4]); |
| 50 | 50 | defer std.testing.allocator.free(slice); |
| 51 | testing.expect(slice.len == 4); | |
| 52 | testing.expect(slice[4] == 0); | |
| 51 | try testing.expect(slice.len == 4); | |
| 52 | try testing.expect(slice[4] == 0); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | pub const NullTerminated2DArray = struct { |
lib/std/dynamic_library.zig+1-1| ... | ... | @@ -408,7 +408,7 @@ test "dynamic_library" { |
| 408 | 408 | }; |
| 409 | 409 | |
| 410 | 410 | const dynlib = DynLib.open(libname) catch |err| { |
| 411 | testing.expect(err == error.FileNotFound); | |
| 411 | try testing.expect(err == error.FileNotFound); | |
| 412 | 412 | return; |
| 413 | 413 | }; |
| 414 | 414 | } |
lib/std/elf.zig+1-1| ... | ... | @@ -565,7 +565,7 @@ test "bswapAllFields" { |
| 565 | 565 | .ch_addralign = 0x12124242, |
| 566 | 566 | }; |
| 567 | 567 | bswapAllFields(Elf32_Chdr, &s); |
| 568 | std.testing.expectEqual(Elf32_Chdr{ | |
| 568 | try std.testing.expectEqual(Elf32_Chdr{ | |
| 569 | 569 | .ch_type = 0x34123412, |
| 570 | 570 | .ch_size = 0x78567856, |
| 571 | 571 | .ch_addralign = 0x42421212, |
lib/std/enums.zig+275-275| ... | ... | @@ -56,10 +56,10 @@ test "std.enums.valuesFromFields" { |
| 56 | 56 | .{ .name = "a", .value = undefined }, |
| 57 | 57 | .{ .name = "d", .value = undefined }, |
| 58 | 58 | }); |
| 59 | testing.expectEqual(E.b, fields[0]); | |
| 60 | testing.expectEqual(E.a, fields[1]); | |
| 61 | testing.expectEqual(E.d, fields[2]); // a == d | |
| 62 | testing.expectEqual(E.d, fields[3]); | |
| 59 | try testing.expectEqual(E.b, fields[0]); | |
| 60 | try testing.expectEqual(E.a, fields[1]); | |
| 61 | try testing.expectEqual(E.d, fields[2]); // a == d | |
| 62 | try testing.expectEqual(E.d, fields[3]); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /// Returns the set of all named values in the given enum, in |
| ... | ... | @@ -70,7 +70,7 @@ pub fn values(comptime E: type) []const E { |
| 70 | 70 | |
| 71 | 71 | test "std.enum.values" { |
| 72 | 72 | const E = extern enum { a, b, c, d = 0 }; |
| 73 | testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E)); | |
| 73 | try testing.expectEqualSlices(E, &.{ .a, .b, .c, .d }, values(E)); | |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /// Returns the set of all unique named values in the given enum, in |
| ... | ... | @@ -82,10 +82,10 @@ pub fn uniqueValues(comptime E: type) []const E { |
| 82 | 82 | |
| 83 | 83 | test "std.enum.uniqueValues" { |
| 84 | 84 | const E = extern enum { a, b, c, d = 0, e, f = 3 }; |
| 85 | testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E)); | |
| 85 | try testing.expectEqualSlices(E, &.{ .a, .b, .c, .f }, uniqueValues(E)); | |
| 86 | 86 | |
| 87 | 87 | const F = enum { a, b, c }; |
| 88 | testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F)); | |
| 88 | try testing.expectEqualSlices(F, &.{ .a, .b, .c }, uniqueValues(F)); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /// Returns the set of all unique field values in the given enum, in |
| ... | ... | @@ -179,10 +179,10 @@ test "std.enums.directEnumArray" { |
| 179 | 179 | .c = true, |
| 180 | 180 | }); |
| 181 | 181 | |
| 182 | testing.expectEqual([7]bool, @TypeOf(array)); | |
| 183 | testing.expectEqual(true, array[4]); | |
| 184 | testing.expectEqual(false, array[6]); | |
| 185 | testing.expectEqual(true, array[2]); | |
| 182 | try testing.expectEqual([7]bool, @TypeOf(array)); | |
| 183 | try testing.expectEqual(true, array[4]); | |
| 184 | try testing.expectEqual(false, array[6]); | |
| 185 | try testing.expectEqual(true, array[2]); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /// Initializes an array of Data which can be indexed by |
| ... | ... | @@ -220,10 +220,10 @@ test "std.enums.directEnumArrayDefault" { |
| 220 | 220 | .b = runtime_false, |
| 221 | 221 | }); |
| 222 | 222 | |
| 223 | testing.expectEqual([7]bool, @TypeOf(array)); | |
| 224 | testing.expectEqual(true, array[4]); | |
| 225 | testing.expectEqual(false, array[6]); | |
| 226 | testing.expectEqual(false, array[2]); | |
| 223 | try testing.expectEqual([7]bool, @TypeOf(array)); | |
| 224 | try testing.expectEqual(true, array[4]); | |
| 225 | try testing.expectEqual(false, array[6]); | |
| 226 | try testing.expectEqual(false, array[2]); | |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /// Cast an enum literal, value, or string to the enum value of type E |
| ... | ... | @@ -250,23 +250,23 @@ pub fn nameCast(comptime E: type, comptime value: anytype) E { |
| 250 | 250 | test "std.enums.nameCast" { |
| 251 | 251 | const A = enum { a = 0, b = 1 }; |
| 252 | 252 | const B = enum { a = 1, b = 0 }; |
| 253 | testing.expectEqual(A.a, nameCast(A, .a)); | |
| 254 | testing.expectEqual(A.a, nameCast(A, A.a)); | |
| 255 | testing.expectEqual(A.a, nameCast(A, B.a)); | |
| 256 | testing.expectEqual(A.a, nameCast(A, "a")); | |
| 257 | testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a"))); | |
| 258 | testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a"))); | |
| 259 | testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a"))); | |
| 260 | ||
| 261 | testing.expectEqual(B.a, nameCast(B, .a)); | |
| 262 | testing.expectEqual(B.a, nameCast(B, A.a)); | |
| 263 | testing.expectEqual(B.a, nameCast(B, B.a)); | |
| 264 | testing.expectEqual(B.a, nameCast(B, "a")); | |
| 265 | ||
| 266 | testing.expectEqual(B.b, nameCast(B, .b)); | |
| 267 | testing.expectEqual(B.b, nameCast(B, A.b)); | |
| 268 | testing.expectEqual(B.b, nameCast(B, B.b)); | |
| 269 | testing.expectEqual(B.b, nameCast(B, "b")); | |
| 253 | try testing.expectEqual(A.a, nameCast(A, .a)); | |
| 254 | try testing.expectEqual(A.a, nameCast(A, A.a)); | |
| 255 | try testing.expectEqual(A.a, nameCast(A, B.a)); | |
| 256 | try testing.expectEqual(A.a, nameCast(A, "a")); | |
| 257 | try testing.expectEqual(A.a, nameCast(A, @as(*const [1]u8, "a"))); | |
| 258 | try testing.expectEqual(A.a, nameCast(A, @as([:0]const u8, "a"))); | |
| 259 | try testing.expectEqual(A.a, nameCast(A, @as([]const u8, "a"))); | |
| 260 | ||
| 261 | try testing.expectEqual(B.a, nameCast(B, .a)); | |
| 262 | try testing.expectEqual(B.a, nameCast(B, A.a)); | |
| 263 | try testing.expectEqual(B.a, nameCast(B, B.a)); | |
| 264 | try testing.expectEqual(B.a, nameCast(B, "a")); | |
| 265 | ||
| 266 | try testing.expectEqual(B.b, nameCast(B, .b)); | |
| 267 | try testing.expectEqual(B.b, nameCast(B, A.b)); | |
| 268 | try testing.expectEqual(B.b, nameCast(B, B.b)); | |
| 269 | try testing.expectEqual(B.b, nameCast(B, "b")); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /// A set of enum elements, backed by a bitfield. If the enum |
| ... | ... | @@ -851,202 +851,202 @@ test "std.enums.EnumIndexer dense zeroed" { |
| 851 | 851 | const E = enum { b = 1, a = 0, c = 2 }; |
| 852 | 852 | const Indexer = EnumIndexer(E); |
| 853 | 853 | ensureIndexer(Indexer); |
| 854 | testing.expectEqual(E, Indexer.Key); | |
| 855 | testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 854 | try testing.expectEqual(E, Indexer.Key); | |
| 855 | try testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 856 | 856 | |
| 857 | testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 858 | testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 859 | testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 857 | try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 858 | try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 859 | try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 860 | 860 | |
| 861 | testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 862 | testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 863 | testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 861 | try testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 862 | try testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 863 | try testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | test "std.enums.EnumIndexer dense positive" { |
| 867 | 867 | const E = enum(u4) { c = 6, a = 4, b = 5 }; |
| 868 | 868 | const Indexer = EnumIndexer(E); |
| 869 | 869 | ensureIndexer(Indexer); |
| 870 | testing.expectEqual(E, Indexer.Key); | |
| 871 | testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 870 | try testing.expectEqual(E, Indexer.Key); | |
| 871 | try testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 872 | 872 | |
| 873 | testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 874 | testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 875 | testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 873 | try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 874 | try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 875 | try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 876 | 876 | |
| 877 | testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 878 | testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 879 | testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 877 | try testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 878 | try testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 879 | try testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | test "std.enums.EnumIndexer dense negative" { |
| 883 | 883 | const E = enum(i4) { a = -6, c = -4, b = -5 }; |
| 884 | 884 | const Indexer = EnumIndexer(E); |
| 885 | 885 | ensureIndexer(Indexer); |
| 886 | testing.expectEqual(E, Indexer.Key); | |
| 887 | testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 886 | try testing.expectEqual(E, Indexer.Key); | |
| 887 | try testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 888 | 888 | |
| 889 | testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 890 | testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 891 | testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 889 | try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 890 | try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 891 | try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 892 | 892 | |
| 893 | testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 894 | testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 895 | testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 893 | try testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 894 | try testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 895 | try testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | test "std.enums.EnumIndexer sparse" { |
| 899 | 899 | const E = enum(i4) { a = -2, c = 6, b = 4 }; |
| 900 | 900 | const Indexer = EnumIndexer(E); |
| 901 | 901 | ensureIndexer(Indexer); |
| 902 | testing.expectEqual(E, Indexer.Key); | |
| 903 | testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 902 | try testing.expectEqual(E, Indexer.Key); | |
| 903 | try testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 904 | 904 | |
| 905 | testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 906 | testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 907 | testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 905 | try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 906 | try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 907 | try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 908 | 908 | |
| 909 | testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 910 | testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 911 | testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 909 | try testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 910 | try testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 911 | try testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | test "std.enums.EnumIndexer repeats" { |
| 915 | 915 | const E = extern enum { a = -2, c = 6, b = 4, b2 = 4 }; |
| 916 | 916 | const Indexer = EnumIndexer(E); |
| 917 | 917 | ensureIndexer(Indexer); |
| 918 | testing.expectEqual(E, Indexer.Key); | |
| 919 | testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 918 | try testing.expectEqual(E, Indexer.Key); | |
| 919 | try testing.expectEqual(@as(usize, 3), Indexer.count); | |
| 920 | 920 | |
| 921 | testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 922 | testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 923 | testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 921 | try testing.expectEqual(@as(usize, 0), Indexer.indexOf(.a)); | |
| 922 | try testing.expectEqual(@as(usize, 1), Indexer.indexOf(.b)); | |
| 923 | try testing.expectEqual(@as(usize, 2), Indexer.indexOf(.c)); | |
| 924 | 924 | |
| 925 | testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 926 | testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 927 | testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 925 | try testing.expectEqual(E.a, Indexer.keyForIndex(0)); | |
| 926 | try testing.expectEqual(E.b, Indexer.keyForIndex(1)); | |
| 927 | try testing.expectEqual(E.c, Indexer.keyForIndex(2)); | |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | test "std.enums.EnumSet" { |
| 931 | 931 | const E = extern enum { a, b, c, d, e = 0 }; |
| 932 | 932 | const Set = EnumSet(E); |
| 933 | testing.expectEqual(E, Set.Key); | |
| 934 | testing.expectEqual(EnumIndexer(E), Set.Indexer); | |
| 935 | testing.expectEqual(@as(usize, 4), Set.len); | |
| 933 | try testing.expectEqual(E, Set.Key); | |
| 934 | try testing.expectEqual(EnumIndexer(E), Set.Indexer); | |
| 935 | try testing.expectEqual(@as(usize, 4), Set.len); | |
| 936 | 936 | |
| 937 | 937 | // Empty sets |
| 938 | 938 | const empty = Set{}; |
| 939 | comptime testing.expect(empty.count() == 0); | |
| 939 | comptime try testing.expect(empty.count() == 0); | |
| 940 | 940 | |
| 941 | 941 | var empty_b = Set.init(.{}); |
| 942 | testing.expect(empty_b.count() == 0); | |
| 942 | try testing.expect(empty_b.count() == 0); | |
| 943 | 943 | |
| 944 | 944 | const empty_c = comptime Set.init(.{}); |
| 945 | comptime testing.expect(empty_c.count() == 0); | |
| 945 | comptime try testing.expect(empty_c.count() == 0); | |
| 946 | 946 | |
| 947 | 947 | const full = Set.initFull(); |
| 948 | testing.expect(full.count() == Set.len); | |
| 948 | try testing.expect(full.count() == Set.len); | |
| 949 | 949 | |
| 950 | 950 | const full_b = comptime Set.initFull(); |
| 951 | comptime testing.expect(full_b.count() == Set.len); | |
| 951 | comptime try testing.expect(full_b.count() == Set.len); | |
| 952 | 952 | |
| 953 | testing.expectEqual(false, empty.contains(.a)); | |
| 954 | testing.expectEqual(false, empty.contains(.b)); | |
| 955 | testing.expectEqual(false, empty.contains(.c)); | |
| 956 | testing.expectEqual(false, empty.contains(.d)); | |
| 957 | testing.expectEqual(false, empty.contains(.e)); | |
| 953 | try testing.expectEqual(false, empty.contains(.a)); | |
| 954 | try testing.expectEqual(false, empty.contains(.b)); | |
| 955 | try testing.expectEqual(false, empty.contains(.c)); | |
| 956 | try testing.expectEqual(false, empty.contains(.d)); | |
| 957 | try testing.expectEqual(false, empty.contains(.e)); | |
| 958 | 958 | { |
| 959 | 959 | var iter = empty_b.iterator(); |
| 960 | testing.expectEqual(@as(?E, null), iter.next()); | |
| 960 | try testing.expectEqual(@as(?E, null), iter.next()); | |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | var mut = Set.init(.{ |
| 964 | 964 | .a = true, |
| 965 | 965 | .c = true, |
| 966 | 966 | }); |
| 967 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 968 | testing.expectEqual(true, mut.contains(.a)); | |
| 969 | testing.expectEqual(false, mut.contains(.b)); | |
| 970 | testing.expectEqual(true, mut.contains(.c)); | |
| 971 | testing.expectEqual(false, mut.contains(.d)); | |
| 972 | testing.expectEqual(true, mut.contains(.e)); // aliases a | |
| 967 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 968 | try testing.expectEqual(true, mut.contains(.a)); | |
| 969 | try testing.expectEqual(false, mut.contains(.b)); | |
| 970 | try testing.expectEqual(true, mut.contains(.c)); | |
| 971 | try testing.expectEqual(false, mut.contains(.d)); | |
| 972 | try testing.expectEqual(true, mut.contains(.e)); // aliases a | |
| 973 | 973 | { |
| 974 | 974 | var it = mut.iterator(); |
| 975 | testing.expectEqual(@as(?E, .a), it.next()); | |
| 976 | testing.expectEqual(@as(?E, .c), it.next()); | |
| 977 | testing.expectEqual(@as(?E, null), it.next()); | |
| 975 | try testing.expectEqual(@as(?E, .a), it.next()); | |
| 976 | try testing.expectEqual(@as(?E, .c), it.next()); | |
| 977 | try testing.expectEqual(@as(?E, null), it.next()); | |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | mut.toggleAll(); |
| 981 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 982 | testing.expectEqual(false, mut.contains(.a)); | |
| 983 | testing.expectEqual(true, mut.contains(.b)); | |
| 984 | testing.expectEqual(false, mut.contains(.c)); | |
| 985 | testing.expectEqual(true, mut.contains(.d)); | |
| 986 | testing.expectEqual(false, mut.contains(.e)); // aliases a | |
| 981 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 982 | try testing.expectEqual(false, mut.contains(.a)); | |
| 983 | try testing.expectEqual(true, mut.contains(.b)); | |
| 984 | try testing.expectEqual(false, mut.contains(.c)); | |
| 985 | try testing.expectEqual(true, mut.contains(.d)); | |
| 986 | try testing.expectEqual(false, mut.contains(.e)); // aliases a | |
| 987 | 987 | { |
| 988 | 988 | var it = mut.iterator(); |
| 989 | testing.expectEqual(@as(?E, .b), it.next()); | |
| 990 | testing.expectEqual(@as(?E, .d), it.next()); | |
| 991 | testing.expectEqual(@as(?E, null), it.next()); | |
| 989 | try testing.expectEqual(@as(?E, .b), it.next()); | |
| 990 | try testing.expectEqual(@as(?E, .d), it.next()); | |
| 991 | try testing.expectEqual(@as(?E, null), it.next()); | |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | mut.toggleSet(Set.init(.{ .a = true, .b = true })); |
| 995 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 996 | testing.expectEqual(true, mut.contains(.a)); | |
| 997 | testing.expectEqual(false, mut.contains(.b)); | |
| 998 | testing.expectEqual(false, mut.contains(.c)); | |
| 999 | testing.expectEqual(true, mut.contains(.d)); | |
| 1000 | testing.expectEqual(true, mut.contains(.e)); // aliases a | |
| 995 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 996 | try testing.expectEqual(true, mut.contains(.a)); | |
| 997 | try testing.expectEqual(false, mut.contains(.b)); | |
| 998 | try testing.expectEqual(false, mut.contains(.c)); | |
| 999 | try testing.expectEqual(true, mut.contains(.d)); | |
| 1000 | try testing.expectEqual(true, mut.contains(.e)); // aliases a | |
| 1001 | 1001 | |
| 1002 | 1002 | mut.setUnion(Set.init(.{ .a = true, .b = true })); |
| 1003 | testing.expectEqual(@as(usize, 3), mut.count()); | |
| 1004 | testing.expectEqual(true, mut.contains(.a)); | |
| 1005 | testing.expectEqual(true, mut.contains(.b)); | |
| 1006 | testing.expectEqual(false, mut.contains(.c)); | |
| 1007 | testing.expectEqual(true, mut.contains(.d)); | |
| 1003 | try testing.expectEqual(@as(usize, 3), mut.count()); | |
| 1004 | try testing.expectEqual(true, mut.contains(.a)); | |
| 1005 | try testing.expectEqual(true, mut.contains(.b)); | |
| 1006 | try testing.expectEqual(false, mut.contains(.c)); | |
| 1007 | try testing.expectEqual(true, mut.contains(.d)); | |
| 1008 | 1008 | |
| 1009 | 1009 | mut.remove(.c); |
| 1010 | 1010 | mut.remove(.b); |
| 1011 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1012 | testing.expectEqual(true, mut.contains(.a)); | |
| 1013 | testing.expectEqual(false, mut.contains(.b)); | |
| 1014 | testing.expectEqual(false, mut.contains(.c)); | |
| 1015 | testing.expectEqual(true, mut.contains(.d)); | |
| 1011 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1012 | try testing.expectEqual(true, mut.contains(.a)); | |
| 1013 | try testing.expectEqual(false, mut.contains(.b)); | |
| 1014 | try testing.expectEqual(false, mut.contains(.c)); | |
| 1015 | try testing.expectEqual(true, mut.contains(.d)); | |
| 1016 | 1016 | |
| 1017 | 1017 | mut.setIntersection(Set.init(.{ .a = true, .b = true })); |
| 1018 | testing.expectEqual(@as(usize, 1), mut.count()); | |
| 1019 | testing.expectEqual(true, mut.contains(.a)); | |
| 1020 | testing.expectEqual(false, mut.contains(.b)); | |
| 1021 | testing.expectEqual(false, mut.contains(.c)); | |
| 1022 | testing.expectEqual(false, mut.contains(.d)); | |
| 1018 | try testing.expectEqual(@as(usize, 1), mut.count()); | |
| 1019 | try testing.expectEqual(true, mut.contains(.a)); | |
| 1020 | try testing.expectEqual(false, mut.contains(.b)); | |
| 1021 | try testing.expectEqual(false, mut.contains(.c)); | |
| 1022 | try testing.expectEqual(false, mut.contains(.d)); | |
| 1023 | 1023 | |
| 1024 | 1024 | mut.insert(.a); |
| 1025 | 1025 | mut.insert(.b); |
| 1026 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1027 | testing.expectEqual(true, mut.contains(.a)); | |
| 1028 | testing.expectEqual(true, mut.contains(.b)); | |
| 1029 | testing.expectEqual(false, mut.contains(.c)); | |
| 1030 | testing.expectEqual(false, mut.contains(.d)); | |
| 1026 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1027 | try testing.expectEqual(true, mut.contains(.a)); | |
| 1028 | try testing.expectEqual(true, mut.contains(.b)); | |
| 1029 | try testing.expectEqual(false, mut.contains(.c)); | |
| 1030 | try testing.expectEqual(false, mut.contains(.d)); | |
| 1031 | 1031 | |
| 1032 | 1032 | mut.setPresent(.a, false); |
| 1033 | 1033 | mut.toggle(.b); |
| 1034 | 1034 | mut.toggle(.c); |
| 1035 | 1035 | mut.setPresent(.d, true); |
| 1036 | testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1037 | testing.expectEqual(false, mut.contains(.a)); | |
| 1038 | testing.expectEqual(false, mut.contains(.b)); | |
| 1039 | testing.expectEqual(true, mut.contains(.c)); | |
| 1040 | testing.expectEqual(true, mut.contains(.d)); | |
| 1036 | try testing.expectEqual(@as(usize, 2), mut.count()); | |
| 1037 | try testing.expectEqual(false, mut.contains(.a)); | |
| 1038 | try testing.expectEqual(false, mut.contains(.b)); | |
| 1039 | try testing.expectEqual(true, mut.contains(.c)); | |
| 1040 | try testing.expectEqual(true, mut.contains(.d)); | |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | test "std.enums.EnumArray void" { |
| 1044 | 1044 | const E = extern enum { a, b, c, d, e = 0 }; |
| 1045 | 1045 | const ArrayVoid = EnumArray(E, void); |
| 1046 | testing.expectEqual(E, ArrayVoid.Key); | |
| 1047 | testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer); | |
| 1048 | testing.expectEqual(void, ArrayVoid.Value); | |
| 1049 | testing.expectEqual(@as(usize, 4), ArrayVoid.len); | |
| 1046 | try testing.expectEqual(E, ArrayVoid.Key); | |
| 1047 | try testing.expectEqual(EnumIndexer(E), ArrayVoid.Indexer); | |
| 1048 | try testing.expectEqual(void, ArrayVoid.Value); | |
| 1049 | try testing.expectEqual(@as(usize, 4), ArrayVoid.len); | |
| 1050 | 1050 | |
| 1051 | 1051 | const undef = ArrayVoid.initUndefined(); |
| 1052 | 1052 | var inst = ArrayVoid.initFill({}); |
| ... | ... | @@ -1059,113 +1059,113 @@ test "std.enums.EnumArray void" { |
| 1059 | 1059 | inst.set(.a, {}); |
| 1060 | 1060 | |
| 1061 | 1061 | var it = inst.iterator(); |
| 1062 | testing.expectEqual(E.a, it.next().?.key); | |
| 1063 | testing.expectEqual(E.b, it.next().?.key); | |
| 1064 | testing.expectEqual(E.c, it.next().?.key); | |
| 1065 | testing.expectEqual(E.d, it.next().?.key); | |
| 1066 | testing.expect(it.next() == null); | |
| 1062 | try testing.expectEqual(E.a, it.next().?.key); | |
| 1063 | try testing.expectEqual(E.b, it.next().?.key); | |
| 1064 | try testing.expectEqual(E.c, it.next().?.key); | |
| 1065 | try testing.expectEqual(E.d, it.next().?.key); | |
| 1066 | try testing.expect(it.next() == null); | |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | test "std.enums.EnumArray sized" { |
| 1070 | 1070 | const E = extern enum { a, b, c, d, e = 0 }; |
| 1071 | 1071 | const Array = EnumArray(E, usize); |
| 1072 | testing.expectEqual(E, Array.Key); | |
| 1073 | testing.expectEqual(EnumIndexer(E), Array.Indexer); | |
| 1074 | testing.expectEqual(usize, Array.Value); | |
| 1075 | testing.expectEqual(@as(usize, 4), Array.len); | |
| 1072 | try testing.expectEqual(E, Array.Key); | |
| 1073 | try testing.expectEqual(EnumIndexer(E), Array.Indexer); | |
| 1074 | try testing.expectEqual(usize, Array.Value); | |
| 1075 | try testing.expectEqual(@as(usize, 4), Array.len); | |
| 1076 | 1076 | |
| 1077 | 1077 | const undef = Array.initUndefined(); |
| 1078 | 1078 | var inst = Array.initFill(5); |
| 1079 | 1079 | const inst2 = Array.init(.{ .a = 1, .b = 2, .c = 3, .d = 4 }); |
| 1080 | 1080 | const inst3 = Array.initDefault(6, .{ .b = 4, .c = 2 }); |
| 1081 | 1081 | |
| 1082 | testing.expectEqual(@as(usize, 5), inst.get(.a)); | |
| 1083 | testing.expectEqual(@as(usize, 5), inst.get(.b)); | |
| 1084 | testing.expectEqual(@as(usize, 5), inst.get(.c)); | |
| 1085 | testing.expectEqual(@as(usize, 5), inst.get(.d)); | |
| 1082 | try testing.expectEqual(@as(usize, 5), inst.get(.a)); | |
| 1083 | try testing.expectEqual(@as(usize, 5), inst.get(.b)); | |
| 1084 | try testing.expectEqual(@as(usize, 5), inst.get(.c)); | |
| 1085 | try testing.expectEqual(@as(usize, 5), inst.get(.d)); | |
| 1086 | 1086 | |
| 1087 | testing.expectEqual(@as(usize, 1), inst2.get(.a)); | |
| 1088 | testing.expectEqual(@as(usize, 2), inst2.get(.b)); | |
| 1089 | testing.expectEqual(@as(usize, 3), inst2.get(.c)); | |
| 1090 | testing.expectEqual(@as(usize, 4), inst2.get(.d)); | |
| 1087 | try testing.expectEqual(@as(usize, 1), inst2.get(.a)); | |
| 1088 | try testing.expectEqual(@as(usize, 2), inst2.get(.b)); | |
| 1089 | try testing.expectEqual(@as(usize, 3), inst2.get(.c)); | |
| 1090 | try testing.expectEqual(@as(usize, 4), inst2.get(.d)); | |
| 1091 | 1091 | |
| 1092 | testing.expectEqual(@as(usize, 6), inst3.get(.a)); | |
| 1093 | testing.expectEqual(@as(usize, 4), inst3.get(.b)); | |
| 1094 | testing.expectEqual(@as(usize, 2), inst3.get(.c)); | |
| 1095 | testing.expectEqual(@as(usize, 6), inst3.get(.d)); | |
| 1092 | try testing.expectEqual(@as(usize, 6), inst3.get(.a)); | |
| 1093 | try testing.expectEqual(@as(usize, 4), inst3.get(.b)); | |
| 1094 | try testing.expectEqual(@as(usize, 2), inst3.get(.c)); | |
| 1095 | try testing.expectEqual(@as(usize, 6), inst3.get(.d)); | |
| 1096 | 1096 | |
| 1097 | testing.expectEqual(&inst.values[0], inst.getPtr(.a)); | |
| 1098 | testing.expectEqual(&inst.values[1], inst.getPtr(.b)); | |
| 1099 | testing.expectEqual(&inst.values[2], inst.getPtr(.c)); | |
| 1100 | testing.expectEqual(&inst.values[3], inst.getPtr(.d)); | |
| 1097 | try testing.expectEqual(&inst.values[0], inst.getPtr(.a)); | |
| 1098 | try testing.expectEqual(&inst.values[1], inst.getPtr(.b)); | |
| 1099 | try testing.expectEqual(&inst.values[2], inst.getPtr(.c)); | |
| 1100 | try testing.expectEqual(&inst.values[3], inst.getPtr(.d)); | |
| 1101 | 1101 | |
| 1102 | testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a)); | |
| 1103 | testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b)); | |
| 1104 | testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c)); | |
| 1105 | testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d)); | |
| 1102 | try testing.expectEqual(@as(*const usize, &inst.values[0]), inst.getPtrConst(.a)); | |
| 1103 | try testing.expectEqual(@as(*const usize, &inst.values[1]), inst.getPtrConst(.b)); | |
| 1104 | try testing.expectEqual(@as(*const usize, &inst.values[2]), inst.getPtrConst(.c)); | |
| 1105 | try testing.expectEqual(@as(*const usize, &inst.values[3]), inst.getPtrConst(.d)); | |
| 1106 | 1106 | |
| 1107 | 1107 | inst.set(.c, 8); |
| 1108 | testing.expectEqual(@as(usize, 5), inst.get(.a)); | |
| 1109 | testing.expectEqual(@as(usize, 5), inst.get(.b)); | |
| 1110 | testing.expectEqual(@as(usize, 8), inst.get(.c)); | |
| 1111 | testing.expectEqual(@as(usize, 5), inst.get(.d)); | |
| 1108 | try testing.expectEqual(@as(usize, 5), inst.get(.a)); | |
| 1109 | try testing.expectEqual(@as(usize, 5), inst.get(.b)); | |
| 1110 | try testing.expectEqual(@as(usize, 8), inst.get(.c)); | |
| 1111 | try testing.expectEqual(@as(usize, 5), inst.get(.d)); | |
| 1112 | 1112 | |
| 1113 | 1113 | var it = inst.iterator(); |
| 1114 | 1114 | const Entry = Array.Entry; |
| 1115 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1115 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1116 | 1116 | .key = .a, |
| 1117 | 1117 | .value = &inst.values[0], |
| 1118 | 1118 | }), it.next()); |
| 1119 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1119 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1120 | 1120 | .key = .b, |
| 1121 | 1121 | .value = &inst.values[1], |
| 1122 | 1122 | }), it.next()); |
| 1123 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1123 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1124 | 1124 | .key = .c, |
| 1125 | 1125 | .value = &inst.values[2], |
| 1126 | 1126 | }), it.next()); |
| 1127 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1127 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1128 | 1128 | .key = .d, |
| 1129 | 1129 | .value = &inst.values[3], |
| 1130 | 1130 | }), it.next()); |
| 1131 | testing.expectEqual(@as(?Entry, null), it.next()); | |
| 1131 | try testing.expectEqual(@as(?Entry, null), it.next()); | |
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | test "std.enums.EnumMap void" { |
| 1135 | 1135 | const E = extern enum { a, b, c, d, e = 0 }; |
| 1136 | 1136 | const Map = EnumMap(E, void); |
| 1137 | testing.expectEqual(E, Map.Key); | |
| 1138 | testing.expectEqual(EnumIndexer(E), Map.Indexer); | |
| 1139 | testing.expectEqual(void, Map.Value); | |
| 1140 | testing.expectEqual(@as(usize, 4), Map.len); | |
| 1137 | try testing.expectEqual(E, Map.Key); | |
| 1138 | try testing.expectEqual(EnumIndexer(E), Map.Indexer); | |
| 1139 | try testing.expectEqual(void, Map.Value); | |
| 1140 | try testing.expectEqual(@as(usize, 4), Map.len); | |
| 1141 | 1141 | |
| 1142 | 1142 | const b = Map.initFull({}); |
| 1143 | testing.expectEqual(@as(usize, 4), b.count()); | |
| 1143 | try testing.expectEqual(@as(usize, 4), b.count()); | |
| 1144 | 1144 | |
| 1145 | 1145 | const c = Map.initFullWith(.{ .a = {}, .b = {}, .c = {}, .d = {} }); |
| 1146 | testing.expectEqual(@as(usize, 4), c.count()); | |
| 1146 | try testing.expectEqual(@as(usize, 4), c.count()); | |
| 1147 | 1147 | |
| 1148 | 1148 | const d = Map.initFullWithDefault({}, .{ .b = {} }); |
| 1149 | testing.expectEqual(@as(usize, 4), d.count()); | |
| 1149 | try testing.expectEqual(@as(usize, 4), d.count()); | |
| 1150 | 1150 | |
| 1151 | 1151 | var a = Map.init(.{ .b = {}, .d = {} }); |
| 1152 | testing.expectEqual(@as(usize, 2), a.count()); | |
| 1153 | testing.expectEqual(false, a.contains(.a)); | |
| 1154 | testing.expectEqual(true, a.contains(.b)); | |
| 1155 | testing.expectEqual(false, a.contains(.c)); | |
| 1156 | testing.expectEqual(true, a.contains(.d)); | |
| 1157 | testing.expect(a.get(.a) == null); | |
| 1158 | testing.expect(a.get(.b) != null); | |
| 1159 | testing.expect(a.get(.c) == null); | |
| 1160 | testing.expect(a.get(.d) != null); | |
| 1161 | testing.expect(a.getPtr(.a) == null); | |
| 1162 | testing.expect(a.getPtr(.b) != null); | |
| 1163 | testing.expect(a.getPtr(.c) == null); | |
| 1164 | testing.expect(a.getPtr(.d) != null); | |
| 1165 | testing.expect(a.getPtrConst(.a) == null); | |
| 1166 | testing.expect(a.getPtrConst(.b) != null); | |
| 1167 | testing.expect(a.getPtrConst(.c) == null); | |
| 1168 | testing.expect(a.getPtrConst(.d) != null); | |
| 1152 | try testing.expectEqual(@as(usize, 2), a.count()); | |
| 1153 | try testing.expectEqual(false, a.contains(.a)); | |
| 1154 | try testing.expectEqual(true, a.contains(.b)); | |
| 1155 | try testing.expectEqual(false, a.contains(.c)); | |
| 1156 | try testing.expectEqual(true, a.contains(.d)); | |
| 1157 | try testing.expect(a.get(.a) == null); | |
| 1158 | try testing.expect(a.get(.b) != null); | |
| 1159 | try testing.expect(a.get(.c) == null); | |
| 1160 | try testing.expect(a.get(.d) != null); | |
| 1161 | try testing.expect(a.getPtr(.a) == null); | |
| 1162 | try testing.expect(a.getPtr(.b) != null); | |
| 1163 | try testing.expect(a.getPtr(.c) == null); | |
| 1164 | try testing.expect(a.getPtr(.d) != null); | |
| 1165 | try testing.expect(a.getPtrConst(.a) == null); | |
| 1166 | try testing.expect(a.getPtrConst(.b) != null); | |
| 1167 | try testing.expect(a.getPtrConst(.c) == null); | |
| 1168 | try testing.expect(a.getPtrConst(.d) != null); | |
| 1169 | 1169 | _ = a.getPtrAssertContains(.b); |
| 1170 | 1170 | _ = a.getAssertContains(.d); |
| 1171 | 1171 | |
| ... | ... | @@ -1174,115 +1174,115 @@ test "std.enums.EnumMap void" { |
| 1174 | 1174 | a.putUninitialized(.c).* = {}; |
| 1175 | 1175 | a.putUninitialized(.c).* = {}; |
| 1176 | 1176 | |
| 1177 | testing.expectEqual(@as(usize, 4), a.count()); | |
| 1178 | testing.expect(a.get(.a) != null); | |
| 1179 | testing.expect(a.get(.b) != null); | |
| 1180 | testing.expect(a.get(.c) != null); | |
| 1181 | testing.expect(a.get(.d) != null); | |
| 1177 | try testing.expectEqual(@as(usize, 4), a.count()); | |
| 1178 | try testing.expect(a.get(.a) != null); | |
| 1179 | try testing.expect(a.get(.b) != null); | |
| 1180 | try testing.expect(a.get(.c) != null); | |
| 1181 | try testing.expect(a.get(.d) != null); | |
| 1182 | 1182 | |
| 1183 | 1183 | a.remove(.a); |
| 1184 | 1184 | _ = a.fetchRemove(.c); |
| 1185 | 1185 | |
| 1186 | 1186 | var iter = a.iterator(); |
| 1187 | 1187 | const Entry = Map.Entry; |
| 1188 | testing.expectEqual(E.b, iter.next().?.key); | |
| 1189 | testing.expectEqual(E.d, iter.next().?.key); | |
| 1190 | testing.expect(iter.next() == null); | |
| 1188 | try testing.expectEqual(E.b, iter.next().?.key); | |
| 1189 | try testing.expectEqual(E.d, iter.next().?.key); | |
| 1190 | try testing.expect(iter.next() == null); | |
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | test "std.enums.EnumMap sized" { |
| 1194 | 1194 | const E = extern enum { a, b, c, d, e = 0 }; |
| 1195 | 1195 | const Map = EnumMap(E, usize); |
| 1196 | testing.expectEqual(E, Map.Key); | |
| 1197 | testing.expectEqual(EnumIndexer(E), Map.Indexer); | |
| 1198 | testing.expectEqual(usize, Map.Value); | |
| 1199 | testing.expectEqual(@as(usize, 4), Map.len); | |
| 1196 | try testing.expectEqual(E, Map.Key); | |
| 1197 | try testing.expectEqual(EnumIndexer(E), Map.Indexer); | |
| 1198 | try testing.expectEqual(usize, Map.Value); | |
| 1199 | try testing.expectEqual(@as(usize, 4), Map.len); | |
| 1200 | 1200 | |
| 1201 | 1201 | const b = Map.initFull(5); |
| 1202 | testing.expectEqual(@as(usize, 4), b.count()); | |
| 1203 | testing.expect(b.contains(.a)); | |
| 1204 | testing.expect(b.contains(.b)); | |
| 1205 | testing.expect(b.contains(.c)); | |
| 1206 | testing.expect(b.contains(.d)); | |
| 1207 | testing.expectEqual(@as(?usize, 5), b.get(.a)); | |
| 1208 | testing.expectEqual(@as(?usize, 5), b.get(.b)); | |
| 1209 | testing.expectEqual(@as(?usize, 5), b.get(.c)); | |
| 1210 | testing.expectEqual(@as(?usize, 5), b.get(.d)); | |
| 1202 | try testing.expectEqual(@as(usize, 4), b.count()); | |
| 1203 | try testing.expect(b.contains(.a)); | |
| 1204 | try testing.expect(b.contains(.b)); | |
| 1205 | try testing.expect(b.contains(.c)); | |
| 1206 | try testing.expect(b.contains(.d)); | |
| 1207 | try testing.expectEqual(@as(?usize, 5), b.get(.a)); | |
| 1208 | try testing.expectEqual(@as(?usize, 5), b.get(.b)); | |
| 1209 | try testing.expectEqual(@as(?usize, 5), b.get(.c)); | |
| 1210 | try testing.expectEqual(@as(?usize, 5), b.get(.d)); | |
| 1211 | 1211 | |
| 1212 | 1212 | const c = Map.initFullWith(.{ .a = 1, .b = 2, .c = 3, .d = 4 }); |
| 1213 | testing.expectEqual(@as(usize, 4), c.count()); | |
| 1214 | testing.expect(c.contains(.a)); | |
| 1215 | testing.expect(c.contains(.b)); | |
| 1216 | testing.expect(c.contains(.c)); | |
| 1217 | testing.expect(c.contains(.d)); | |
| 1218 | testing.expectEqual(@as(?usize, 1), c.get(.a)); | |
| 1219 | testing.expectEqual(@as(?usize, 2), c.get(.b)); | |
| 1220 | testing.expectEqual(@as(?usize, 3), c.get(.c)); | |
| 1221 | testing.expectEqual(@as(?usize, 4), c.get(.d)); | |
| 1213 | try testing.expectEqual(@as(usize, 4), c.count()); | |
| 1214 | try testing.expect(c.contains(.a)); | |
| 1215 | try testing.expect(c.contains(.b)); | |
| 1216 | try testing.expect(c.contains(.c)); | |
| 1217 | try testing.expect(c.contains(.d)); | |
| 1218 | try testing.expectEqual(@as(?usize, 1), c.get(.a)); | |
| 1219 | try testing.expectEqual(@as(?usize, 2), c.get(.b)); | |
| 1220 | try testing.expectEqual(@as(?usize, 3), c.get(.c)); | |
| 1221 | try testing.expectEqual(@as(?usize, 4), c.get(.d)); | |
| 1222 | 1222 | |
| 1223 | 1223 | const d = Map.initFullWithDefault(6, .{ .b = 2, .c = 4 }); |
| 1224 | testing.expectEqual(@as(usize, 4), d.count()); | |
| 1225 | testing.expect(d.contains(.a)); | |
| 1226 | testing.expect(d.contains(.b)); | |
| 1227 | testing.expect(d.contains(.c)); | |
| 1228 | testing.expect(d.contains(.d)); | |
| 1229 | testing.expectEqual(@as(?usize, 6), d.get(.a)); | |
| 1230 | testing.expectEqual(@as(?usize, 2), d.get(.b)); | |
| 1231 | testing.expectEqual(@as(?usize, 4), d.get(.c)); | |
| 1232 | testing.expectEqual(@as(?usize, 6), d.get(.d)); | |
| 1224 | try testing.expectEqual(@as(usize, 4), d.count()); | |
| 1225 | try testing.expect(d.contains(.a)); | |
| 1226 | try testing.expect(d.contains(.b)); | |
| 1227 | try testing.expect(d.contains(.c)); | |
| 1228 | try testing.expect(d.contains(.d)); | |
| 1229 | try testing.expectEqual(@as(?usize, 6), d.get(.a)); | |
| 1230 | try testing.expectEqual(@as(?usize, 2), d.get(.b)); | |
| 1231 | try testing.expectEqual(@as(?usize, 4), d.get(.c)); | |
| 1232 | try testing.expectEqual(@as(?usize, 6), d.get(.d)); | |
| 1233 | 1233 | |
| 1234 | 1234 | var a = Map.init(.{ .b = 2, .d = 4 }); |
| 1235 | testing.expectEqual(@as(usize, 2), a.count()); | |
| 1236 | testing.expectEqual(false, a.contains(.a)); | |
| 1237 | testing.expectEqual(true, a.contains(.b)); | |
| 1238 | testing.expectEqual(false, a.contains(.c)); | |
| 1239 | testing.expectEqual(true, a.contains(.d)); | |
| 1240 | ||
| 1241 | testing.expectEqual(@as(?usize, null), a.get(.a)); | |
| 1242 | testing.expectEqual(@as(?usize, 2), a.get(.b)); | |
| 1243 | testing.expectEqual(@as(?usize, null), a.get(.c)); | |
| 1244 | testing.expectEqual(@as(?usize, 4), a.get(.d)); | |
| 1245 | ||
| 1246 | testing.expectEqual(@as(?*usize, null), a.getPtr(.a)); | |
| 1247 | testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b)); | |
| 1248 | testing.expectEqual(@as(?*usize, null), a.getPtr(.c)); | |
| 1249 | testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d)); | |
| 1250 | ||
| 1251 | testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a)); | |
| 1252 | testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b)); | |
| 1253 | testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c)); | |
| 1254 | testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d)); | |
| 1255 | ||
| 1256 | testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b)); | |
| 1257 | testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d)); | |
| 1258 | testing.expectEqual(@as(usize, 2), a.getAssertContains(.b)); | |
| 1259 | testing.expectEqual(@as(usize, 4), a.getAssertContains(.d)); | |
| 1235 | try testing.expectEqual(@as(usize, 2), a.count()); | |
| 1236 | try testing.expectEqual(false, a.contains(.a)); | |
| 1237 | try testing.expectEqual(true, a.contains(.b)); | |
| 1238 | try testing.expectEqual(false, a.contains(.c)); | |
| 1239 | try testing.expectEqual(true, a.contains(.d)); | |
| 1240 | ||
| 1241 | try testing.expectEqual(@as(?usize, null), a.get(.a)); | |
| 1242 | try testing.expectEqual(@as(?usize, 2), a.get(.b)); | |
| 1243 | try testing.expectEqual(@as(?usize, null), a.get(.c)); | |
| 1244 | try testing.expectEqual(@as(?usize, 4), a.get(.d)); | |
| 1245 | ||
| 1246 | try testing.expectEqual(@as(?*usize, null), a.getPtr(.a)); | |
| 1247 | try testing.expectEqual(@as(?*usize, &a.values[1]), a.getPtr(.b)); | |
| 1248 | try testing.expectEqual(@as(?*usize, null), a.getPtr(.c)); | |
| 1249 | try testing.expectEqual(@as(?*usize, &a.values[3]), a.getPtr(.d)); | |
| 1250 | ||
| 1251 | try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.a)); | |
| 1252 | try testing.expectEqual(@as(?*const usize, &a.values[1]), a.getPtrConst(.b)); | |
| 1253 | try testing.expectEqual(@as(?*const usize, null), a.getPtrConst(.c)); | |
| 1254 | try testing.expectEqual(@as(?*const usize, &a.values[3]), a.getPtrConst(.d)); | |
| 1255 | ||
| 1256 | try testing.expectEqual(@as(*const usize, &a.values[1]), a.getPtrAssertContains(.b)); | |
| 1257 | try testing.expectEqual(@as(*const usize, &a.values[3]), a.getPtrAssertContains(.d)); | |
| 1258 | try testing.expectEqual(@as(usize, 2), a.getAssertContains(.b)); | |
| 1259 | try testing.expectEqual(@as(usize, 4), a.getAssertContains(.d)); | |
| 1260 | 1260 | |
| 1261 | 1261 | a.put(.a, 3); |
| 1262 | 1262 | a.put(.a, 5); |
| 1263 | 1263 | a.putUninitialized(.c).* = 7; |
| 1264 | 1264 | a.putUninitialized(.c).* = 9; |
| 1265 | 1265 | |
| 1266 | testing.expectEqual(@as(usize, 4), a.count()); | |
| 1267 | testing.expectEqual(@as(?usize, 5), a.get(.a)); | |
| 1268 | testing.expectEqual(@as(?usize, 2), a.get(.b)); | |
| 1269 | testing.expectEqual(@as(?usize, 9), a.get(.c)); | |
| 1270 | testing.expectEqual(@as(?usize, 4), a.get(.d)); | |
| 1266 | try testing.expectEqual(@as(usize, 4), a.count()); | |
| 1267 | try testing.expectEqual(@as(?usize, 5), a.get(.a)); | |
| 1268 | try testing.expectEqual(@as(?usize, 2), a.get(.b)); | |
| 1269 | try testing.expectEqual(@as(?usize, 9), a.get(.c)); | |
| 1270 | try testing.expectEqual(@as(?usize, 4), a.get(.d)); | |
| 1271 | 1271 | |
| 1272 | 1272 | a.remove(.a); |
| 1273 | testing.expectEqual(@as(?usize, null), a.fetchRemove(.a)); | |
| 1274 | testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c)); | |
| 1273 | try testing.expectEqual(@as(?usize, null), a.fetchRemove(.a)); | |
| 1274 | try testing.expectEqual(@as(?usize, 9), a.fetchRemove(.c)); | |
| 1275 | 1275 | a.remove(.c); |
| 1276 | 1276 | |
| 1277 | 1277 | var iter = a.iterator(); |
| 1278 | 1278 | const Entry = Map.Entry; |
| 1279 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1279 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1280 | 1280 | .key = .b, |
| 1281 | 1281 | .value = &a.values[1], |
| 1282 | 1282 | }), iter.next()); |
| 1283 | testing.expectEqual(@as(?Entry, Entry{ | |
| 1283 | try testing.expectEqual(@as(?Entry, Entry{ | |
| 1284 | 1284 | .key = .d, |
| 1285 | 1285 | .value = &a.values[3], |
| 1286 | 1286 | }), iter.next()); |
| 1287 | testing.expectEqual(@as(?Entry, null), iter.next()); | |
| 1287 | try testing.expectEqual(@as(?Entry, null), iter.next()); | |
| 1288 | 1288 | } |
lib/std/event/batch.zig+2-2| ... | ... | @@ -119,12 +119,12 @@ test "std.event.Batch" { |
| 119 | 119 | batch.add(&async sleepALittle(&count)); |
| 120 | 120 | batch.add(&async increaseByTen(&count)); |
| 121 | 121 | batch.wait(); |
| 122 | testing.expect(count == 11); | |
| 122 | try testing.expect(count == 11); | |
| 123 | 123 | |
| 124 | 124 | var another = Batch(anyerror!void, 2, .auto_async).init(); |
| 125 | 125 | another.add(&async somethingElse()); |
| 126 | 126 | another.add(&async doSomethingThatFails()); |
| 127 | testing.expectError(error.ItBroke, another.wait()); | |
| 127 | try testing.expectError(error.ItBroke, another.wait()); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | fn sleepALittle(count: *usize) void { |
lib/std/event/channel.zig+7-7| ... | ... | @@ -310,25 +310,25 @@ test "std.event.Channel wraparound" { |
| 310 | 310 | // the buffer wraps around, make sure it doesn't crash. |
| 311 | 311 | var result: i32 = undefined; |
| 312 | 312 | channel.put(5); |
| 313 | testing.expectEqual(@as(i32, 5), channel.get()); | |
| 313 | try testing.expectEqual(@as(i32, 5), channel.get()); | |
| 314 | 314 | channel.put(6); |
| 315 | testing.expectEqual(@as(i32, 6), channel.get()); | |
| 315 | try testing.expectEqual(@as(i32, 6), channel.get()); | |
| 316 | 316 | channel.put(7); |
| 317 | testing.expectEqual(@as(i32, 7), channel.get()); | |
| 317 | try testing.expectEqual(@as(i32, 7), channel.get()); | |
| 318 | 318 | } |
| 319 | 319 | fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void { |
| 320 | 320 | const value1 = channel.get(); |
| 321 | testing.expect(value1 == 1234); | |
| 321 | try testing.expect(value1 == 1234); | |
| 322 | 322 | |
| 323 | 323 | const value2 = channel.get(); |
| 324 | testing.expect(value2 == 4567); | |
| 324 | try testing.expect(value2 == 4567); | |
| 325 | 325 | |
| 326 | 326 | const value3 = channel.getOrNull(); |
| 327 | testing.expect(value3 == null); | |
| 327 | try testing.expect(value3 == null); | |
| 328 | 328 | |
| 329 | 329 | var last_put = async testPut(channel, 4444); |
| 330 | 330 | const value4 = channel.getOrNull(); |
| 331 | testing.expect(value4.? == 4444); | |
| 331 | try testing.expect(value4.? == 4444); | |
| 332 | 332 | await last_put; |
| 333 | 333 | } |
| 334 | 334 | fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void { |
lib/std/event/future.zig+1-1| ... | ... | @@ -107,7 +107,7 @@ fn testFuture() void { |
| 107 | 107 | |
| 108 | 108 | const result = (await a) + (await b); |
| 109 | 109 | |
| 110 | testing.expect(result == 12); | |
| 110 | try testing.expect(result == 12); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | fn waitOnFuture(future: *Future(i32)) i32 { |
lib/std/event/group.zig+2-2| ... | ... | @@ -140,14 +140,14 @@ fn testGroup(allocator: *Allocator) callconv(.Async) void { |
| 140 | 140 | var increase_by_ten_frame = async increaseByTen(&count); |
| 141 | 141 | group.add(&increase_by_ten_frame) catch @panic("memory"); |
| 142 | 142 | group.wait(); |
| 143 | testing.expect(count == 11); | |
| 143 | try testing.expect(count == 11); | |
| 144 | 144 | |
| 145 | 145 | var another = Group(anyerror!void).init(allocator); |
| 146 | 146 | var something_else_frame = async somethingElse(); |
| 147 | 147 | another.add(&something_else_frame) catch @panic("memory"); |
| 148 | 148 | var something_that_fails_frame = async doSomethingThatFails(); |
| 149 | 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 | } |
| 152 | 152 | fn sleepALittle(count: *usize) callconv(.Async) void { |
| 153 | 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 | 136 | testLock(&lock); |
| 137 | 137 | |
| 138 | 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 | } |
| 141 | 141 | fn testLock(lock: *Lock) void { |
| 142 | 142 | var handle1 = async lockRunner(lock); |
lib/std/event/loop.zig+3-3| ... | ... | @@ -1655,7 +1655,7 @@ fn testEventLoop() i32 { |
| 1655 | 1655 | |
| 1656 | 1656 | fn testEventLoop2(h: anyframe->i32, did_it: *bool) void { |
| 1657 | 1657 | const value = await h; |
| 1658 | testing.expect(value == 1234); | |
| 1658 | try testing.expect(value == 1234); | |
| 1659 | 1659 | did_it.* = true; |
| 1660 | 1660 | } |
| 1661 | 1661 | |
| ... | ... | @@ -1682,7 +1682,7 @@ test "std.event.Loop - runDetached" { |
| 1682 | 1682 | // with the previous runDetached. |
| 1683 | 1683 | loop.run(); |
| 1684 | 1684 | |
| 1685 | testing.expect(testRunDetachedData == 1); | |
| 1685 | try testing.expect(testRunDetachedData == 1); | |
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | fn testRunDetached() void { |
| ... | ... | @@ -1705,7 +1705,7 @@ test "std.event.Loop - sleep" { |
| 1705 | 1705 | for (frames) |*frame| |
| 1706 | 1706 | await frame; |
| 1707 | 1707 | |
| 1708 | testing.expect(sleep_count == frames.len); | |
| 1708 | try testing.expect(sleep_count == frames.len); | |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | fn testSleep(wait_ns: u64, sleep_count: *usize) void { |
lib/std/event/rwlock.zig+3-3| ... | ... | @@ -228,7 +228,7 @@ test "std.event.RwLock" { |
| 228 | 228 | const handle = testLock(std.heap.page_allocator, &lock); |
| 229 | 229 | |
| 230 | 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 | } |
| 233 | 233 | fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void { |
| 234 | 234 | var read_nodes: [100]Loop.NextTickNode = undefined; |
| ... | ... | @@ -290,7 +290,7 @@ fn readRunner(lock: *RwLock) callconv(.Async) void { |
| 290 | 290 | const handle = await lock_promise; |
| 291 | 291 | defer handle.release(); |
| 292 | 292 | |
| 293 | testing.expect(shared_test_index == 0); | |
| 294 | testing.expect(shared_test_data[i] == @intCast(i32, shared_count)); | |
| 293 | try testing.expect(shared_test_index == 0); | |
| 294 | try testing.expect(shared_test_data[i] == @intCast(i32, shared_count)); | |
| 295 | 295 | } |
| 296 | 296 | } |
lib/std/fifo.zig+38-38| ... | ... | @@ -402,59 +402,59 @@ test "LinearFifo(u8, .Dynamic)" { |
| 402 | 402 | defer fifo.deinit(); |
| 403 | 403 | |
| 404 | 404 | try fifo.write("HELLO"); |
| 405 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 406 | testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); | |
| 405 | try testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 406 | try testing.expectEqualSlices(u8, "HELLO", fifo.readableSlice(0)); | |
| 407 | 407 | |
| 408 | 408 | { |
| 409 | 409 | var i: usize = 0; |
| 410 | 410 | while (i < 5) : (i += 1) { |
| 411 | 411 | try fifo.write(&[_]u8{fifo.peekItem(i)}); |
| 412 | 412 | } |
| 413 | testing.expectEqual(@as(usize, 10), fifo.readableLength()); | |
| 414 | testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); | |
| 413 | try testing.expectEqual(@as(usize, 10), fifo.readableLength()); | |
| 414 | try testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0)); | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | { |
| 418 | testing.expectEqual(@as(u8, 'H'), fifo.readItem().?); | |
| 419 | testing.expectEqual(@as(u8, 'E'), fifo.readItem().?); | |
| 420 | testing.expectEqual(@as(u8, 'L'), fifo.readItem().?); | |
| 421 | testing.expectEqual(@as(u8, 'L'), fifo.readItem().?); | |
| 422 | testing.expectEqual(@as(u8, 'O'), fifo.readItem().?); | |
| 418 | try testing.expectEqual(@as(u8, 'H'), fifo.readItem().?); | |
| 419 | try testing.expectEqual(@as(u8, 'E'), fifo.readItem().?); | |
| 420 | try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?); | |
| 421 | try testing.expectEqual(@as(u8, 'L'), fifo.readItem().?); | |
| 422 | try testing.expectEqual(@as(u8, 'O'), fifo.readItem().?); | |
| 423 | 423 | } |
| 424 | testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 424 | try testing.expectEqual(@as(usize, 5), fifo.readableLength()); | |
| 425 | 425 | |
| 426 | 426 | { // Writes that wrap around |
| 427 | testing.expectEqual(@as(usize, 11), fifo.writableLength()); | |
| 428 | testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len); | |
| 427 | try testing.expectEqual(@as(usize, 11), fifo.writableLength()); | |
| 428 | try testing.expectEqual(@as(usize, 6), fifo.writableSlice(0).len); | |
| 429 | 429 | fifo.writeAssumeCapacity("6<chars<11"); |
| 430 | testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0)); | |
| 431 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11)); | |
| 432 | testing.expectEqualSlices(u8, "11", fifo.readableSlice(13)); | |
| 433 | testing.expectEqualSlices(u8, "", fifo.readableSlice(15)); | |
| 430 | try testing.expectEqualSlices(u8, "HELLO6<char", fifo.readableSlice(0)); | |
| 431 | try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(11)); | |
| 432 | try testing.expectEqualSlices(u8, "11", fifo.readableSlice(13)); | |
| 433 | try testing.expectEqualSlices(u8, "", fifo.readableSlice(15)); | |
| 434 | 434 | fifo.discard(11); |
| 435 | testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0)); | |
| 435 | try testing.expectEqualSlices(u8, "s<11", fifo.readableSlice(0)); | |
| 436 | 436 | fifo.discard(4); |
| 437 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 437 | try testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | { |
| 441 | 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 | 443 | var i: u8 = 0; |
| 444 | 444 | while (i < 10) : (i += 1) { |
| 445 | 445 | buf[i] = i + 'a'; |
| 446 | 446 | } |
| 447 | 447 | fifo.update(10); |
| 448 | testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0)); | |
| 448 | try testing.expectEqualSlices(u8, "abcdefghij", fifo.readableSlice(0)); | |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | { |
| 452 | 452 | try fifo.unget("prependedstring"); |
| 453 | 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 | 455 | try fifo.unget("b"); |
| 456 | 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 | } |
| 459 | 459 | |
| 460 | 460 | fifo.shrink(0); |
| ... | ... | @@ -462,17 +462,17 @@ test "LinearFifo(u8, .Dynamic)" { |
| 462 | 462 | { |
| 463 | 463 | try fifo.writer().print("{s}, {s}!", .{ "Hello", "World" }); |
| 464 | 464 | var result: [30]u8 = undefined; |
| 465 | testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); | |
| 466 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 465 | try testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); | |
| 466 | try testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | { |
| 470 | 470 | try fifo.writer().writeAll("This is a test"); |
| 471 | 471 | var result: [30]u8 = undefined; |
| 472 | testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 473 | testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 474 | testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 475 | testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 472 | try testing.expectEqualSlices(u8, "This", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 473 | try testing.expectEqualSlices(u8, "is", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 474 | try testing.expectEqualSlices(u8, "a", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 475 | try testing.expectEqualSlices(u8, "test", (try fifo.reader().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | { |
| ... | ... | @@ -481,7 +481,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 481 | 481 | var out_buf: [50]u8 = undefined; |
| 482 | 482 | var out_fbs = std.io.fixedBufferStream(&out_buf); |
| 483 | 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 | } |
| 487 | 487 | |
| ... | ... | @@ -498,28 +498,28 @@ test "LinearFifo" { |
| 498 | 498 | defer fifo.deinit(); |
| 499 | 499 | |
| 500 | 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()); | |
| 502 | 502 | |
| 503 | 503 | { |
| 504 | testing.expectEqual(@as(T, 0), fifo.readItem().?); | |
| 505 | testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 506 | testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 507 | testing.expectEqual(@as(T, 0), fifo.readItem().?); | |
| 508 | testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 509 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 504 | try testing.expectEqual(@as(T, 0), fifo.readItem().?); | |
| 505 | try testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 506 | try testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 507 | try testing.expectEqual(@as(T, 0), fifo.readItem().?); | |
| 508 | try testing.expectEqual(@as(T, 1), fifo.readItem().?); | |
| 509 | try testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | { |
| 513 | 513 | try fifo.writeItem(1); |
| 514 | 514 | try fifo.writeItem(1); |
| 515 | 515 | try fifo.writeItem(1); |
| 516 | testing.expectEqual(@as(usize, 3), fifo.readableLength()); | |
| 516 | try testing.expectEqual(@as(usize, 3), fifo.readableLength()); | |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | { |
| 520 | 520 | var readBuf: [3]T = undefined; |
| 521 | 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+77-77| ... | ... | @@ -1422,7 +1422,7 @@ test "fmtDuration" { |
| 1422 | 1422 | .{ .s = "1y1m999ns", .d = 365 * std.time.ns_per_day + std.time.ns_per_min + 999 }, |
| 1423 | 1423 | }) |tc| { |
| 1424 | 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 | } |
| 1428 | 1428 | |
| ... | ... | @@ -1478,44 +1478,44 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) ParseIntError!T { |
| 1478 | 1478 | } |
| 1479 | 1479 | |
| 1480 | 1480 | test "parseInt" { |
| 1481 | std.testing.expect((try parseInt(i32, "-10", 10)) == -10); | |
| 1482 | std.testing.expect((try parseInt(i32, "+10", 10)) == 10); | |
| 1483 | std.testing.expect((try parseInt(u32, "+10", 10)) == 10); | |
| 1484 | std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10)); | |
| 1485 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10)); | |
| 1486 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10)); | |
| 1487 | std.testing.expect((try parseInt(u8, "255", 10)) == 255); | |
| 1488 | std.testing.expectError(error.Overflow, parseInt(u8, "256", 10)); | |
| 1481 | try std.testing.expect((try parseInt(i32, "-10", 10)) == -10); | |
| 1482 | try std.testing.expect((try parseInt(i32, "+10", 10)) == 10); | |
| 1483 | try std.testing.expect((try parseInt(u32, "+10", 10)) == 10); | |
| 1484 | try std.testing.expectError(error.Overflow, parseInt(u32, "-10", 10)); | |
| 1485 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, " 10", 10)); | |
| 1486 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "10 ", 10)); | |
| 1487 | try std.testing.expect((try parseInt(u8, "255", 10)) == 255); | |
| 1488 | try std.testing.expectError(error.Overflow, parseInt(u8, "256", 10)); | |
| 1489 | 1489 | |
| 1490 | 1490 | // +0 and -0 should work for unsigned |
| 1491 | std.testing.expect((try parseInt(u8, "-0", 10)) == 0); | |
| 1492 | std.testing.expect((try parseInt(u8, "+0", 10)) == 0); | |
| 1491 | try std.testing.expect((try parseInt(u8, "-0", 10)) == 0); | |
| 1492 | try std.testing.expect((try parseInt(u8, "+0", 10)) == 0); | |
| 1493 | 1493 | |
| 1494 | 1494 | // ensure minInt is parsed correctly |
| 1495 | std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8)); | |
| 1496 | std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43)); | |
| 1495 | try std.testing.expect((try parseInt(i8, "-128", 10)) == math.minInt(i8)); | |
| 1496 | try std.testing.expect((try parseInt(i43, "-4398046511104", 10)) == math.minInt(i43)); | |
| 1497 | 1497 | |
| 1498 | 1498 | // empty string or bare +- is invalid |
| 1499 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10)); | |
| 1500 | std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10)); | |
| 1501 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10)); | |
| 1502 | std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10)); | |
| 1503 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10)); | |
| 1504 | std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10)); | |
| 1499 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "", 10)); | |
| 1500 | try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "", 10)); | |
| 1501 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "+", 10)); | |
| 1502 | try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "+", 10)); | |
| 1503 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "-", 10)); | |
| 1504 | try std.testing.expectError(error.InvalidCharacter, parseInt(i32, "-", 10)); | |
| 1505 | 1505 | |
| 1506 | 1506 | // autodectect the radix |
| 1507 | std.testing.expect((try parseInt(i32, "111", 0)) == 111); | |
| 1508 | std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7); | |
| 1509 | std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73); | |
| 1510 | std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273); | |
| 1511 | std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7); | |
| 1512 | std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73); | |
| 1513 | std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273); | |
| 1507 | try std.testing.expect((try parseInt(i32, "111", 0)) == 111); | |
| 1508 | try std.testing.expect((try parseInt(i32, "+0b111", 0)) == 7); | |
| 1509 | try std.testing.expect((try parseInt(i32, "+0o111", 0)) == 73); | |
| 1510 | try std.testing.expect((try parseInt(i32, "+0x111", 0)) == 273); | |
| 1511 | try std.testing.expect((try parseInt(i32, "-0b111", 0)) == -7); | |
| 1512 | try std.testing.expect((try parseInt(i32, "-0o111", 0)) == -73); | |
| 1513 | try std.testing.expect((try parseInt(i32, "-0x111", 0)) == -273); | |
| 1514 | 1514 | |
| 1515 | 1515 | // bare binary/octal/decimal prefix is invalid |
| 1516 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0)); | |
| 1517 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0)); | |
| 1518 | std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0)); | |
| 1516 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0b", 0)); | |
| 1517 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0o", 0)); | |
| 1518 | try std.testing.expectError(error.InvalidCharacter, parseInt(u32, "0x", 0)); | |
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | fn parseWithSign( |
| ... | ... | @@ -1583,37 +1583,37 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseIntError |
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | test "parseUnsigned" { |
| 1586 | std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124); | |
| 1587 | std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535); | |
| 1588 | std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10)); | |
| 1586 | try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124); | |
| 1587 | try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535); | |
| 1588 | try std.testing.expectError(error.Overflow, parseUnsigned(u16, "65536", 10)); | |
| 1589 | 1589 | |
| 1590 | std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff); | |
| 1591 | std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16)); | |
| 1590 | try std.testing.expect((try parseUnsigned(u64, "0ffffffffffffffff", 16)) == 0xffffffffffffffff); | |
| 1591 | try std.testing.expectError(error.Overflow, parseUnsigned(u64, "10000000000000000", 16)); | |
| 1592 | 1592 | |
| 1593 | std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF); | |
| 1593 | try std.testing.expect((try parseUnsigned(u32, "DeadBeef", 16)) == 0xDEADBEEF); | |
| 1594 | 1594 | |
| 1595 | std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1); | |
| 1596 | std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8); | |
| 1595 | try std.testing.expect((try parseUnsigned(u7, "1", 10)) == 1); | |
| 1596 | try std.testing.expect((try parseUnsigned(u7, "1000", 2)) == 8); | |
| 1597 | 1597 | |
| 1598 | std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10)); | |
| 1599 | std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8)); | |
| 1598 | try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u32, "f", 10)); | |
| 1599 | try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "109", 8)); | |
| 1600 | 1600 | |
| 1601 | std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747); | |
| 1601 | try std.testing.expect((try parseUnsigned(u32, "NUMBER", 36)) == 1442151747); | |
| 1602 | 1602 | |
| 1603 | 1603 | // these numbers should fit even though the radix itself doesn't fit in the destination type |
| 1604 | std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0); | |
| 1605 | std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1); | |
| 1606 | std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10)); | |
| 1607 | std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1); | |
| 1608 | std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3); | |
| 1609 | std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16)); | |
| 1604 | try std.testing.expect((try parseUnsigned(u1, "0", 10)) == 0); | |
| 1605 | try std.testing.expect((try parseUnsigned(u1, "1", 10)) == 1); | |
| 1606 | try std.testing.expectError(error.Overflow, parseUnsigned(u1, "2", 10)); | |
| 1607 | try std.testing.expect((try parseUnsigned(u1, "001", 16)) == 1); | |
| 1608 | try std.testing.expect((try parseUnsigned(u2, "3", 16)) == 3); | |
| 1609 | try std.testing.expectError(error.Overflow, parseUnsigned(u2, "4", 16)); | |
| 1610 | 1610 | |
| 1611 | 1611 | // parseUnsigned does not expect a sign |
| 1612 | std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10)); | |
| 1613 | std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10)); | |
| 1612 | try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "+0", 10)); | |
| 1613 | try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "-0", 10)); | |
| 1614 | 1614 | |
| 1615 | 1615 | // test empty string error |
| 1616 | std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10)); | |
| 1616 | try std.testing.expectError(error.InvalidCharacter, parseUnsigned(u8, "", 10)); | |
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | pub const parseFloat = @import("fmt/parse_float.zig").parseFloat; |
| ... | ... | @@ -1692,21 +1692,21 @@ test "bufPrintInt" { |
| 1692 | 1692 | var buffer: [100]u8 = undefined; |
| 1693 | 1693 | const buf = buffer[0..]; |
| 1694 | 1694 | |
| 1695 | std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{})); | |
| 1695 | try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{})); | |
| 1696 | 1696 | |
| 1697 | std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{})); | |
| 1698 | std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{})); | |
| 1699 | std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{})); | |
| 1700 | std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{})); | |
| 1697 | try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{})); | |
| 1698 | try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{})); | |
| 1699 | try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{})); | |
| 1700 | try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{})); | |
| 1701 | 1701 | |
| 1702 | std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{})); | |
| 1702 | try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{})); | |
| 1703 | 1703 | |
| 1704 | std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 })); | |
| 1705 | std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 })); | |
| 1706 | std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 })); | |
| 1704 | try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 })); | |
| 1705 | try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 })); | |
| 1706 | try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 })); | |
| 1707 | 1707 | |
| 1708 | std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 })); | |
| 1709 | std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 })); | |
| 1708 | try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 })); | |
| 1709 | try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 })); | |
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 { |
| ... | ... | @@ -1724,8 +1724,8 @@ pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, |
| 1724 | 1724 | |
| 1725 | 1725 | test "comptimePrint" { |
| 1726 | 1726 | @setEvalBranchQuota(2000); |
| 1727 | std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100}))); | |
| 1728 | std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); | |
| 1727 | try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100}))); | |
| 1728 | try std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); | |
| 1729 | 1729 | } |
| 1730 | 1730 | |
| 1731 | 1731 | test "parse u64 digit too big" { |
| ... | ... | @@ -1738,7 +1738,7 @@ test "parse u64 digit too big" { |
| 1738 | 1738 | |
| 1739 | 1739 | test "parse unsigned comptime" { |
| 1740 | 1740 | comptime { |
| 1741 | std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2); | |
| 1741 | try std.testing.expect((try parseUnsigned(usize, "2", 10)) == 2); | |
| 1742 | 1742 | } |
| 1743 | 1743 | } |
| 1744 | 1744 | |
| ... | ... | @@ -1835,15 +1835,15 @@ test "buffer" { |
| 1835 | 1835 | var buf1: [32]u8 = undefined; |
| 1836 | 1836 | var fbs = std.io.fixedBufferStream(&buf1); |
| 1837 | 1837 | try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth); |
| 1838 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234")); | |
| 1838 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234")); | |
| 1839 | 1839 | |
| 1840 | 1840 | fbs.reset(); |
| 1841 | 1841 | try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth); |
| 1842 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "a")); | |
| 1842 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a")); | |
| 1843 | 1843 | |
| 1844 | 1844 | fbs.reset(); |
| 1845 | 1845 | try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth); |
| 1846 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100")); | |
| 1846 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100")); | |
| 1847 | 1847 | } |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| ... | ... | @@ -2170,10 +2170,10 @@ test "union" { |
| 2170 | 2170 | |
| 2171 | 2171 | var buf: [100]u8 = undefined; |
| 2172 | 2172 | const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst}); |
| 2173 | std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); | |
| 2173 | try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); | |
| 2174 | 2174 | |
| 2175 | 2175 | const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst}); |
| 2176 | std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); | |
| 2176 | try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@")); | |
| 2177 | 2177 | } |
| 2178 | 2178 | |
| 2179 | 2179 | test "enum" { |
| ... | ... | @@ -2256,9 +2256,9 @@ test "hexToBytes" { |
| 2256 | 2256 | try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))}); |
| 2257 | 2257 | try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))}); |
| 2258 | 2258 | try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))}); |
| 2259 | std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); | |
| 2260 | std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA")); | |
| 2261 | std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB")); | |
| 2259 | try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); | |
| 2260 | try std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA")); | |
| 2261 | try std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB")); | |
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | test "formatIntValue with comptime_int" { |
| ... | ... | @@ -2267,7 +2267,7 @@ test "formatIntValue with comptime_int" { |
| 2267 | 2267 | var buf: [20]u8 = undefined; |
| 2268 | 2268 | var fbs = std.io.fixedBufferStream(&buf); |
| 2269 | 2269 | try formatIntValue(value, "", FormatOptions{}, fbs.writer()); |
| 2270 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789")); | |
| 2270 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789")); | |
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | test "formatFloatValue with comptime_float" { |
| ... | ... | @@ -2276,7 +2276,7 @@ test "formatFloatValue with comptime_float" { |
| 2276 | 2276 | var buf: [20]u8 = undefined; |
| 2277 | 2277 | var fbs = std.io.fixedBufferStream(&buf); |
| 2278 | 2278 | try formatFloatValue(value, "", FormatOptions{}, fbs.writer()); |
| 2279 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00")); | |
| 2279 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1.0e+00")); | |
| 2280 | 2280 | |
| 2281 | 2281 | try expectFmt("1.0e+00", "{}", .{value}); |
| 2282 | 2282 | try expectFmt("1.0e+00", "{}", .{1.0}); |
| ... | ... | @@ -2332,19 +2332,19 @@ test "formatType max_depth" { |
| 2332 | 2332 | var buf: [1000]u8 = undefined; |
| 2333 | 2333 | var fbs = std.io.fixedBufferStream(&buf); |
| 2334 | 2334 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 0); |
| 2335 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }")); | |
| 2335 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }")); | |
| 2336 | 2336 | |
| 2337 | 2337 | fbs.reset(); |
| 2338 | 2338 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 1); |
| 2339 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); | |
| 2339 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); | |
| 2340 | 2340 | |
| 2341 | 2341 | fbs.reset(); |
| 2342 | 2342 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 2); |
| 2343 | 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) }")); | |
| 2343 | 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) }")); | |
| 2344 | 2344 | |
| 2345 | 2345 | fbs.reset(); |
| 2346 | 2346 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 3); |
| 2347 | 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) }")); | |
| 2347 | 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) }")); | |
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | 2350 | test "positional" { |
lib/std/fmt/parse_float.zig+29-29| ... | ... | @@ -376,44 +376,44 @@ test "fmt.parseFloat" { |
| 376 | 376 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
| 377 | 377 | const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 378 | 378 | |
| 379 | testing.expectError(error.InvalidCharacter, parseFloat(T, "")); | |
| 380 | testing.expectError(error.InvalidCharacter, parseFloat(T, " 1")); | |
| 381 | testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc")); | |
| 382 | testing.expectError(error.InvalidCharacter, parseFloat(T, "+")); | |
| 383 | testing.expectError(error.InvalidCharacter, parseFloat(T, "-")); | |
| 379 | try testing.expectError(error.InvalidCharacter, parseFloat(T, "")); | |
| 380 | try testing.expectError(error.InvalidCharacter, parseFloat(T, " 1")); | |
| 381 | try testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc")); | |
| 382 | try testing.expectError(error.InvalidCharacter, parseFloat(T, "+")); | |
| 383 | try testing.expectError(error.InvalidCharacter, parseFloat(T, "-")); | |
| 384 | 384 | |
| 385 | expectEqual(try parseFloat(T, "0"), 0.0); | |
| 386 | expectEqual(try parseFloat(T, "0"), 0.0); | |
| 387 | expectEqual(try parseFloat(T, "+0"), 0.0); | |
| 388 | expectEqual(try parseFloat(T, "-0"), 0.0); | |
| 385 | try expectEqual(try parseFloat(T, "0"), 0.0); | |
| 386 | try expectEqual(try parseFloat(T, "0"), 0.0); | |
| 387 | try expectEqual(try parseFloat(T, "+0"), 0.0); | |
| 388 | try expectEqual(try parseFloat(T, "-0"), 0.0); | |
| 389 | 389 | |
| 390 | expectEqual(try parseFloat(T, "0e0"), 0); | |
| 391 | expectEqual(try parseFloat(T, "2e3"), 2000.0); | |
| 392 | expectEqual(try parseFloat(T, "1e0"), 1.0); | |
| 393 | expectEqual(try parseFloat(T, "-2e3"), -2000.0); | |
| 394 | expectEqual(try parseFloat(T, "-1e0"), -1.0); | |
| 395 | expectEqual(try parseFloat(T, "1.234e3"), 1234); | |
| 390 | try expectEqual(try parseFloat(T, "0e0"), 0); | |
| 391 | try expectEqual(try parseFloat(T, "2e3"), 2000.0); | |
| 392 | try expectEqual(try parseFloat(T, "1e0"), 1.0); | |
| 393 | try expectEqual(try parseFloat(T, "-2e3"), -2000.0); | |
| 394 | try expectEqual(try parseFloat(T, "-1e0"), -1.0); | |
| 395 | try expectEqual(try parseFloat(T, "1.234e3"), 1234); | |
| 396 | 396 | |
| 397 | expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon)); | |
| 398 | expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon)); | |
| 397 | try expect(approxEqAbs(T, try parseFloat(T, "3.141"), 3.141, epsilon)); | |
| 398 | try expect(approxEqAbs(T, try parseFloat(T, "-3.141"), -3.141, epsilon)); | |
| 399 | 399 | |
| 400 | expectEqual(try parseFloat(T, "1e-700"), 0); | |
| 401 | expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T)); | |
| 400 | try expectEqual(try parseFloat(T, "1e-700"), 0); | |
| 401 | try expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T)); | |
| 402 | 402 | |
| 403 | expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T))); | |
| 404 | expectEqual(try parseFloat(T, "inF"), std.math.inf(T)); | |
| 405 | expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T)); | |
| 403 | try expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T))); | |
| 404 | try expectEqual(try parseFloat(T, "inF"), std.math.inf(T)); | |
| 405 | try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T)); | |
| 406 | 406 | |
| 407 | expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T)); | |
| 407 | try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T)); | |
| 408 | 408 | |
| 409 | 409 | if (T != f16) { |
| 410 | expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon)); | |
| 411 | expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon)); | |
| 410 | try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon)); | |
| 411 | try expect(approxEqAbs(T, try parseFloat(T, "1234e-2"), 12.34, epsilon)); | |
| 412 | 412 | |
| 413 | expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); | |
| 414 | expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon)); | |
| 415 | expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon)); | |
| 416 | expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon)); | |
| 413 | try expect(approxEqAbs(T, try parseFloat(T, "123142.1"), 123142.1, epsilon)); | |
| 414 | try expect(approxEqAbs(T, try parseFloat(T, "-123142.1124"), @as(T, -123142.1124), epsilon)); | |
| 415 | try expect(approxEqAbs(T, try parseFloat(T, "0.7062146892655368"), @as(T, 0.7062146892655368), epsilon)); | |
| 416 | try expect(approxEqAbs(T, try parseFloat(T, "2.71828182845904523536"), @as(T, 2.718281828459045), epsilon)); | |
| 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 | 247 | } |
| 248 | 248 | |
| 249 | 249 | test "special" { |
| 250 | testing.expect(math.isNan(try parseHexFloat(f32, "nAn"))); | |
| 251 | testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf"))); | |
| 252 | testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf"))); | |
| 253 | testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf"))); | |
| 250 | try testing.expect(math.isNan(try parseHexFloat(f32, "nAn"))); | |
| 251 | try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "iNf"))); | |
| 252 | try testing.expect(math.isPositiveInf(try parseHexFloat(f32, "+Inf"))); | |
| 253 | try testing.expect(math.isNegativeInf(try parseHexFloat(f32, "-iNf"))); | |
| 254 | 254 | } |
| 255 | 255 | test "zero" { |
| 256 | testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0")); | |
| 257 | testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0")); | |
| 258 | testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42")); | |
| 259 | testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42")); | |
| 260 | testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666")); | |
| 256 | try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0")); | |
| 257 | try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0")); | |
| 258 | try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0p42")); | |
| 259 | try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "-0x0.00000p42")); | |
| 260 | try testing.expectEqual(@as(f32, 0.0), try parseHexFloat(f32, "0x0.00000p666")); | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | test "f16" { |
| ... | ... | @@ -279,7 +279,7 @@ test "f16" { |
| 279 | 279 | }; |
| 280 | 280 | |
| 281 | 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 | } |
| 285 | 285 | test "f32" { |
| ... | ... | @@ -303,7 +303,7 @@ test "f32" { |
| 303 | 303 | }; |
| 304 | 304 | |
| 305 | 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 | } |
| 309 | 309 | test "f64" { |
| ... | ... | @@ -325,7 +325,7 @@ test "f64" { |
| 325 | 325 | }; |
| 326 | 326 | |
| 327 | 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 | } |
| 331 | 331 | test "f128" { |
| ... | ... | @@ -347,6 +347,6 @@ test "f128" { |
| 347 | 347 | }; |
| 348 | 348 | |
| 349 | 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 | 96 | return out[0 .. out.len - 1 :0]; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) void { | |
| 99 | fn testJoinMaybeZWindows(paths: []const []const u8, expected: []const u8, zero: bool) !void { | |
| 100 | 100 | const windowsIsSep = struct { |
| 101 | 101 | fn isSep(byte: u8) bool { |
| 102 | 102 | return byte == '/' or byte == '\\'; |
| 103 | 103 | } |
| 104 | 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 | 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 | } |
| 109 | 109 | |
| 110 | fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) void { | |
| 110 | fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bool) !void { | |
| 111 | 111 | const posixIsSep = struct { |
| 112 | 112 | fn isSep(byte: u8) bool { |
| 113 | 113 | return byte == '/'; |
| 114 | 114 | } |
| 115 | 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 | 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 | } |
| 120 | 120 | |
| 121 | 121 | test "join" { |
| 122 | 122 | { |
| 123 | 123 | const actual: []u8 = try join(testing.allocator, &[_][]const u8{}); |
| 124 | 124 | defer testing.allocator.free(actual); |
| 125 | testing.expectEqualSlices(u8, "", actual); | |
| 125 | try testing.expectEqualSlices(u8, "", actual); | |
| 126 | 126 | } |
| 127 | 127 | { |
| 128 | 128 | const actual: [:0]u8 = try joinZ(testing.allocator, &[_][]const u8{}); |
| 129 | 129 | defer testing.allocator.free(actual); |
| 130 | testing.expectEqualSlices(u8, "", actual); | |
| 130 | try testing.expectEqualSlices(u8, "", actual); | |
| 131 | 131 | } |
| 132 | 132 | for (&[_]bool{ false, true }) |zero| { |
| 133 | testJoinMaybeZWindows(&[_][]const u8{}, "", zero); | |
| 134 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); | |
| 135 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); | |
| 136 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 133 | try testJoinMaybeZWindows(&[_][]const u8{}, "", zero); | |
| 134 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); | |
| 135 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c", zero); | |
| 136 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 137 | 137 | |
| 138 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 139 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 138 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 139 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero); | |
| 140 | 140 | |
| 141 | testJoinMaybeZWindows( | |
| 141 | try testJoinMaybeZWindows( | |
| 142 | 142 | &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" }, |
| 143 | 143 | "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig", |
| 144 | 144 | zero, |
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero); | |
| 148 | testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero); | |
| 147 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\", "a", "b/", "c" }, "c:\\a\\b/c", zero); | |
| 148 | try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a/", "b\\", "/c" }, "c:\\a/b\\c", zero); | |
| 149 | 149 | |
| 150 | testJoinMaybeZPosix(&[_][]const u8{}, "", zero); | |
| 151 | testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero); | |
| 152 | testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero); | |
| 150 | try testJoinMaybeZPosix(&[_][]const u8{}, "", zero); | |
| 151 | try testJoinMaybeZPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c", zero); | |
| 152 | try testJoinMaybeZPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c", zero); | |
| 153 | 153 | |
| 154 | testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero); | |
| 155 | testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero); | |
| 154 | try testJoinMaybeZPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c", zero); | |
| 155 | try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero); | |
| 156 | 156 | |
| 157 | testJoinMaybeZPosix( | |
| 157 | try testJoinMaybeZPosix( | |
| 158 | 158 | &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" }, |
| 159 | 159 | "/home/andy/dev/zig/build/lib/zig/std/io.zig", |
| 160 | 160 | zero, |
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero); | |
| 164 | testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero); | |
| 163 | try testJoinMaybeZPosix(&[_][]const u8{ "a", "/c" }, "a/c", zero); | |
| 164 | try testJoinMaybeZPosix(&[_][]const u8{ "a/", "/c" }, "a/c", zero); | |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| ... | ... | @@ -235,42 +235,42 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | test "isAbsoluteWindows" { |
| 238 | testIsAbsoluteWindows("", false); | |
| 239 | testIsAbsoluteWindows("/", true); | |
| 240 | testIsAbsoluteWindows("//", true); | |
| 241 | testIsAbsoluteWindows("//server", true); | |
| 242 | testIsAbsoluteWindows("//server/file", true); | |
| 243 | testIsAbsoluteWindows("\\\\server\\file", true); | |
| 244 | testIsAbsoluteWindows("\\\\server", true); | |
| 245 | testIsAbsoluteWindows("\\\\", true); | |
| 246 | testIsAbsoluteWindows("c", false); | |
| 247 | testIsAbsoluteWindows("c:", false); | |
| 248 | testIsAbsoluteWindows("c:\\", true); | |
| 249 | testIsAbsoluteWindows("c:/", true); | |
| 250 | testIsAbsoluteWindows("c://", true); | |
| 251 | testIsAbsoluteWindows("C:/Users/", true); | |
| 252 | testIsAbsoluteWindows("C:\\Users\\", true); | |
| 253 | testIsAbsoluteWindows("C:cwd/another", false); | |
| 254 | testIsAbsoluteWindows("C:cwd\\another", false); | |
| 255 | testIsAbsoluteWindows("directory/directory", false); | |
| 256 | testIsAbsoluteWindows("directory\\directory", false); | |
| 257 | testIsAbsoluteWindows("/usr/local", true); | |
| 238 | try testIsAbsoluteWindows("", false); | |
| 239 | try testIsAbsoluteWindows("/", true); | |
| 240 | try testIsAbsoluteWindows("//", true); | |
| 241 | try testIsAbsoluteWindows("//server", true); | |
| 242 | try testIsAbsoluteWindows("//server/file", true); | |
| 243 | try testIsAbsoluteWindows("\\\\server\\file", true); | |
| 244 | try testIsAbsoluteWindows("\\\\server", true); | |
| 245 | try testIsAbsoluteWindows("\\\\", true); | |
| 246 | try testIsAbsoluteWindows("c", false); | |
| 247 | try testIsAbsoluteWindows("c:", false); | |
| 248 | try testIsAbsoluteWindows("c:\\", true); | |
| 249 | try testIsAbsoluteWindows("c:/", true); | |
| 250 | try testIsAbsoluteWindows("c://", true); | |
| 251 | try testIsAbsoluteWindows("C:/Users/", true); | |
| 252 | try testIsAbsoluteWindows("C:\\Users\\", true); | |
| 253 | try testIsAbsoluteWindows("C:cwd/another", false); | |
| 254 | try testIsAbsoluteWindows("C:cwd\\another", false); | |
| 255 | try testIsAbsoluteWindows("directory/directory", false); | |
| 256 | try testIsAbsoluteWindows("directory\\directory", false); | |
| 257 | try testIsAbsoluteWindows("/usr/local", true); | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | test "isAbsolutePosix" { |
| 261 | testIsAbsolutePosix("", false); | |
| 262 | testIsAbsolutePosix("/home/foo", true); | |
| 263 | testIsAbsolutePosix("/home/foo/..", true); | |
| 264 | testIsAbsolutePosix("bar/", false); | |
| 265 | testIsAbsolutePosix("./baz", false); | |
| 261 | try testIsAbsolutePosix("", false); | |
| 262 | try testIsAbsolutePosix("/home/foo", true); | |
| 263 | try testIsAbsolutePosix("/home/foo/..", true); | |
| 264 | try testIsAbsolutePosix("bar/", false); | |
| 265 | try testIsAbsolutePosix("./baz", false); | |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) void { | |
| 269 | testing.expectEqual(expected_result, isAbsoluteWindows(path)); | |
| 268 | fn testIsAbsoluteWindows(path: []const u8, expected_result: bool) !void { | |
| 269 | try testing.expectEqual(expected_result, isAbsoluteWindows(path)); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | fn testIsAbsolutePosix(path: []const u8, expected_result: bool) void { | |
| 273 | testing.expectEqual(expected_result, isAbsolutePosix(path)); | |
| 272 | fn testIsAbsolutePosix(path: []const u8, expected_result: bool) !void { | |
| 273 | try testing.expectEqual(expected_result, isAbsolutePosix(path)); | |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | pub const WindowsPath = struct { |
| ... | ... | @@ -334,33 +334,33 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 334 | 334 | test "windowsParsePath" { |
| 335 | 335 | { |
| 336 | 336 | const parsed = windowsParsePath("//a/b"); |
| 337 | testing.expect(parsed.is_abs); | |
| 338 | testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 339 | testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b")); | |
| 337 | try testing.expect(parsed.is_abs); | |
| 338 | try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 339 | try testing.expect(mem.eql(u8, parsed.disk_designator, "//a/b")); | |
| 340 | 340 | } |
| 341 | 341 | { |
| 342 | 342 | const parsed = windowsParsePath("\\\\a\\b"); |
| 343 | testing.expect(parsed.is_abs); | |
| 344 | testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 345 | testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b")); | |
| 343 | try testing.expect(parsed.is_abs); | |
| 344 | try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare); | |
| 345 | try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b")); | |
| 346 | 346 | } |
| 347 | 347 | { |
| 348 | 348 | const parsed = windowsParsePath("\\\\a\\"); |
| 349 | testing.expect(!parsed.is_abs); | |
| 350 | testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 351 | testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 349 | try testing.expect(!parsed.is_abs); | |
| 350 | try testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 351 | try testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 352 | 352 | } |
| 353 | 353 | { |
| 354 | 354 | const parsed = windowsParsePath("/usr/local"); |
| 355 | testing.expect(parsed.is_abs); | |
| 356 | testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 357 | testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 355 | try testing.expect(parsed.is_abs); | |
| 356 | try testing.expect(parsed.kind == WindowsPath.Kind.None); | |
| 357 | try testing.expect(mem.eql(u8, parsed.disk_designator, "")); | |
| 358 | 358 | } |
| 359 | 359 | { |
| 360 | 360 | const parsed = windowsParsePath("c:../"); |
| 361 | testing.expect(!parsed.is_abs); | |
| 362 | testing.expect(parsed.kind == WindowsPath.Kind.Drive); | |
| 363 | testing.expect(mem.eql(u8, parsed.disk_designator, "c:")); | |
| 361 | try testing.expect(!parsed.is_abs); | |
| 362 | try testing.expect(parsed.kind == WindowsPath.Kind.Drive); | |
| 363 | try testing.expect(mem.eql(u8, parsed.disk_designator, "c:")); | |
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 | |
| ... | ... | @@ -772,13 +772,13 @@ test "resolvePosix" { |
| 772 | 772 | fn testResolveWindows(paths: []const []const u8, expected: []const u8) !void { |
| 773 | 773 | const actual = try resolveWindows(testing.allocator, paths); |
| 774 | 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 | } |
| 777 | 777 | |
| 778 | 778 | fn testResolvePosix(paths: []const []const u8, expected: []const u8) !void { |
| 779 | 779 | const actual = try resolvePosix(testing.allocator, paths); |
| 780 | 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 | } |
| 783 | 783 | |
| 784 | 784 | /// Strip the last component from a file path. |
| ... | ... | @@ -856,68 +856,68 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 { |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | test "dirnamePosix" { |
| 859 | testDirnamePosix("/a/b/c", "/a/b"); | |
| 860 | testDirnamePosix("/a/b/c///", "/a/b"); | |
| 861 | testDirnamePosix("/a", "/"); | |
| 862 | testDirnamePosix("/", null); | |
| 863 | testDirnamePosix("//", null); | |
| 864 | testDirnamePosix("///", null); | |
| 865 | testDirnamePosix("////", null); | |
| 866 | testDirnamePosix("", null); | |
| 867 | testDirnamePosix("a", null); | |
| 868 | testDirnamePosix("a/", null); | |
| 869 | testDirnamePosix("a//", null); | |
| 859 | try testDirnamePosix("/a/b/c", "/a/b"); | |
| 860 | try testDirnamePosix("/a/b/c///", "/a/b"); | |
| 861 | try testDirnamePosix("/a", "/"); | |
| 862 | try testDirnamePosix("/", null); | |
| 863 | try testDirnamePosix("//", null); | |
| 864 | try testDirnamePosix("///", null); | |
| 865 | try testDirnamePosix("////", null); | |
| 866 | try testDirnamePosix("", null); | |
| 867 | try testDirnamePosix("a", null); | |
| 868 | try testDirnamePosix("a/", null); | |
| 869 | try testDirnamePosix("a//", null); | |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | test "dirnameWindows" { |
| 873 | testDirnameWindows("c:\\", null); | |
| 874 | testDirnameWindows("c:\\foo", "c:\\"); | |
| 875 | testDirnameWindows("c:\\foo\\", "c:\\"); | |
| 876 | testDirnameWindows("c:\\foo\\bar", "c:\\foo"); | |
| 877 | testDirnameWindows("c:\\foo\\bar\\", "c:\\foo"); | |
| 878 | testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar"); | |
| 879 | testDirnameWindows("\\", null); | |
| 880 | testDirnameWindows("\\foo", "\\"); | |
| 881 | testDirnameWindows("\\foo\\", "\\"); | |
| 882 | testDirnameWindows("\\foo\\bar", "\\foo"); | |
| 883 | testDirnameWindows("\\foo\\bar\\", "\\foo"); | |
| 884 | testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar"); | |
| 885 | testDirnameWindows("c:", null); | |
| 886 | testDirnameWindows("c:foo", null); | |
| 887 | testDirnameWindows("c:foo\\", null); | |
| 888 | testDirnameWindows("c:foo\\bar", "c:foo"); | |
| 889 | testDirnameWindows("c:foo\\bar\\", "c:foo"); | |
| 890 | testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar"); | |
| 891 | testDirnameWindows("file:stream", null); | |
| 892 | testDirnameWindows("dir\\file:stream", "dir"); | |
| 893 | testDirnameWindows("\\\\unc\\share", null); | |
| 894 | testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\"); | |
| 895 | testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\"); | |
| 896 | testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo"); | |
| 897 | testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo"); | |
| 898 | testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar"); | |
| 899 | testDirnameWindows("/a/b/", "/a"); | |
| 900 | testDirnameWindows("/a/b", "/a"); | |
| 901 | testDirnameWindows("/a", "/"); | |
| 902 | testDirnameWindows("", null); | |
| 903 | testDirnameWindows("/", null); | |
| 904 | testDirnameWindows("////", null); | |
| 905 | testDirnameWindows("foo", null); | |
| 873 | try testDirnameWindows("c:\\", null); | |
| 874 | try testDirnameWindows("c:\\foo", "c:\\"); | |
| 875 | try testDirnameWindows("c:\\foo\\", "c:\\"); | |
| 876 | try testDirnameWindows("c:\\foo\\bar", "c:\\foo"); | |
| 877 | try testDirnameWindows("c:\\foo\\bar\\", "c:\\foo"); | |
| 878 | try testDirnameWindows("c:\\foo\\bar\\baz", "c:\\foo\\bar"); | |
| 879 | try testDirnameWindows("\\", null); | |
| 880 | try testDirnameWindows("\\foo", "\\"); | |
| 881 | try testDirnameWindows("\\foo\\", "\\"); | |
| 882 | try testDirnameWindows("\\foo\\bar", "\\foo"); | |
| 883 | try testDirnameWindows("\\foo\\bar\\", "\\foo"); | |
| 884 | try testDirnameWindows("\\foo\\bar\\baz", "\\foo\\bar"); | |
| 885 | try testDirnameWindows("c:", null); | |
| 886 | try testDirnameWindows("c:foo", null); | |
| 887 | try testDirnameWindows("c:foo\\", null); | |
| 888 | try testDirnameWindows("c:foo\\bar", "c:foo"); | |
| 889 | try testDirnameWindows("c:foo\\bar\\", "c:foo"); | |
| 890 | try testDirnameWindows("c:foo\\bar\\baz", "c:foo\\bar"); | |
| 891 | try testDirnameWindows("file:stream", null); | |
| 892 | try testDirnameWindows("dir\\file:stream", "dir"); | |
| 893 | try testDirnameWindows("\\\\unc\\share", null); | |
| 894 | try testDirnameWindows("\\\\unc\\share\\foo", "\\\\unc\\share\\"); | |
| 895 | try testDirnameWindows("\\\\unc\\share\\foo\\", "\\\\unc\\share\\"); | |
| 896 | try testDirnameWindows("\\\\unc\\share\\foo\\bar", "\\\\unc\\share\\foo"); | |
| 897 | try testDirnameWindows("\\\\unc\\share\\foo\\bar\\", "\\\\unc\\share\\foo"); | |
| 898 | try testDirnameWindows("\\\\unc\\share\\foo\\bar\\baz", "\\\\unc\\share\\foo\\bar"); | |
| 899 | try testDirnameWindows("/a/b/", "/a"); | |
| 900 | try testDirnameWindows("/a/b", "/a"); | |
| 901 | try testDirnameWindows("/a", "/"); | |
| 902 | try testDirnameWindows("", null); | |
| 903 | try testDirnameWindows("/", null); | |
| 904 | try testDirnameWindows("////", null); | |
| 905 | try testDirnameWindows("foo", null); | |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) void { | |
| 908 | fn testDirnamePosix(input: []const u8, expected_output: ?[]const u8) !void { | |
| 909 | 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 | 911 | } else { |
| 912 | testing.expect(expected_output == null); | |
| 912 | try testing.expect(expected_output == null); | |
| 913 | 913 | } |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void { | |
| 916 | fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) !void { | |
| 917 | 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 | 919 | } else { |
| 920 | testing.expect(expected_output == null); | |
| 920 | try testing.expect(expected_output == null); | |
| 921 | 921 | } |
| 922 | 922 | } |
| 923 | 923 | |
| ... | ... | @@ -983,54 +983,54 @@ pub fn basenameWindows(path: []const u8) []const u8 { |
| 983 | 983 | } |
| 984 | 984 | |
| 985 | 985 | test "basename" { |
| 986 | testBasename("", ""); | |
| 987 | testBasename("/", ""); | |
| 988 | testBasename("/dir/basename.ext", "basename.ext"); | |
| 989 | testBasename("/basename.ext", "basename.ext"); | |
| 990 | testBasename("basename.ext", "basename.ext"); | |
| 991 | testBasename("basename.ext/", "basename.ext"); | |
| 992 | testBasename("basename.ext//", "basename.ext"); | |
| 993 | testBasename("/aaa/bbb", "bbb"); | |
| 994 | testBasename("/aaa/", "aaa"); | |
| 995 | testBasename("/aaa/b", "b"); | |
| 996 | testBasename("/a/b", "b"); | |
| 997 | testBasename("//a", "a"); | |
| 998 | ||
| 999 | testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext"); | |
| 1000 | testBasenamePosix("\\basename.ext", "\\basename.ext"); | |
| 1001 | testBasenamePosix("basename.ext", "basename.ext"); | |
| 1002 | testBasenamePosix("basename.ext\\", "basename.ext\\"); | |
| 1003 | testBasenamePosix("basename.ext\\\\", "basename.ext\\\\"); | |
| 1004 | testBasenamePosix("foo", "foo"); | |
| 1005 | ||
| 1006 | testBasenameWindows("\\dir\\basename.ext", "basename.ext"); | |
| 1007 | testBasenameWindows("\\basename.ext", "basename.ext"); | |
| 1008 | testBasenameWindows("basename.ext", "basename.ext"); | |
| 1009 | testBasenameWindows("basename.ext\\", "basename.ext"); | |
| 1010 | testBasenameWindows("basename.ext\\\\", "basename.ext"); | |
| 1011 | testBasenameWindows("foo", "foo"); | |
| 1012 | testBasenameWindows("C:", ""); | |
| 1013 | testBasenameWindows("C:.", "."); | |
| 1014 | testBasenameWindows("C:\\", ""); | |
| 1015 | testBasenameWindows("C:\\dir\\base.ext", "base.ext"); | |
| 1016 | testBasenameWindows("C:\\basename.ext", "basename.ext"); | |
| 1017 | testBasenameWindows("C:basename.ext", "basename.ext"); | |
| 1018 | testBasenameWindows("C:basename.ext\\", "basename.ext"); | |
| 1019 | testBasenameWindows("C:basename.ext\\\\", "basename.ext"); | |
| 1020 | testBasenameWindows("C:foo", "foo"); | |
| 1021 | testBasenameWindows("file:stream", "file:stream"); | |
| 986 | try testBasename("", ""); | |
| 987 | try testBasename("/", ""); | |
| 988 | try testBasename("/dir/basename.ext", "basename.ext"); | |
| 989 | try testBasename("/basename.ext", "basename.ext"); | |
| 990 | try testBasename("basename.ext", "basename.ext"); | |
| 991 | try testBasename("basename.ext/", "basename.ext"); | |
| 992 | try testBasename("basename.ext//", "basename.ext"); | |
| 993 | try testBasename("/aaa/bbb", "bbb"); | |
| 994 | try testBasename("/aaa/", "aaa"); | |
| 995 | try testBasename("/aaa/b", "b"); | |
| 996 | try testBasename("/a/b", "b"); | |
| 997 | try testBasename("//a", "a"); | |
| 998 | ||
| 999 | try testBasenamePosix("\\dir\\basename.ext", "\\dir\\basename.ext"); | |
| 1000 | try testBasenamePosix("\\basename.ext", "\\basename.ext"); | |
| 1001 | try testBasenamePosix("basename.ext", "basename.ext"); | |
| 1002 | try testBasenamePosix("basename.ext\\", "basename.ext\\"); | |
| 1003 | try testBasenamePosix("basename.ext\\\\", "basename.ext\\\\"); | |
| 1004 | try testBasenamePosix("foo", "foo"); | |
| 1005 | ||
| 1006 | try testBasenameWindows("\\dir\\basename.ext", "basename.ext"); | |
| 1007 | try testBasenameWindows("\\basename.ext", "basename.ext"); | |
| 1008 | try testBasenameWindows("basename.ext", "basename.ext"); | |
| 1009 | try testBasenameWindows("basename.ext\\", "basename.ext"); | |
| 1010 | try testBasenameWindows("basename.ext\\\\", "basename.ext"); | |
| 1011 | try testBasenameWindows("foo", "foo"); | |
| 1012 | try testBasenameWindows("C:", ""); | |
| 1013 | try testBasenameWindows("C:.", "."); | |
| 1014 | try testBasenameWindows("C:\\", ""); | |
| 1015 | try testBasenameWindows("C:\\dir\\base.ext", "base.ext"); | |
| 1016 | try testBasenameWindows("C:\\basename.ext", "basename.ext"); | |
| 1017 | try testBasenameWindows("C:basename.ext", "basename.ext"); | |
| 1018 | try testBasenameWindows("C:basename.ext\\", "basename.ext"); | |
| 1019 | try testBasenameWindows("C:basename.ext\\\\", "basename.ext"); | |
| 1020 | try testBasenameWindows("C:foo", "foo"); | |
| 1021 | try testBasenameWindows("file:stream", "file:stream"); | |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | fn testBasename(input: []const u8, expected_output: []const u8) void { | |
| 1025 | testing.expectEqualSlices(u8, expected_output, basename(input)); | |
| 1024 | fn testBasename(input: []const u8, expected_output: []const u8) !void { | |
| 1025 | try testing.expectEqualSlices(u8, expected_output, basename(input)); | |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | fn testBasenamePosix(input: []const u8, expected_output: []const u8) void { | |
| 1029 | testing.expectEqualSlices(u8, expected_output, basenamePosix(input)); | |
| 1028 | fn testBasenamePosix(input: []const u8, expected_output: []const u8) !void { | |
| 1029 | try testing.expectEqualSlices(u8, expected_output, basenamePosix(input)); | |
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { | |
| 1033 | testing.expectEqualSlices(u8, expected_output, basenameWindows(input)); | |
| 1032 | fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void { | |
| 1033 | try testing.expectEqualSlices(u8, expected_output, basenameWindows(input)); | |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /// Returns the relative path from `from` to `to`. If `from` and `to` each |
| ... | ... | @@ -1212,13 +1212,13 @@ test "relative" { |
| 1212 | 1212 | fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) !void { |
| 1213 | 1213 | const result = try relativePosix(testing.allocator, from, to); |
| 1214 | 1214 | defer testing.allocator.free(result); |
| 1215 | testing.expectEqualSlices(u8, expected_output, result); | |
| 1215 | try testing.expectEqualSlices(u8, expected_output, result); | |
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | 1218 | fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) !void { |
| 1219 | 1219 | const result = try relativeWindows(testing.allocator, from, to); |
| 1220 | 1220 | defer testing.allocator.free(result); |
| 1221 | testing.expectEqualSlices(u8, expected_output, result); | |
| 1221 | try testing.expectEqualSlices(u8, expected_output, result); | |
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | /// Returns the extension of the file name (if any). |
| ... | ... | @@ -1241,47 +1241,47 @@ pub fn extension(path: []const u8) []const u8 { |
| 1241 | 1241 | return filename[index..]; |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | fn testExtension(path: []const u8, expected: []const u8) void { | |
| 1245 | std.testing.expectEqualStrings(expected, extension(path)); | |
| 1244 | fn testExtension(path: []const u8, expected: []const u8) !void { | |
| 1245 | try std.testing.expectEqualStrings(expected, extension(path)); | |
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | test "extension" { |
| 1249 | testExtension("", ""); | |
| 1250 | testExtension(".", ""); | |
| 1251 | testExtension("a.", "."); | |
| 1252 | testExtension("abc.", "."); | |
| 1253 | testExtension(".a", ""); | |
| 1254 | testExtension(".file", ""); | |
| 1255 | testExtension(".gitignore", ""); | |
| 1256 | testExtension("file.ext", ".ext"); | |
| 1257 | testExtension("file.ext.", "."); | |
| 1258 | testExtension("very-long-file.bruh", ".bruh"); | |
| 1259 | testExtension("a.b.c", ".c"); | |
| 1260 | testExtension("a.b.c/", ".c"); | |
| 1261 | ||
| 1262 | testExtension("/", ""); | |
| 1263 | testExtension("/.", ""); | |
| 1264 | testExtension("/a.", "."); | |
| 1265 | testExtension("/abc.", "."); | |
| 1266 | testExtension("/.a", ""); | |
| 1267 | testExtension("/.file", ""); | |
| 1268 | testExtension("/.gitignore", ""); | |
| 1269 | testExtension("/file.ext", ".ext"); | |
| 1270 | testExtension("/file.ext.", "."); | |
| 1271 | testExtension("/very-long-file.bruh", ".bruh"); | |
| 1272 | testExtension("/a.b.c", ".c"); | |
| 1273 | testExtension("/a.b.c/", ".c"); | |
| 1274 | ||
| 1275 | testExtension("/foo/bar/bam/", ""); | |
| 1276 | testExtension("/foo/bar/bam/.", ""); | |
| 1277 | testExtension("/foo/bar/bam/a.", "."); | |
| 1278 | testExtension("/foo/bar/bam/abc.", "."); | |
| 1279 | testExtension("/foo/bar/bam/.a", ""); | |
| 1280 | testExtension("/foo/bar/bam/.file", ""); | |
| 1281 | testExtension("/foo/bar/bam/.gitignore", ""); | |
| 1282 | testExtension("/foo/bar/bam/file.ext", ".ext"); | |
| 1283 | testExtension("/foo/bar/bam/file.ext.", "."); | |
| 1284 | testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); | |
| 1285 | testExtension("/foo/bar/bam/a.b.c", ".c"); | |
| 1286 | testExtension("/foo/bar/bam/a.b.c/", ".c"); | |
| 1249 | try testExtension("", ""); | |
| 1250 | try testExtension(".", ""); | |
| 1251 | try testExtension("a.", "."); | |
| 1252 | try testExtension("abc.", "."); | |
| 1253 | try testExtension(".a", ""); | |
| 1254 | try testExtension(".file", ""); | |
| 1255 | try testExtension(".gitignore", ""); | |
| 1256 | try testExtension("file.ext", ".ext"); | |
| 1257 | try testExtension("file.ext.", "."); | |
| 1258 | try testExtension("very-long-file.bruh", ".bruh"); | |
| 1259 | try testExtension("a.b.c", ".c"); | |
| 1260 | try testExtension("a.b.c/", ".c"); | |
| 1261 | ||
| 1262 | try testExtension("/", ""); | |
| 1263 | try testExtension("/.", ""); | |
| 1264 | try testExtension("/a.", "."); | |
| 1265 | try testExtension("/abc.", "."); | |
| 1266 | try testExtension("/.a", ""); | |
| 1267 | try testExtension("/.file", ""); | |
| 1268 | try testExtension("/.gitignore", ""); | |
| 1269 | try testExtension("/file.ext", ".ext"); | |
| 1270 | try testExtension("/file.ext.", "."); | |
| 1271 | try testExtension("/very-long-file.bruh", ".bruh"); | |
| 1272 | try testExtension("/a.b.c", ".c"); | |
| 1273 | try testExtension("/a.b.c/", ".c"); | |
| 1274 | ||
| 1275 | try testExtension("/foo/bar/bam/", ""); | |
| 1276 | try testExtension("/foo/bar/bam/.", ""); | |
| 1277 | try testExtension("/foo/bar/bam/a.", "."); | |
| 1278 | try testExtension("/foo/bar/bam/abc.", "."); | |
| 1279 | try testExtension("/foo/bar/bam/.a", ""); | |
| 1280 | try testExtension("/foo/bar/bam/.file", ""); | |
| 1281 | try testExtension("/foo/bar/bam/.gitignore", ""); | |
| 1282 | try testExtension("/foo/bar/bam/file.ext", ".ext"); | |
| 1283 | try testExtension("/foo/bar/bam/file.ext.", "."); | |
| 1284 | try testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); | |
| 1285 | try testExtension("/foo/bar/bam/a.b.c", ".c"); | |
| 1286 | try testExtension("/foo/bar/bam/a.b.c/", ".c"); | |
| 1287 | 1287 | } |
lib/std/fs/test.zig+52-52| ... | ... | @@ -46,7 +46,7 @@ test "Dir.readLink" { |
| 46 | 46 | fn testReadLink(dir: Dir, target_path: []const u8, symlink_path: []const u8) !void { |
| 47 | 47 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 48 | 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 | } |
| 51 | 51 | |
| 52 | 52 | test "accessAbsolute" { |
| ... | ... | @@ -132,7 +132,7 @@ test "readLinkAbsolute" { |
| 132 | 132 | fn testReadLinkAbsolute(target_path: []const u8, symlink_path: []const u8) !void { |
| 133 | 133 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 134 | 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 | } |
| 137 | 137 | |
| 138 | 138 | test "Dir.Iterator" { |
| ... | ... | @@ -159,9 +159,9 @@ test "Dir.Iterator" { |
| 159 | 159 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind }); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..' | |
| 163 | testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File })); | |
| 164 | testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory })); | |
| 162 | try testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..' | |
| 163 | try testing.expect(contains(&entries, Dir.Entry{ .name = "some_file", .kind = Dir.Entry.Kind.File })); | |
| 164 | try testing.expect(contains(&entries, Dir.Entry{ .name = "some_dir", .kind = Dir.Entry.Kind.Directory })); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | fn entryEql(lhs: Dir.Entry, rhs: Dir.Entry) bool { |
| ... | ... | @@ -203,7 +203,7 @@ test "Dir.realpath smoke test" { |
| 203 | 203 | const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]); |
| 204 | 204 | const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" }); |
| 205 | 205 | |
| 206 | testing.expect(mem.eql(u8, file_path, expected_path)); | |
| 206 | try testing.expect(mem.eql(u8, file_path, expected_path)); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // Next, test alloc version |
| ... | ... | @@ -211,7 +211,7 @@ test "Dir.realpath smoke test" { |
| 211 | 211 | const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file"); |
| 212 | 212 | const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" }); |
| 213 | 213 | |
| 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 | } |
| 217 | 217 | |
| ... | ... | @@ -224,7 +224,7 @@ test "readAllAlloc" { |
| 224 | 224 | |
| 225 | 225 | const buf1 = try file.readToEndAlloc(testing.allocator, 1024); |
| 226 | 226 | defer testing.allocator.free(buf1); |
| 227 | testing.expect(buf1.len == 0); | |
| 227 | try testing.expect(buf1.len == 0); | |
| 228 | 228 | |
| 229 | 229 | const write_buf: []const u8 = "this is a test.\nthis is a test.\nthis is a test.\nthis is a test.\n"; |
| 230 | 230 | try file.writeAll(write_buf); |
| ... | ... | @@ -233,19 +233,19 @@ test "readAllAlloc" { |
| 233 | 233 | // max_bytes > file_size |
| 234 | 234 | const buf2 = try file.readToEndAlloc(testing.allocator, 1024); |
| 235 | 235 | defer testing.allocator.free(buf2); |
| 236 | testing.expectEqual(write_buf.len, buf2.len); | |
| 237 | testing.expect(std.mem.eql(u8, write_buf, buf2)); | |
| 236 | try testing.expectEqual(write_buf.len, buf2.len); | |
| 237 | try testing.expect(std.mem.eql(u8, write_buf, buf2)); | |
| 238 | 238 | try file.seekTo(0); |
| 239 | 239 | |
| 240 | 240 | // max_bytes == file_size |
| 241 | 241 | const buf3 = try file.readToEndAlloc(testing.allocator, write_buf.len); |
| 242 | 242 | defer testing.allocator.free(buf3); |
| 243 | testing.expectEqual(write_buf.len, buf3.len); | |
| 244 | testing.expect(std.mem.eql(u8, write_buf, buf3)); | |
| 243 | try testing.expectEqual(write_buf.len, buf3.len); | |
| 244 | try testing.expect(std.mem.eql(u8, write_buf, buf3)); | |
| 245 | 245 | try file.seekTo(0); |
| 246 | 246 | |
| 247 | 247 | // 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 | } |
| 250 | 250 | |
| 251 | 251 | test "directory operations on files" { |
| ... | ... | @@ -257,22 +257,22 @@ test "directory operations on files" { |
| 257 | 257 | var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true }); |
| 258 | 258 | file.close(); |
| 259 | 259 | |
| 260 | testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name)); | |
| 261 | testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{})); | |
| 262 | testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name)); | |
| 260 | try testing.expectError(error.PathAlreadyExists, tmp_dir.dir.makeDir(test_file_name)); | |
| 261 | try testing.expectError(error.NotDir, tmp_dir.dir.openDir(test_file_name, .{})); | |
| 262 | try testing.expectError(error.NotDir, tmp_dir.dir.deleteDir(test_file_name)); | |
| 263 | 263 | |
| 264 | 264 | if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) { |
| 265 | 265 | const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_file_name); |
| 266 | 266 | defer testing.allocator.free(absolute_path); |
| 267 | 267 | |
| 268 | testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path)); | |
| 269 | testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path)); | |
| 268 | try testing.expectError(error.PathAlreadyExists, fs.makeDirAbsolute(absolute_path)); | |
| 269 | try testing.expectError(error.NotDir, fs.deleteDirAbsolute(absolute_path)); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // ensure the file still exists and is a file as a sanity check |
| 273 | 273 | file = try tmp_dir.dir.openFile(test_file_name, .{}); |
| 274 | 274 | const stat = try file.stat(); |
| 275 | testing.expect(stat.kind == .File); | |
| 275 | try testing.expect(stat.kind == .File); | |
| 276 | 276 | file.close(); |
| 277 | 277 | } |
| 278 | 278 | |
| ... | ... | @@ -287,23 +287,23 @@ test "file operations on directories" { |
| 287 | 287 | |
| 288 | 288 | try tmp_dir.dir.makeDir(test_dir_name); |
| 289 | 289 | |
| 290 | testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{})); | |
| 291 | testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name)); | |
| 290 | try testing.expectError(error.IsDir, tmp_dir.dir.createFile(test_dir_name, .{})); | |
| 291 | try testing.expectError(error.IsDir, tmp_dir.dir.deleteFile(test_dir_name)); | |
| 292 | 292 | // Currently, WASI will return error.Unexpected (via ENOTCAPABLE) when attempting fd_read on a directory handle. |
| 293 | 293 | // TODO: Re-enable on WASI once https://github.com/bytecodealliance/wasmtime/issues/1935 is resolved. |
| 294 | 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 | 297 | // Note: The `.write = true` is necessary to ensure the error occurs on all platforms. |
| 298 | 298 | // 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 })); | |
| 300 | 300 | |
| 301 | 301 | if (builtin.os.tag != .wasi and builtin.os.tag != .freebsd and builtin.os.tag != .openbsd) { |
| 302 | 302 | const absolute_path = try tmp_dir.dir.realpathAlloc(testing.allocator, test_dir_name); |
| 303 | 303 | defer testing.allocator.free(absolute_path); |
| 304 | 304 | |
| 305 | testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{})); | |
| 306 | testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path)); | |
| 305 | try testing.expectError(error.IsDir, fs.createFileAbsolute(absolute_path, .{})); | |
| 306 | try testing.expectError(error.IsDir, fs.deleteFileAbsolute(absolute_path)); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // ensure the directory still exists as a sanity check |
| ... | ... | @@ -316,7 +316,7 @@ test "deleteDir" { |
| 316 | 316 | defer tmp_dir.cleanup(); |
| 317 | 317 | |
| 318 | 318 | // 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")); | |
| 320 | 320 | |
| 321 | 321 | var dir = try tmp_dir.dir.makeOpenPath("test_dir", .{}); |
| 322 | 322 | var file = try dir.createFile("test_file", .{}); |
| ... | ... | @@ -326,7 +326,7 @@ test "deleteDir" { |
| 326 | 326 | // deleting a non-empty directory |
| 327 | 327 | // TODO: Re-enable this check on Windows, see https://github.com/ziglang/zig/issues/5537 |
| 328 | 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 | } |
| 331 | 331 | |
| 332 | 332 | dir = try tmp_dir.dir.openDir("test_dir", .{}); |
| ... | ... | @@ -341,7 +341,7 @@ test "Dir.rename files" { |
| 341 | 341 | var tmp_dir = tmpDir(.{}); |
| 342 | 342 | defer tmp_dir.cleanup(); |
| 343 | 343 | |
| 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")); | |
| 345 | 345 | |
| 346 | 346 | // Renaming files |
| 347 | 347 | const test_file_name = "test_file"; |
| ... | ... | @@ -351,7 +351,7 @@ test "Dir.rename files" { |
| 351 | 351 | try tmp_dir.dir.rename(test_file_name, renamed_test_file_name); |
| 352 | 352 | |
| 353 | 353 | // 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 | 355 | file = try tmp_dir.dir.openFile(renamed_test_file_name, .{}); |
| 356 | 356 | file.close(); |
| 357 | 357 | |
| ... | ... | @@ -363,7 +363,7 @@ test "Dir.rename files" { |
| 363 | 363 | existing_file.close(); |
| 364 | 364 | try tmp_dir.dir.rename(renamed_test_file_name, "existing_file"); |
| 365 | 365 | |
| 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 | 367 | file = try tmp_dir.dir.openFile("existing_file", .{}); |
| 368 | 368 | file.close(); |
| 369 | 369 | } |
| ... | ... | @@ -380,7 +380,7 @@ test "Dir.rename directories" { |
| 380 | 380 | try tmp_dir.dir.rename("test_dir", "test_dir_renamed"); |
| 381 | 381 | |
| 382 | 382 | // 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 | 384 | var dir = try tmp_dir.dir.openDir("test_dir_renamed", .{}); |
| 385 | 385 | |
| 386 | 386 | // Put a file in the directory |
| ... | ... | @@ -391,7 +391,7 @@ test "Dir.rename directories" { |
| 391 | 391 | try tmp_dir.dir.rename("test_dir_renamed", "test_dir_renamed_again"); |
| 392 | 392 | |
| 393 | 393 | // 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 | 395 | dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{}); |
| 396 | 396 | file = try dir.openFile("test_file", .{}); |
| 397 | 397 | file.close(); |
| ... | ... | @@ -402,7 +402,7 @@ test "Dir.rename directories" { |
| 402 | 402 | file = try target_dir.createFile("filler", .{ .read = true }); |
| 403 | 403 | file.close(); |
| 404 | 404 | |
| 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")); | |
| 406 | 406 | |
| 407 | 407 | // Ensure the directory was not renamed |
| 408 | 408 | dir = try tmp_dir.dir.openDir("test_dir_renamed_again", .{}); |
| ... | ... | @@ -421,8 +421,8 @@ test "Dir.rename file <-> dir" { |
| 421 | 421 | var file = try tmp_dir.dir.createFile("test_file", .{ .read = true }); |
| 422 | 422 | file.close(); |
| 423 | 423 | try tmp_dir.dir.makeDir("test_dir"); |
| 424 | testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir")); | |
| 425 | testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file")); | |
| 424 | try testing.expectError(error.IsDir, tmp_dir.dir.rename("test_file", "test_dir")); | |
| 425 | try testing.expectError(error.NotDir, tmp_dir.dir.rename("test_dir", "test_file")); | |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | test "rename" { |
| ... | ... | @@ -440,7 +440,7 @@ test "rename" { |
| 440 | 440 | try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name); |
| 441 | 441 | |
| 442 | 442 | // 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 | 444 | file = try tmp_dir2.dir.openFile(renamed_test_file_name, .{}); |
| 445 | 445 | file.close(); |
| 446 | 446 | } |
| ... | ... | @@ -461,7 +461,7 @@ test "renameAbsolute" { |
| 461 | 461 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); |
| 462 | 462 | }; |
| 463 | 463 | |
| 464 | testing.expectError(error.FileNotFound, fs.renameAbsolute( | |
| 464 | try testing.expectError(error.FileNotFound, fs.renameAbsolute( | |
| 465 | 465 | try fs.path.join(allocator, &[_][]const u8{ base_path, "missing_file_name" }), |
| 466 | 466 | try fs.path.join(allocator, &[_][]const u8{ base_path, "something_else" }), |
| 467 | 467 | )); |
| ... | ... | @@ -477,10 +477,10 @@ test "renameAbsolute" { |
| 477 | 477 | ); |
| 478 | 478 | |
| 479 | 479 | // 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 | 481 | file = try tmp_dir.dir.openFile(renamed_test_file_name, .{}); |
| 482 | 482 | const stat = try file.stat(); |
| 483 | testing.expect(stat.kind == .File); | |
| 483 | try testing.expect(stat.kind == .File); | |
| 484 | 484 | file.close(); |
| 485 | 485 | |
| 486 | 486 | // Renaming directories |
| ... | ... | @@ -493,7 +493,7 @@ test "renameAbsolute" { |
| 493 | 493 | ); |
| 494 | 494 | |
| 495 | 495 | // 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 | 497 | var dir = try tmp_dir.dir.openDir(renamed_test_dir_name, .{}); |
| 498 | 498 | dir.close(); |
| 499 | 499 | } |
| ... | ... | @@ -516,7 +516,7 @@ test "makePath, put some files in it, deleteTree" { |
| 516 | 516 | if (tmp.dir.openDir("os_test_tmp", .{})) |dir| { |
| 517 | 517 | @panic("expected error"); |
| 518 | 518 | } else |err| { |
| 519 | testing.expect(err == error.FileNotFound); | |
| 519 | try testing.expect(err == error.FileNotFound); | |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| ... | ... | @@ -530,7 +530,7 @@ test "access file" { |
| 530 | 530 | if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| { |
| 531 | 531 | @panic("expected error"); |
| 532 | 532 | } else |err| { |
| 533 | testing.expect(err == error.FileNotFound); | |
| 533 | try testing.expect(err == error.FileNotFound); | |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", ""); |
| ... | ... | @@ -600,7 +600,7 @@ test "sendfile" { |
| 600 | 600 | .header_count = 2, |
| 601 | 601 | }); |
| 602 | 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 | } |
| 605 | 605 | |
| 606 | 606 | test "copyRangeAll" { |
| ... | ... | @@ -626,7 +626,7 @@ test "copyRangeAll" { |
| 626 | 626 | _ = try src_file.copyRangeAll(0, dest_file, 0, data.len); |
| 627 | 627 | |
| 628 | 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 | } |
| 631 | 631 | |
| 632 | 632 | test "fs.copyFile" { |
| ... | ... | @@ -655,7 +655,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { |
| 655 | 655 | const contents = try dir.readFileAlloc(testing.allocator, file_path, 1000); |
| 656 | 656 | defer testing.allocator.free(contents); |
| 657 | 657 | |
| 658 | testing.expectEqualSlices(u8, data, contents); | |
| 658 | try testing.expectEqualSlices(u8, data, contents); | |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | test "AtomicFile" { |
| ... | ... | @@ -676,7 +676,7 @@ test "AtomicFile" { |
| 676 | 676 | } |
| 677 | 677 | const content = try tmp.dir.readFileAlloc(testing.allocator, test_out_file, 9999); |
| 678 | 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)); | |
| 680 | 680 | |
| 681 | 681 | try tmp.dir.deleteFile(test_out_file); |
| 682 | 682 | } |
| ... | ... | @@ -685,7 +685,7 @@ test "realpath" { |
| 685 | 685 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 686 | 686 | |
| 687 | 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 | } |
| 690 | 690 | |
| 691 | 691 | test "open file with exclusive nonblocking lock twice" { |
| ... | ... | @@ -700,7 +700,7 @@ test "open file with exclusive nonblocking lock twice" { |
| 700 | 700 | defer file1.close(); |
| 701 | 701 | |
| 702 | 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 | } |
| 705 | 705 | |
| 706 | 706 | test "open file with shared and exclusive nonblocking lock" { |
| ... | ... | @@ -715,7 +715,7 @@ test "open file with shared and exclusive nonblocking lock" { |
| 715 | 715 | defer file1.close(); |
| 716 | 716 | |
| 717 | 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 | } |
| 720 | 720 | |
| 721 | 721 | test "open file with exclusive and shared nonblocking lock" { |
| ... | ... | @@ -730,7 +730,7 @@ test "open file with exclusive and shared nonblocking lock" { |
| 730 | 730 | defer file1.close(); |
| 731 | 731 | |
| 732 | 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 | } |
| 735 | 735 | |
| 736 | 736 | test "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 | 790 | |
| 791 | 791 | const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true }); |
| 792 | 792 | file1.close(); |
| 793 | testing.expectError(error.WouldBlock, file2); | |
| 793 | try testing.expectError(error.WouldBlock, file2); | |
| 794 | 794 | |
| 795 | 795 | try fs.deleteFileAbsolute(filename); |
| 796 | 796 | } |
| ... | ... | @@ -830,6 +830,6 @@ test "walker" { |
| 830 | 830 | try fs.path.join(allocator, &[_][]const u8{ expected_dir_name, name }); |
| 831 | 831 | |
| 832 | 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 | 174 | |
| 175 | 175 | try preopens.populate(); |
| 176 | 176 | |
| 177 | std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len); | |
| 177 | try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len); | |
| 178 | 178 | const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable; |
| 179 | std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." })); | |
| 180 | std.testing.expectEqual(@as(usize, 3), preopen.fd); | |
| 179 | try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." })); | |
| 180 | try std.testing.expectEqual(@as(usize, 3), preopen.fd); | |
| 181 | 181 | } |
lib/std/fs/watch.zig+3-3| ... | ... | @@ -662,13 +662,13 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void { |
| 662 | 662 | |
| 663 | 663 | const read_contents = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024); |
| 664 | 664 | defer allocator.free(read_contents); |
| 665 | testing.expectEqualSlices(u8, contents, read_contents); | |
| 665 | try testing.expectEqualSlices(u8, contents, read_contents); | |
| 666 | 666 | |
| 667 | 667 | // now watch the file |
| 668 | 668 | var watch = try Watch(void).init(allocator, 0); |
| 669 | 669 | defer watch.deinit(); |
| 670 | 670 | |
| 671 | testing.expect((try watch.addFile(file_path, {})) == null); | |
| 671 | try testing.expect((try watch.addFile(file_path, {})) == null); | |
| 672 | 672 | |
| 673 | 673 | var ev = async watch.channel.get(); |
| 674 | 674 | var ev_consumed = false; |
| ... | ... | @@ -698,7 +698,7 @@ fn testWriteWatchWriteDelete(allocator: *Allocator) !void { |
| 698 | 698 | const contents_updated = try std.fs.cwd().readFileAlloc(allocator, file_path, 1024 * 1024); |
| 699 | 699 | defer allocator.free(contents_updated); |
| 700 | 700 | |
| 701 | testing.expectEqualSlices(u8, | |
| 701 | try testing.expectEqualSlices(u8, | |
| 702 | 702 | \\line 1 |
| 703 | 703 | \\lorem ipsum |
| 704 | 704 | , contents_updated); |
lib/std/hash/adler.zig+6-6| ... | ... | @@ -99,21 +99,21 @@ pub const Adler32 = struct { |
| 99 | 99 | }; |
| 100 | 100 | |
| 101 | 101 | test "adler32 sanity" { |
| 102 | testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a")); | |
| 103 | testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example")); | |
| 102 | try testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a")); | |
| 103 | try testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example")); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | test "adler32 long" { |
| 107 | 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..])); | |
| 109 | 109 | |
| 110 | 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 | } |
| 113 | 113 | |
| 114 | 114 | test "adler32 very long" { |
| 115 | 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 | } |
| 118 | 118 | |
| 119 | 119 | test "adler32 very long with variation" { |
| ... | ... | @@ -129,5 +129,5 @@ test "adler32 very long with variation" { |
| 129 | 129 | break :blk result; |
| 130 | 130 | }; |
| 131 | 131 | |
| 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 | 239 | |
| 240 | 240 | test "typeContainsSlice" { |
| 241 | 241 | comptime { |
| 242 | testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo))); | |
| 242 | try testing.expect(!typeContainsSlice(meta.Tag(std.builtin.TypeInfo))); | |
| 243 | 243 | |
| 244 | testing.expect(typeContainsSlice([]const u8)); | |
| 245 | testing.expect(!typeContainsSlice(u8)); | |
| 244 | try testing.expect(typeContainsSlice([]const u8)); | |
| 245 | try testing.expect(!typeContainsSlice(u8)); | |
| 246 | 246 | const A = struct { x: []const u8 }; |
| 247 | 247 | const B = struct { a: A }; |
| 248 | 248 | const C = struct { b: B }; |
| 249 | 249 | const D = struct { x: u8 }; |
| 250 | testing.expect(typeContainsSlice(A)); | |
| 251 | testing.expect(typeContainsSlice(B)); | |
| 252 | testing.expect(typeContainsSlice(C)); | |
| 253 | testing.expect(!typeContainsSlice(D)); | |
| 250 | try testing.expect(typeContainsSlice(A)); | |
| 251 | try testing.expect(typeContainsSlice(B)); | |
| 252 | try testing.expect(typeContainsSlice(C)); | |
| 253 | try testing.expect(!typeContainsSlice(D)); | |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
| ... | ... | @@ -261,17 +261,17 @@ test "hash pointer" { |
| 261 | 261 | const c = &array[2]; |
| 262 | 262 | const d = a; |
| 263 | 263 | |
| 264 | testing.expect(testHashShallow(a) == testHashShallow(d)); | |
| 265 | testing.expect(testHashShallow(a) != testHashShallow(c)); | |
| 266 | testing.expect(testHashShallow(a) != testHashShallow(b)); | |
| 264 | try testing.expect(testHashShallow(a) == testHashShallow(d)); | |
| 265 | try testing.expect(testHashShallow(a) != testHashShallow(c)); | |
| 266 | try testing.expect(testHashShallow(a) != testHashShallow(b)); | |
| 267 | 267 | |
| 268 | testing.expect(testHashDeep(a) == testHashDeep(a)); | |
| 269 | testing.expect(testHashDeep(a) == testHashDeep(c)); | |
| 270 | testing.expect(testHashDeep(a) == testHashDeep(b)); | |
| 268 | try testing.expect(testHashDeep(a) == testHashDeep(a)); | |
| 269 | try testing.expect(testHashDeep(a) == testHashDeep(c)); | |
| 270 | try testing.expect(testHashDeep(a) == testHashDeep(b)); | |
| 271 | 271 | |
| 272 | testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a)); | |
| 273 | testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c)); | |
| 274 | testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b)); | |
| 272 | try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(a)); | |
| 273 | try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(c)); | |
| 274 | try testing.expect(testHashDeepRecursive(a) == testHashDeepRecursive(b)); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | test "hash slice shallow" { |
| ... | ... | @@ -286,10 +286,10 @@ test "hash slice shallow" { |
| 286 | 286 | const a = array1[runtime_zero..]; |
| 287 | 287 | const b = array2[runtime_zero..]; |
| 288 | 288 | const c = array1[runtime_zero..3]; |
| 289 | testing.expect(testHashShallow(a) == testHashShallow(a)); | |
| 290 | testing.expect(testHashShallow(a) != testHashShallow(array1)); | |
| 291 | testing.expect(testHashShallow(a) != testHashShallow(b)); | |
| 292 | testing.expect(testHashShallow(a) != testHashShallow(c)); | |
| 289 | try testing.expect(testHashShallow(a) == testHashShallow(a)); | |
| 290 | try testing.expect(testHashShallow(a) != testHashShallow(array1)); | |
| 291 | try testing.expect(testHashShallow(a) != testHashShallow(b)); | |
| 292 | try testing.expect(testHashShallow(a) != testHashShallow(c)); | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | test "hash slice deep" { |
| ... | ... | @@ -302,10 +302,10 @@ test "hash slice deep" { |
| 302 | 302 | const a = array1[0..]; |
| 303 | 303 | const b = array2[0..]; |
| 304 | 304 | const c = array1[0..3]; |
| 305 | testing.expect(testHashDeep(a) == testHashDeep(a)); | |
| 306 | testing.expect(testHashDeep(a) == testHashDeep(array1)); | |
| 307 | testing.expect(testHashDeep(a) == testHashDeep(b)); | |
| 308 | testing.expect(testHashDeep(a) != testHashDeep(c)); | |
| 305 | try testing.expect(testHashDeep(a) == testHashDeep(a)); | |
| 306 | try testing.expect(testHashDeep(a) == testHashDeep(array1)); | |
| 307 | try testing.expect(testHashDeep(a) == testHashDeep(b)); | |
| 308 | try testing.expect(testHashDeep(a) != testHashDeep(c)); | |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | test "hash struct deep" { |
| ... | ... | @@ -331,28 +331,28 @@ test "hash struct deep" { |
| 331 | 331 | defer allocator.destroy(bar.c); |
| 332 | 332 | defer allocator.destroy(baz.c); |
| 333 | 333 | |
| 334 | testing.expect(testHashDeep(foo) == testHashDeep(bar)); | |
| 335 | testing.expect(testHashDeep(foo) != testHashDeep(baz)); | |
| 336 | testing.expect(testHashDeep(bar) != testHashDeep(baz)); | |
| 334 | try testing.expect(testHashDeep(foo) == testHashDeep(bar)); | |
| 335 | try testing.expect(testHashDeep(foo) != testHashDeep(baz)); | |
| 336 | try testing.expect(testHashDeep(bar) != testHashDeep(baz)); | |
| 337 | 337 | |
| 338 | 338 | var hasher = Wyhash.init(0); |
| 339 | 339 | const h = testHashDeep(foo); |
| 340 | 340 | autoHash(&hasher, foo.a); |
| 341 | 341 | autoHash(&hasher, foo.b); |
| 342 | 342 | autoHash(&hasher, foo.c.*); |
| 343 | testing.expectEqual(h, hasher.final()); | |
| 343 | try testing.expectEqual(h, hasher.final()); | |
| 344 | 344 | |
| 345 | 345 | const h2 = testHashDeepRecursive(&foo); |
| 346 | testing.expect(h2 != testHashDeep(&foo)); | |
| 347 | testing.expect(h2 == testHashDeep(foo)); | |
| 346 | try testing.expect(h2 != testHashDeep(&foo)); | |
| 347 | try testing.expect(h2 == testHashDeep(foo)); | |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | test "testHash optional" { |
| 351 | 351 | const a: ?u32 = 123; |
| 352 | 352 | const b: ?u32 = null; |
| 353 | testing.expectEqual(testHash(a), testHash(@as(u32, 123))); | |
| 354 | testing.expect(testHash(a) != testHash(b)); | |
| 355 | testing.expectEqual(testHash(b), 0); | |
| 353 | try testing.expectEqual(testHash(a), testHash(@as(u32, 123))); | |
| 354 | try testing.expect(testHash(a) != testHash(b)); | |
| 355 | try testing.expectEqual(testHash(b), 0); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | test "testHash array" { |
| ... | ... | @@ -362,7 +362,7 @@ test "testHash array" { |
| 362 | 362 | autoHash(&hasher, @as(u32, 1)); |
| 363 | 363 | autoHash(&hasher, @as(u32, 2)); |
| 364 | 364 | autoHash(&hasher, @as(u32, 3)); |
| 365 | testing.expectEqual(h, hasher.final()); | |
| 365 | try testing.expectEqual(h, hasher.final()); | |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | test "testHash struct" { |
| ... | ... | @@ -377,7 +377,7 @@ test "testHash struct" { |
| 377 | 377 | autoHash(&hasher, @as(u32, 1)); |
| 378 | 378 | autoHash(&hasher, @as(u32, 2)); |
| 379 | 379 | autoHash(&hasher, @as(u32, 3)); |
| 380 | testing.expectEqual(h, hasher.final()); | |
| 380 | try testing.expectEqual(h, hasher.final()); | |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | test "testHash union" { |
| ... | ... | @@ -390,12 +390,12 @@ test "testHash union" { |
| 390 | 390 | const a = Foo{ .A = 18 }; |
| 391 | 391 | var b = Foo{ .B = true }; |
| 392 | 392 | const c = Foo{ .C = 18 }; |
| 393 | testing.expect(testHash(a) == testHash(a)); | |
| 394 | testing.expect(testHash(a) != testHash(b)); | |
| 395 | testing.expect(testHash(a) != testHash(c)); | |
| 393 | try testing.expect(testHash(a) == testHash(a)); | |
| 394 | try testing.expect(testHash(a) != testHash(b)); | |
| 395 | try testing.expect(testHash(a) != testHash(c)); | |
| 396 | 396 | |
| 397 | 397 | b = Foo{ .A = 18 }; |
| 398 | testing.expect(testHash(a) == testHash(b)); | |
| 398 | try testing.expect(testHash(a) == testHash(b)); | |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | test "testHash vector" { |
| ... | ... | @@ -404,13 +404,13 @@ test "testHash vector" { |
| 404 | 404 | |
| 405 | 405 | const a: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 4 }; |
| 406 | 406 | const b: meta.Vector(4, u32) = [_]u32{ 1, 2, 3, 5 }; |
| 407 | testing.expect(testHash(a) == testHash(a)); | |
| 408 | testing.expect(testHash(a) != testHash(b)); | |
| 407 | try testing.expect(testHash(a) == testHash(a)); | |
| 408 | try testing.expect(testHash(a) != testHash(b)); | |
| 409 | 409 | |
| 410 | 410 | const c: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 4 }; |
| 411 | 411 | const d: meta.Vector(4, u31) = [_]u31{ 1, 2, 3, 5 }; |
| 412 | testing.expect(testHash(c) == testHash(c)); | |
| 413 | testing.expect(testHash(c) != testHash(d)); | |
| 412 | try testing.expect(testHash(c) == testHash(c)); | |
| 413 | try testing.expect(testHash(c) != testHash(d)); | |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | test "testHash error union" { |
| ... | ... | @@ -422,7 +422,7 @@ test "testHash error union" { |
| 422 | 422 | }; |
| 423 | 423 | const f = Foo{}; |
| 424 | 424 | const g: Errors!Foo = Errors.Test; |
| 425 | testing.expect(testHash(f) != testHash(g)); | |
| 426 | testing.expect(testHash(f) == testHash(Foo{})); | |
| 427 | testing.expect(testHash(g) == testHash(Errors.Test)); | |
| 425 | try testing.expect(testHash(f) != testHash(g)); | |
| 426 | try testing.expect(testHash(f) == testHash(Foo{})); | |
| 427 | try testing.expect(testHash(g) == testHash(Errors.Test)); | |
| 428 | 428 | } |
lib/std/hash/cityhash.zig+7-7| ... | ... | @@ -381,14 +381,14 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 { |
| 381 | 381 | |
| 382 | 382 | test "cityhash32" { |
| 383 | 383 | const Test = struct { |
| 384 | fn doTest() void { | |
| 384 | fn doTest() !void { | |
| 385 | 385 | // Note: SMHasher doesn't provide a 32bit version of the algorithm. |
| 386 | 386 | // Note: The implementation was verified against the Google Abseil version. |
| 387 | std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 388 | std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 387 | try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 388 | try std.testing.expectEqual(SMHasherTest(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 389 | 389 | } |
| 390 | 390 | }; |
| 391 | Test.doTest(); | |
| 391 | try Test.doTest(); | |
| 392 | 392 | // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test |
| 393 | 393 | // case once we ship stage2. |
| 394 | 394 | //@setEvalBranchQuota(50000); |
| ... | ... | @@ -397,13 +397,13 @@ test "cityhash32" { |
| 397 | 397 | |
| 398 | 398 | test "cityhash64" { |
| 399 | 399 | const Test = struct { |
| 400 | fn doTest() void { | |
| 400 | fn doTest() !void { | |
| 401 | 401 | // Note: This is not compliant with the SMHasher implementation of CityHash64! |
| 402 | 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 | 407 | // TODO This is uncommented to prevent OOM on the CI server. Re-enable this test |
| 408 | 408 | // case once we ship stage2. |
| 409 | 409 | //@setEvalBranchQuota(50000); |
lib/std/hash/crc.zig+12-12| ... | ... | @@ -109,9 +109,9 @@ test "crc32 ieee" { |
| 109 | 109 | |
| 110 | 110 | const Crc32Ieee = Crc32WithPoly(.IEEE); |
| 111 | 111 | |
| 112 | testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 113 | testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 114 | testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 112 | try testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 113 | try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 114 | try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "crc32 castagnoli" { |
| ... | ... | @@ -119,9 +119,9 @@ test "crc32 castagnoli" { |
| 119 | 119 | |
| 120 | 120 | const Crc32Castagnoli = Crc32WithPoly(.Castagnoli); |
| 121 | 121 | |
| 122 | testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 123 | testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 124 | testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 122 | try testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 123 | try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 124 | try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // half-byte lookup table implementation. |
| ... | ... | @@ -177,9 +177,9 @@ test "small crc32 ieee" { |
| 177 | 177 | |
| 178 | 178 | const Crc32Ieee = Crc32SmallWithPoly(.IEEE); |
| 179 | 179 | |
| 180 | testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 181 | testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 182 | testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 180 | try testing.expect(Crc32Ieee.hash("") == 0x00000000); | |
| 181 | try testing.expect(Crc32Ieee.hash("a") == 0xe8b7be43); | |
| 182 | try testing.expect(Crc32Ieee.hash("abc") == 0x352441c2); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "small crc32 castagnoli" { |
| ... | ... | @@ -187,7 +187,7 @@ test "small crc32 castagnoli" { |
| 187 | 187 | |
| 188 | 188 | const Crc32Castagnoli = Crc32SmallWithPoly(.Castagnoli); |
| 189 | 189 | |
| 190 | testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 191 | testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 192 | testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 190 | try testing.expect(Crc32Castagnoli.hash("") == 0x00000000); | |
| 191 | try testing.expect(Crc32Castagnoli.hash("a") == 0xc1d04330); | |
| 192 | try testing.expect(Crc32Castagnoli.hash("abc") == 0x364b3fb7); | |
| 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 | 46 | } |
| 47 | 47 | |
| 48 | 48 | test "fnv1a-32" { |
| 49 | testing.expect(Fnv1a_32.hash("") == 0x811c9dc5); | |
| 50 | testing.expect(Fnv1a_32.hash("a") == 0xe40c292c); | |
| 51 | testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968); | |
| 49 | try testing.expect(Fnv1a_32.hash("") == 0x811c9dc5); | |
| 50 | try testing.expect(Fnv1a_32.hash("a") == 0xe40c292c); | |
| 51 | try testing.expect(Fnv1a_32.hash("foobar") == 0xbf9cf968); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "fnv1a-64" { |
| 55 | testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325); | |
| 56 | testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c); | |
| 57 | testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8); | |
| 55 | try testing.expect(Fnv1a_64.hash("") == 0xcbf29ce484222325); | |
| 56 | try testing.expect(Fnv1a_64.hash("a") == 0xaf63dc4c8601ec8c); | |
| 57 | try testing.expect(Fnv1a_64.hash("foobar") == 0x85944171f73967e8); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | test "fnv1a-128" { |
| 61 | testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d); | |
| 62 | testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964); | |
| 61 | try testing.expect(Fnv1a_128.hash("") == 0x6c62272e07bb014262b821756295c58d); | |
| 62 | try testing.expect(Fnv1a_128.hash("a") == 0xd228cb696f1a8caf78912b704e4a8964); | |
| 63 | 63 | } |
lib/std/hash/murmur.zig+9-9| ... | ... | @@ -308,7 +308,7 @@ fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 { |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | test "murmur2_32" { |
| 311 | testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E); | |
| 311 | try testing.expectEqual(SMHasherTest(Murmur2_32.hashWithSeed, 32), 0x27864C1E); | |
| 312 | 312 | var v0: u32 = 0x12345678; |
| 313 | 313 | var v1: u64 = 0x1234567812345678; |
| 314 | 314 | var v0le: u32 = v0; |
| ... | ... | @@ -317,12 +317,12 @@ test "murmur2_32" { |
| 317 | 317 | v0le = @byteSwap(u32, v0le); |
| 318 | 318 | v1le = @byteSwap(u64, v1le); |
| 319 | 319 | } |
| 320 | testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0)); | |
| 321 | testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1)); | |
| 320 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_32.hashUint32(v0)); | |
| 321 | try testing.expectEqual(Murmur2_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_32.hashUint64(v1)); | |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | test "murmur2_64" { |
| 325 | std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804); | |
| 325 | try std.testing.expectEqual(SMHasherTest(Murmur2_64.hashWithSeed, 64), 0x1F0D3804); | |
| 326 | 326 | var v0: u32 = 0x12345678; |
| 327 | 327 | var v1: u64 = 0x1234567812345678; |
| 328 | 328 | var v0le: u32 = v0; |
| ... | ... | @@ -331,12 +331,12 @@ test "murmur2_64" { |
| 331 | 331 | v0le = @byteSwap(u32, v0le); |
| 332 | 332 | v1le = @byteSwap(u64, v1le); |
| 333 | 333 | } |
| 334 | testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0)); | |
| 335 | testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1)); | |
| 334 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur2_64.hashUint32(v0)); | |
| 335 | try testing.expectEqual(Murmur2_64.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur2_64.hashUint64(v1)); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | test "murmur3_32" { |
| 339 | std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3); | |
| 339 | try std.testing.expectEqual(SMHasherTest(Murmur3_32.hashWithSeed, 32), 0xB0F57EE3); | |
| 340 | 340 | var v0: u32 = 0x12345678; |
| 341 | 341 | var v1: u64 = 0x1234567812345678; |
| 342 | 342 | var v0le: u32 = v0; |
| ... | ... | @@ -345,6 +345,6 @@ test "murmur3_32" { |
| 345 | 345 | v0le = @byteSwap(u32, v0le); |
| 346 | 346 | v1le = @byteSwap(u64, v1le); |
| 347 | 347 | } |
| 348 | testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0)); | |
| 349 | testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1)); | |
| 348 | try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v0le)[0..4]), Murmur3_32.hashUint32(v0)); | |
| 349 | try testing.expectEqual(Murmur3_32.hash(@ptrCast([*]u8, &v1le)[0..8]), Murmur3_32.hashUint64(v1)); | |
| 350 | 350 | } |
lib/std/hash/wyhash.zig+11-11| ... | ... | @@ -183,13 +183,13 @@ const expectEqual = std.testing.expectEqual; |
| 183 | 183 | test "test vectors" { |
| 184 | 184 | const hash = Wyhash.hash; |
| 185 | 185 | |
| 186 | expectEqual(hash(0, ""), 0x0); | |
| 187 | expectEqual(hash(1, "a"), 0xbed235177f41d328); | |
| 188 | expectEqual(hash(2, "abc"), 0xbe348debe59b27c3); | |
| 189 | expectEqual(hash(3, "message digest"), 0x37320f657213a290); | |
| 190 | expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c); | |
| 191 | expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f); | |
| 192 | expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e); | |
| 186 | try expectEqual(hash(0, ""), 0x0); | |
| 187 | try expectEqual(hash(1, "a"), 0xbed235177f41d328); | |
| 188 | try expectEqual(hash(2, "abc"), 0xbe348debe59b27c3); | |
| 189 | try expectEqual(hash(3, "message digest"), 0x37320f657213a290); | |
| 190 | try expectEqual(hash(4, "abcdefghijklmnopqrstuvwxyz"), 0xd0b270e1d8a7019c); | |
| 191 | try expectEqual(hash(5, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0x602a1894d3bbfe7f); | |
| 192 | try expectEqual(hash(6, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 0x829e9c148b75970e); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | test "test vectors streaming" { |
| ... | ... | @@ -197,19 +197,19 @@ test "test vectors streaming" { |
| 197 | 197 | for ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") |e| { |
| 198 | 198 | wh.update(mem.asBytes(&e)); |
| 199 | 199 | } |
| 200 | expectEqual(wh.final(), 0x602a1894d3bbfe7f); | |
| 200 | try expectEqual(wh.final(), 0x602a1894d3bbfe7f); | |
| 201 | 201 | |
| 202 | 202 | const pattern = "1234567890"; |
| 203 | 203 | const count = 8; |
| 204 | 204 | const result = 0x829e9c148b75970e; |
| 205 | expectEqual(Wyhash.hash(6, pattern ** 8), result); | |
| 205 | try expectEqual(Wyhash.hash(6, pattern ** 8), result); | |
| 206 | 206 | |
| 207 | 207 | wh = Wyhash.init(6); |
| 208 | 208 | var i: u32 = 0; |
| 209 | 209 | while (i < count) : (i += 1) { |
| 210 | 210 | wh.update(pattern); |
| 211 | 211 | } |
| 212 | expectEqual(wh.final(), result); | |
| 212 | try expectEqual(wh.final(), result); | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | test "iterative non-divisible update" { |
| ... | ... | @@ -231,6 +231,6 @@ test "iterative non-divisible update" { |
| 231 | 231 | } |
| 232 | 232 | const iterative_hash = wy.final(); |
| 233 | 233 | |
| 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| ... | ... | @@ -824,15 +824,15 @@ test "std.hash_map basic usage" { |
| 824 | 824 | while (it.next()) |kv| { |
| 825 | 825 | sum += kv.key; |
| 826 | 826 | } |
| 827 | expect(sum == total); | |
| 827 | try expect(sum == total); | |
| 828 | 828 | |
| 829 | 829 | i = 0; |
| 830 | 830 | sum = 0; |
| 831 | 831 | while (i < count) : (i += 1) { |
| 832 | expectEqual(map.get(i).?, i); | |
| 832 | try expectEqual(map.get(i).?, i); | |
| 833 | 833 | sum += map.get(i).?; |
| 834 | 834 | } |
| 835 | expectEqual(total, sum); | |
| 835 | try expectEqual(total, sum); | |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | test "std.hash_map ensureCapacity" { |
| ... | ... | @@ -841,13 +841,13 @@ test "std.hash_map ensureCapacity" { |
| 841 | 841 | |
| 842 | 842 | try map.ensureCapacity(20); |
| 843 | 843 | const initial_capacity = map.capacity(); |
| 844 | testing.expect(initial_capacity >= 20); | |
| 844 | try testing.expect(initial_capacity >= 20); | |
| 845 | 845 | var i: i32 = 0; |
| 846 | 846 | while (i < 20) : (i += 1) { |
| 847 | testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null); | |
| 847 | try testing.expect(map.fetchPutAssumeCapacity(i, i + 10) == null); | |
| 848 | 848 | } |
| 849 | 849 | // shouldn't resize from putAssumeCapacity |
| 850 | testing.expect(initial_capacity == map.capacity()); | |
| 850 | try testing.expect(initial_capacity == map.capacity()); | |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | test "std.hash_map ensureCapacity with tombstones" { |
| ... | ... | @@ -870,22 +870,22 @@ test "std.hash_map clearRetainingCapacity" { |
| 870 | 870 | map.clearRetainingCapacity(); |
| 871 | 871 | |
| 872 | 872 | try map.put(1, 1); |
| 873 | expectEqual(map.get(1).?, 1); | |
| 874 | expectEqual(map.count(), 1); | |
| 873 | try expectEqual(map.get(1).?, 1); | |
| 874 | try expectEqual(map.count(), 1); | |
| 875 | 875 | |
| 876 | 876 | map.clearRetainingCapacity(); |
| 877 | 877 | map.putAssumeCapacity(1, 1); |
| 878 | expectEqual(map.get(1).?, 1); | |
| 879 | expectEqual(map.count(), 1); | |
| 878 | try expectEqual(map.get(1).?, 1); | |
| 879 | try expectEqual(map.count(), 1); | |
| 880 | 880 | |
| 881 | 881 | const cap = map.capacity(); |
| 882 | expect(cap > 0); | |
| 882 | try expect(cap > 0); | |
| 883 | 883 | |
| 884 | 884 | map.clearRetainingCapacity(); |
| 885 | 885 | map.clearRetainingCapacity(); |
| 886 | expectEqual(map.count(), 0); | |
| 887 | expectEqual(map.capacity(), cap); | |
| 888 | expect(!map.contains(1)); | |
| 886 | try expectEqual(map.count(), 0); | |
| 887 | try expectEqual(map.capacity(), cap); | |
| 888 | try expect(!map.contains(1)); | |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | test "std.hash_map grow" { |
| ... | ... | @@ -898,19 +898,19 @@ test "std.hash_map grow" { |
| 898 | 898 | while (i < growTo) : (i += 1) { |
| 899 | 899 | try map.put(i, i); |
| 900 | 900 | } |
| 901 | expectEqual(map.count(), growTo); | |
| 901 | try expectEqual(map.count(), growTo); | |
| 902 | 902 | |
| 903 | 903 | i = 0; |
| 904 | 904 | var it = map.iterator(); |
| 905 | 905 | while (it.next()) |kv| { |
| 906 | expectEqual(kv.key, kv.value); | |
| 906 | try expectEqual(kv.key, kv.value); | |
| 907 | 907 | i += 1; |
| 908 | 908 | } |
| 909 | expectEqual(i, growTo); | |
| 909 | try expectEqual(i, growTo); | |
| 910 | 910 | |
| 911 | 911 | i = 0; |
| 912 | 912 | while (i < growTo) : (i += 1) { |
| 913 | expectEqual(map.get(i).?, i); | |
| 913 | try expectEqual(map.get(i).?, i); | |
| 914 | 914 | } |
| 915 | 915 | } |
| 916 | 916 | |
| ... | ... | @@ -921,7 +921,7 @@ test "std.hash_map clone" { |
| 921 | 921 | var a = try map.clone(); |
| 922 | 922 | defer a.deinit(); |
| 923 | 923 | |
| 924 | expectEqual(a.count(), 0); | |
| 924 | try expectEqual(a.count(), 0); | |
| 925 | 925 | |
| 926 | 926 | try a.put(1, 1); |
| 927 | 927 | try a.put(2, 2); |
| ... | ... | @@ -930,10 +930,10 @@ test "std.hash_map clone" { |
| 930 | 930 | var b = try a.clone(); |
| 931 | 931 | defer b.deinit(); |
| 932 | 932 | |
| 933 | expectEqual(b.count(), 3); | |
| 934 | expectEqual(b.get(1), 1); | |
| 935 | expectEqual(b.get(2), 2); | |
| 936 | expectEqual(b.get(3), 3); | |
| 933 | try expectEqual(b.count(), 3); | |
| 934 | try expectEqual(b.get(1), 1); | |
| 935 | try expectEqual(b.get(2), 2); | |
| 936 | try expectEqual(b.get(3), 3); | |
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | test "std.hash_map ensureCapacity with existing elements" { |
| ... | ... | @@ -941,12 +941,12 @@ test "std.hash_map ensureCapacity with existing elements" { |
| 941 | 941 | defer map.deinit(); |
| 942 | 942 | |
| 943 | 943 | try map.put(0, 0); |
| 944 | expectEqual(map.count(), 1); | |
| 945 | expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity); | |
| 944 | try expectEqual(map.count(), 1); | |
| 945 | try expectEqual(map.capacity(), @TypeOf(map).Unmanaged.minimal_capacity); | |
| 946 | 946 | |
| 947 | 947 | try map.ensureCapacity(65); |
| 948 | expectEqual(map.count(), 1); | |
| 949 | expectEqual(map.capacity(), 128); | |
| 948 | try expectEqual(map.count(), 1); | |
| 949 | try expectEqual(map.capacity(), 128); | |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | test "std.hash_map ensureCapacity satisfies max load factor" { |
| ... | ... | @@ -954,7 +954,7 @@ test "std.hash_map ensureCapacity satisfies max load factor" { |
| 954 | 954 | defer map.deinit(); |
| 955 | 955 | |
| 956 | 956 | try map.ensureCapacity(127); |
| 957 | expectEqual(map.capacity(), 256); | |
| 957 | try expectEqual(map.capacity(), 256); | |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | test "std.hash_map remove" { |
| ... | ... | @@ -972,19 +972,19 @@ test "std.hash_map remove" { |
| 972 | 972 | _ = map.remove(i); |
| 973 | 973 | } |
| 974 | 974 | } |
| 975 | expectEqual(map.count(), 10); | |
| 975 | try expectEqual(map.count(), 10); | |
| 976 | 976 | var it = map.iterator(); |
| 977 | 977 | while (it.next()) |kv| { |
| 978 | expectEqual(kv.key, kv.value); | |
| 979 | expect(kv.key % 3 != 0); | |
| 978 | try expectEqual(kv.key, kv.value); | |
| 979 | try expect(kv.key % 3 != 0); | |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | i = 0; |
| 983 | 983 | while (i < 16) : (i += 1) { |
| 984 | 984 | if (i % 3 == 0) { |
| 985 | expect(!map.contains(i)); | |
| 985 | try expect(!map.contains(i)); | |
| 986 | 986 | } else { |
| 987 | expectEqual(map.get(i).?, i); | |
| 987 | try expectEqual(map.get(i).?, i); | |
| 988 | 988 | } |
| 989 | 989 | } |
| 990 | 990 | } |
| ... | ... | @@ -1001,14 +1001,14 @@ test "std.hash_map reverse removes" { |
| 1001 | 1001 | i = 16; |
| 1002 | 1002 | while (i > 0) : (i -= 1) { |
| 1003 | 1003 | _ = map.remove(i - 1); |
| 1004 | expect(!map.contains(i - 1)); | |
| 1004 | try expect(!map.contains(i - 1)); | |
| 1005 | 1005 | var j: u32 = 0; |
| 1006 | 1006 | while (j < i - 1) : (j += 1) { |
| 1007 | expectEqual(map.get(j).?, j); | |
| 1007 | try expectEqual(map.get(j).?, j); | |
| 1008 | 1008 | } |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | expectEqual(map.count(), 0); | |
| 1011 | try expectEqual(map.count(), 0); | |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | test "std.hash_map multiple removes on same metadata" { |
| ... | ... | @@ -1024,17 +1024,17 @@ test "std.hash_map multiple removes on same metadata" { |
| 1024 | 1024 | _ = map.remove(15); |
| 1025 | 1025 | _ = map.remove(14); |
| 1026 | 1026 | _ = map.remove(13); |
| 1027 | expect(!map.contains(7)); | |
| 1028 | expect(!map.contains(15)); | |
| 1029 | expect(!map.contains(14)); | |
| 1030 | expect(!map.contains(13)); | |
| 1027 | try expect(!map.contains(7)); | |
| 1028 | try expect(!map.contains(15)); | |
| 1029 | try expect(!map.contains(14)); | |
| 1030 | try expect(!map.contains(13)); | |
| 1031 | 1031 | |
| 1032 | 1032 | i = 0; |
| 1033 | 1033 | while (i < 13) : (i += 1) { |
| 1034 | 1034 | if (i == 7) { |
| 1035 | expect(!map.contains(i)); | |
| 1035 | try expect(!map.contains(i)); | |
| 1036 | 1036 | } else { |
| 1037 | expectEqual(map.get(i).?, i); | |
| 1037 | try expectEqual(map.get(i).?, i); | |
| 1038 | 1038 | } |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| ... | ... | @@ -1044,7 +1044,7 @@ test "std.hash_map multiple removes on same metadata" { |
| 1044 | 1044 | try map.put(7, 7); |
| 1045 | 1045 | i = 0; |
| 1046 | 1046 | while (i < 16) : (i += 1) { |
| 1047 | expectEqual(map.get(i).?, i); | |
| 1047 | try expectEqual(map.get(i).?, i); | |
| 1048 | 1048 | } |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| ... | ... | @@ -1070,12 +1070,12 @@ test "std.hash_map put and remove loop in random order" { |
| 1070 | 1070 | for (keys.items) |key| { |
| 1071 | 1071 | try map.put(key, key); |
| 1072 | 1072 | } |
| 1073 | expectEqual(map.count(), size); | |
| 1073 | try expectEqual(map.count(), size); | |
| 1074 | 1074 | |
| 1075 | 1075 | for (keys.items) |key| { |
| 1076 | 1076 | _ = map.remove(key); |
| 1077 | 1077 | } |
| 1078 | expectEqual(map.count(), 0); | |
| 1078 | try expectEqual(map.count(), 0); | |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| ... | ... | @@ -1119,7 +1119,7 @@ test "std.hash_map put" { |
| 1119 | 1119 | |
| 1120 | 1120 | i = 0; |
| 1121 | 1121 | while (i < 16) : (i += 1) { |
| 1122 | expectEqual(map.get(i).?, i); | |
| 1122 | try expectEqual(map.get(i).?, i); | |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | i = 0; |
| ... | ... | @@ -1129,7 +1129,7 @@ test "std.hash_map put" { |
| 1129 | 1129 | |
| 1130 | 1130 | i = 0; |
| 1131 | 1131 | while (i < 16) : (i += 1) { |
| 1132 | expectEqual(map.get(i).?, i * 16 + 1); | |
| 1132 | try expectEqual(map.get(i).?, i * 16 + 1); | |
| 1133 | 1133 | } |
| 1134 | 1134 | } |
| 1135 | 1135 | |
| ... | ... | @@ -1148,7 +1148,7 @@ test "std.hash_map putAssumeCapacity" { |
| 1148 | 1148 | while (i < 20) : (i += 1) { |
| 1149 | 1149 | sum += map.get(i).?; |
| 1150 | 1150 | } |
| 1151 | expectEqual(sum, 190); | |
| 1151 | try expectEqual(sum, 190); | |
| 1152 | 1152 | |
| 1153 | 1153 | i = 0; |
| 1154 | 1154 | while (i < 20) : (i += 1) { |
| ... | ... | @@ -1160,7 +1160,7 @@ test "std.hash_map putAssumeCapacity" { |
| 1160 | 1160 | while (i < 20) : (i += 1) { |
| 1161 | 1161 | sum += map.get(i).?; |
| 1162 | 1162 | } |
| 1163 | expectEqual(sum, 20); | |
| 1163 | try expectEqual(sum, 20); | |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | test "std.hash_map getOrPut" { |
| ... | ... | @@ -1183,49 +1183,49 @@ test "std.hash_map getOrPut" { |
| 1183 | 1183 | sum += map.get(i).?; |
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | expectEqual(sum, 30); | |
| 1186 | try expectEqual(sum, 30); | |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | test "std.hash_map basic hash map usage" { |
| 1190 | 1190 | var map = AutoHashMap(i32, i32).init(std.testing.allocator); |
| 1191 | 1191 | defer map.deinit(); |
| 1192 | 1192 | |
| 1193 | testing.expect((try map.fetchPut(1, 11)) == null); | |
| 1194 | testing.expect((try map.fetchPut(2, 22)) == null); | |
| 1195 | testing.expect((try map.fetchPut(3, 33)) == null); | |
| 1196 | testing.expect((try map.fetchPut(4, 44)) == null); | |
| 1193 | try testing.expect((try map.fetchPut(1, 11)) == null); | |
| 1194 | try testing.expect((try map.fetchPut(2, 22)) == null); | |
| 1195 | try testing.expect((try map.fetchPut(3, 33)) == null); | |
| 1196 | try testing.expect((try map.fetchPut(4, 44)) == null); | |
| 1197 | 1197 | |
| 1198 | 1198 | try map.putNoClobber(5, 55); |
| 1199 | testing.expect((try map.fetchPut(5, 66)).?.value == 55); | |
| 1200 | testing.expect((try map.fetchPut(5, 55)).?.value == 66); | |
| 1199 | try testing.expect((try map.fetchPut(5, 66)).?.value == 55); | |
| 1200 | try testing.expect((try map.fetchPut(5, 55)).?.value == 66); | |
| 1201 | 1201 | |
| 1202 | 1202 | const gop1 = try map.getOrPut(5); |
| 1203 | testing.expect(gop1.found_existing == true); | |
| 1204 | testing.expect(gop1.entry.value == 55); | |
| 1203 | try testing.expect(gop1.found_existing == true); | |
| 1204 | try testing.expect(gop1.entry.value == 55); | |
| 1205 | 1205 | gop1.entry.value = 77; |
| 1206 | testing.expect(map.getEntry(5).?.value == 77); | |
| 1206 | try testing.expect(map.getEntry(5).?.value == 77); | |
| 1207 | 1207 | |
| 1208 | 1208 | const gop2 = try map.getOrPut(99); |
| 1209 | testing.expect(gop2.found_existing == false); | |
| 1209 | try testing.expect(gop2.found_existing == false); | |
| 1210 | 1210 | gop2.entry.value = 42; |
| 1211 | testing.expect(map.getEntry(99).?.value == 42); | |
| 1211 | try testing.expect(map.getEntry(99).?.value == 42); | |
| 1212 | 1212 | |
| 1213 | 1213 | const gop3 = try map.getOrPutValue(5, 5); |
| 1214 | testing.expect(gop3.value == 77); | |
| 1214 | try testing.expect(gop3.value == 77); | |
| 1215 | 1215 | |
| 1216 | 1216 | const gop4 = try map.getOrPutValue(100, 41); |
| 1217 | testing.expect(gop4.value == 41); | |
| 1217 | try testing.expect(gop4.value == 41); | |
| 1218 | 1218 | |
| 1219 | testing.expect(map.contains(2)); | |
| 1220 | testing.expect(map.getEntry(2).?.value == 22); | |
| 1221 | testing.expect(map.get(2).? == 22); | |
| 1219 | try testing.expect(map.contains(2)); | |
| 1220 | try testing.expect(map.getEntry(2).?.value == 22); | |
| 1221 | try testing.expect(map.get(2).? == 22); | |
| 1222 | 1222 | |
| 1223 | 1223 | const rmv1 = map.remove(2); |
| 1224 | testing.expect(rmv1.?.key == 2); | |
| 1225 | testing.expect(rmv1.?.value == 22); | |
| 1226 | testing.expect(map.remove(2) == null); | |
| 1227 | testing.expect(map.getEntry(2) == null); | |
| 1228 | testing.expect(map.get(2) == null); | |
| 1224 | try testing.expect(rmv1.?.key == 2); | |
| 1225 | try testing.expect(rmv1.?.value == 22); | |
| 1226 | try testing.expect(map.remove(2) == null); | |
| 1227 | try testing.expect(map.getEntry(2) == null); | |
| 1228 | try testing.expect(map.get(2) == null); | |
| 1229 | 1229 | |
| 1230 | 1230 | map.removeAssertDiscard(3); |
| 1231 | 1231 | } |
| ... | ... | @@ -1244,6 +1244,6 @@ test "std.hash_map clone" { |
| 1244 | 1244 | |
| 1245 | 1245 | i = 0; |
| 1246 | 1246 | while (i < 10) : (i += 1) { |
| 1247 | testing.expect(copy.get(i).? == i * 10); | |
| 1247 | try testing.expect(copy.get(i).? == i * 10); | |
| 1248 | 1248 | } |
| 1249 | 1249 | } |
lib/std/heap.zig+43-43| ... | ... | @@ -858,16 +858,16 @@ test "WasmPageAllocator internals" { |
| 858 | 858 | if (comptime std.Target.current.isWasm()) { |
| 859 | 859 | const conventional_memsize = WasmPageAllocator.conventional.totalPages() * mem.page_size; |
| 860 | 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. | |
| 862 | 862 | |
| 863 | 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 | 865 | inplace = try page_allocator.realloc(inplace, 4); |
| 866 | testing.expectEqual(initial.ptr, inplace.ptr); | |
| 866 | try testing.expectEqual(initial.ptr, inplace.ptr); | |
| 867 | 867 | page_allocator.free(inplace); |
| 868 | 868 | |
| 869 | 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 | 871 | page_allocator.free(reuse); |
| 872 | 872 | |
| 873 | 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 | 875 | page_allocator.free(padding); |
| 876 | 876 | |
| 877 | 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); | |
| 879 | 879 | |
| 880 | 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 | 882 | page_allocator.free(use_small); |
| 883 | 883 | |
| 884 | 884 | inplace = try page_allocator.realloc(extended, 1); |
| 885 | testing.expectEqual(extended.ptr, inplace.ptr); | |
| 885 | try testing.expectEqual(extended.ptr, inplace.ptr); | |
| 886 | 886 | page_allocator.free(inplace); |
| 887 | 887 | |
| 888 | 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 | 890 | page_allocator.free(reuse_extended); |
| 891 | 891 | } |
| 892 | 892 | } |
| ... | ... | @@ -959,15 +959,15 @@ test "FixedBufferAllocator.reset" { |
| 959 | 959 | |
| 960 | 960 | var x = try fba.allocator.create(u64); |
| 961 | 961 | x.* = X; |
| 962 | testing.expectError(error.OutOfMemory, fba.allocator.create(u64)); | |
| 962 | try testing.expectError(error.OutOfMemory, fba.allocator.create(u64)); | |
| 963 | 963 | |
| 964 | 964 | fba.reset(); |
| 965 | 965 | var y = try fba.allocator.create(u64); |
| 966 | 966 | y.* = Y; |
| 967 | 967 | |
| 968 | 968 | // we expect Y to have overwritten X. |
| 969 | testing.expect(x.* == y.*); | |
| 970 | testing.expect(y.* == Y); | |
| 969 | try testing.expect(x.* == y.*); | |
| 970 | try testing.expect(y.* == Y); | |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | 973 | test "StackFallbackAllocator" { |
| ... | ... | @@ -987,11 +987,11 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 987 | 987 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); |
| 988 | 988 | |
| 989 | 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 | 991 | var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10); |
| 992 | testing.expect(slice1.ptr == slice0.ptr); | |
| 993 | testing.expect(slice1.len == 10); | |
| 994 | testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11)); | |
| 992 | try testing.expect(slice1.ptr == slice0.ptr); | |
| 993 | try testing.expect(slice1.len == 10); | |
| 994 | try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11)); | |
| 995 | 995 | } |
| 996 | 996 | // 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 | 1002 | slice0[1] = 2; |
| 1003 | 1003 | var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2); |
| 1004 | 1004 | var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4); |
| 1005 | testing.expect(slice0.ptr != slice2.ptr); | |
| 1006 | testing.expect(slice1.ptr != slice2.ptr); | |
| 1007 | testing.expect(slice2[0] == 1); | |
| 1008 | testing.expect(slice2[1] == 2); | |
| 1005 | try testing.expect(slice0.ptr != slice2.ptr); | |
| 1006 | try testing.expect(slice1.ptr != slice2.ptr); | |
| 1007 | try testing.expect(slice2[0] == 1); | |
| 1008 | try testing.expect(slice2[1] == 2); | |
| 1009 | 1009 | } |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| ... | ... | @@ -1024,28 +1024,28 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void { |
| 1024 | 1024 | const allocator = &validationAllocator.allocator; |
| 1025 | 1025 | |
| 1026 | 1026 | var slice = try allocator.alloc(*i32, 100); |
| 1027 | testing.expect(slice.len == 100); | |
| 1027 | try testing.expect(slice.len == 100); | |
| 1028 | 1028 | for (slice) |*item, i| { |
| 1029 | 1029 | item.* = try allocator.create(i32); |
| 1030 | 1030 | item.*.* = @intCast(i32, i); |
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | slice = try allocator.realloc(slice, 20000); |
| 1034 | testing.expect(slice.len == 20000); | |
| 1034 | try testing.expect(slice.len == 20000); | |
| 1035 | 1035 | |
| 1036 | 1036 | for (slice[0..100]) |item, i| { |
| 1037 | testing.expect(item.* == @intCast(i32, i)); | |
| 1037 | try testing.expect(item.* == @intCast(i32, i)); | |
| 1038 | 1038 | allocator.destroy(item); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | slice = allocator.shrink(slice, 50); |
| 1042 | testing.expect(slice.len == 50); | |
| 1042 | try testing.expect(slice.len == 50); | |
| 1043 | 1043 | slice = allocator.shrink(slice, 25); |
| 1044 | testing.expect(slice.len == 25); | |
| 1044 | try testing.expect(slice.len == 25); | |
| 1045 | 1045 | slice = allocator.shrink(slice, 0); |
| 1046 | testing.expect(slice.len == 0); | |
| 1046 | try testing.expect(slice.len == 0); | |
| 1047 | 1047 | slice = try allocator.realloc(slice, 10); |
| 1048 | testing.expect(slice.len == 10); | |
| 1048 | try testing.expect(slice.len == 10); | |
| 1049 | 1049 | |
| 1050 | 1050 | allocator.free(slice); |
| 1051 | 1051 | |
| ... | ... | @@ -1058,7 +1058,7 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void { |
| 1058 | 1058 | allocator.destroy(zero_bit_ptr); |
| 1059 | 1059 | |
| 1060 | 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 | 1062 | for (oversize) |*item| { |
| 1063 | 1063 | item.* = 0xDEADBEEF; |
| 1064 | 1064 | } |
| ... | ... | @@ -1073,29 +1073,29 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void { |
| 1073 | 1073 | inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| { |
| 1074 | 1074 | // initial |
| 1075 | 1075 | var slice = try allocator.alignedAlloc(u8, alignment, 10); |
| 1076 | testing.expect(slice.len == 10); | |
| 1076 | try testing.expect(slice.len == 10); | |
| 1077 | 1077 | // grow |
| 1078 | 1078 | slice = try allocator.realloc(slice, 100); |
| 1079 | testing.expect(slice.len == 100); | |
| 1079 | try testing.expect(slice.len == 100); | |
| 1080 | 1080 | // shrink |
| 1081 | 1081 | slice = allocator.shrink(slice, 10); |
| 1082 | testing.expect(slice.len == 10); | |
| 1082 | try testing.expect(slice.len == 10); | |
| 1083 | 1083 | // go to zero |
| 1084 | 1084 | slice = allocator.shrink(slice, 0); |
| 1085 | testing.expect(slice.len == 0); | |
| 1085 | try testing.expect(slice.len == 0); | |
| 1086 | 1086 | // realloc from zero |
| 1087 | 1087 | slice = try allocator.realloc(slice, 100); |
| 1088 | testing.expect(slice.len == 100); | |
| 1088 | try testing.expect(slice.len == 100); | |
| 1089 | 1089 | // shrink with shrink |
| 1090 | 1090 | slice = allocator.shrink(slice, 10); |
| 1091 | testing.expect(slice.len == 10); | |
| 1091 | try testing.expect(slice.len == 10); | |
| 1092 | 1092 | // shrink to zero |
| 1093 | 1093 | slice = allocator.shrink(slice, 0); |
| 1094 | testing.expect(slice.len == 0); | |
| 1094 | try testing.expect(slice.len == 0); | |
| 1095 | 1095 | } |
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator.Error!void { | |
| 1098 | pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void { | |
| 1099 | 1099 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1100 | 1100 | const allocator = &validationAllocator.allocator; |
| 1101 | 1101 | |
| ... | ... | @@ -1110,24 +1110,24 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator |
| 1110 | 1110 | _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(u29, large_align)), &align_mask); |
| 1111 | 1111 | |
| 1112 | 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)); | |
| 1114 | 1114 | |
| 1115 | 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)); | |
| 1117 | 1117 | |
| 1118 | 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)); | |
| 1120 | 1120 | |
| 1121 | 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)); | |
| 1123 | 1123 | |
| 1124 | 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)); | |
| 1126 | 1126 | |
| 1127 | 1127 | allocator.free(slice); |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator.Error!void { | |
| 1130 | pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void { | |
| 1131 | 1131 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1132 | 1132 | const allocator = &validationAllocator.allocator; |
| 1133 | 1133 | |
| ... | ... | @@ -1155,8 +1155,8 @@ pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) mem.Allocator. |
| 1155 | 1155 | |
| 1156 | 1156 | // realloc to a smaller size but with a larger alignment |
| 1157 | 1157 | slice = try allocator.reallocAdvanced(slice, mem.page_size * 32, alloc_size / 2, .exact); |
| 1158 | testing.expect(slice[0] == 0x12); | |
| 1159 | testing.expect(slice[60] == 0x34); | |
| 1158 | try testing.expect(slice[0] == 0x12); | |
| 1159 | try testing.expect(slice[60] == 0x34); | |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | test "heap" { |
lib/std/heap/general_purpose_allocator.zig+50-50| ... | ... | @@ -692,7 +692,7 @@ const test_config = Config{}; |
| 692 | 692 | |
| 693 | 693 | test "small allocations - free in same order" { |
| 694 | 694 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 695 | defer std.testing.expect(!gpa.deinit()); | |
| 695 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 696 | 696 | const allocator = &gpa.allocator; |
| 697 | 697 | |
| 698 | 698 | var list = std.ArrayList(*u64).init(std.testing.allocator); |
| ... | ... | @@ -711,7 +711,7 @@ test "small allocations - free in same order" { |
| 711 | 711 | |
| 712 | 712 | test "small allocations - free in reverse order" { |
| 713 | 713 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 714 | defer std.testing.expect(!gpa.deinit()); | |
| 714 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 715 | 715 | const allocator = &gpa.allocator; |
| 716 | 716 | |
| 717 | 717 | var list = std.ArrayList(*u64).init(std.testing.allocator); |
| ... | ... | @@ -730,7 +730,7 @@ test "small allocations - free in reverse order" { |
| 730 | 730 | |
| 731 | 731 | test "large allocations" { |
| 732 | 732 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 733 | defer std.testing.expect(!gpa.deinit()); | |
| 733 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 734 | 734 | const allocator = &gpa.allocator; |
| 735 | 735 | |
| 736 | 736 | const ptr1 = try allocator.alloc(u64, 42768); |
| ... | ... | @@ -743,7 +743,7 @@ test "large allocations" { |
| 743 | 743 | |
| 744 | 744 | test "realloc" { |
| 745 | 745 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 746 | defer std.testing.expect(!gpa.deinit()); | |
| 746 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 747 | 747 | const allocator = &gpa.allocator; |
| 748 | 748 | |
| 749 | 749 | var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1); |
| ... | ... | @@ -753,19 +753,19 @@ test "realloc" { |
| 753 | 753 | // This reallocation should keep its pointer address. |
| 754 | 754 | const old_slice = slice; |
| 755 | 755 | slice = try allocator.realloc(slice, 2); |
| 756 | std.testing.expect(old_slice.ptr == slice.ptr); | |
| 757 | std.testing.expect(slice[0] == 0x12); | |
| 756 | try std.testing.expect(old_slice.ptr == slice.ptr); | |
| 757 | try std.testing.expect(slice[0] == 0x12); | |
| 758 | 758 | slice[1] = 0x34; |
| 759 | 759 | |
| 760 | 760 | // This requires upgrading to a larger size class |
| 761 | 761 | slice = try allocator.realloc(slice, 17); |
| 762 | std.testing.expect(slice[0] == 0x12); | |
| 763 | std.testing.expect(slice[1] == 0x34); | |
| 762 | try std.testing.expect(slice[0] == 0x12); | |
| 763 | try std.testing.expect(slice[1] == 0x34); | |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | test "shrink" { |
| 767 | 767 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 768 | defer std.testing.expect(!gpa.deinit()); | |
| 768 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 769 | 769 | const allocator = &gpa.allocator; |
| 770 | 770 | |
| 771 | 771 | var slice = try allocator.alloc(u8, 20); |
| ... | ... | @@ -776,19 +776,19 @@ test "shrink" { |
| 776 | 776 | slice = allocator.shrink(slice, 17); |
| 777 | 777 | |
| 778 | 778 | for (slice) |b| { |
| 779 | std.testing.expect(b == 0x11); | |
| 779 | try std.testing.expect(b == 0x11); | |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | slice = allocator.shrink(slice, 16); |
| 783 | 783 | |
| 784 | 784 | for (slice) |b| { |
| 785 | std.testing.expect(b == 0x11); | |
| 785 | try std.testing.expect(b == 0x11); | |
| 786 | 786 | } |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | test "large object - grow" { |
| 790 | 790 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 791 | defer std.testing.expect(!gpa.deinit()); | |
| 791 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 792 | 792 | const allocator = &gpa.allocator; |
| 793 | 793 | |
| 794 | 794 | var slice1 = try allocator.alloc(u8, page_size * 2 - 20); |
| ... | ... | @@ -796,17 +796,17 @@ test "large object - grow" { |
| 796 | 796 | |
| 797 | 797 | const old = slice1; |
| 798 | 798 | slice1 = try allocator.realloc(slice1, page_size * 2 - 10); |
| 799 | std.testing.expect(slice1.ptr == old.ptr); | |
| 799 | try std.testing.expect(slice1.ptr == old.ptr); | |
| 800 | 800 | |
| 801 | 801 | slice1 = try allocator.realloc(slice1, page_size * 2); |
| 802 | std.testing.expect(slice1.ptr == old.ptr); | |
| 802 | try std.testing.expect(slice1.ptr == old.ptr); | |
| 803 | 803 | |
| 804 | 804 | slice1 = try allocator.realloc(slice1, page_size * 2 + 1); |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | test "realloc small object to large object" { |
| 808 | 808 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 809 | defer std.testing.expect(!gpa.deinit()); | |
| 809 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 810 | 810 | const allocator = &gpa.allocator; |
| 811 | 811 | |
| 812 | 812 | var slice = try allocator.alloc(u8, 70); |
| ... | ... | @@ -817,13 +817,13 @@ test "realloc small object to large object" { |
| 817 | 817 | // This requires upgrading to a large object |
| 818 | 818 | const large_object_size = page_size * 2 + 50; |
| 819 | 819 | slice = try allocator.realloc(slice, large_object_size); |
| 820 | std.testing.expect(slice[0] == 0x12); | |
| 821 | std.testing.expect(slice[60] == 0x34); | |
| 820 | try std.testing.expect(slice[0] == 0x12); | |
| 821 | try std.testing.expect(slice[60] == 0x34); | |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | test "shrink large object to large object" { |
| 825 | 825 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 826 | defer std.testing.expect(!gpa.deinit()); | |
| 826 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 827 | 827 | const allocator = &gpa.allocator; |
| 828 | 828 | |
| 829 | 829 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| ... | ... | @@ -832,21 +832,21 @@ test "shrink large object to large object" { |
| 832 | 832 | slice[60] = 0x34; |
| 833 | 833 | |
| 834 | 834 | slice = try allocator.resize(slice, page_size * 2 + 1); |
| 835 | std.testing.expect(slice[0] == 0x12); | |
| 836 | std.testing.expect(slice[60] == 0x34); | |
| 835 | try std.testing.expect(slice[0] == 0x12); | |
| 836 | try std.testing.expect(slice[60] == 0x34); | |
| 837 | 837 | |
| 838 | 838 | slice = allocator.shrink(slice, page_size * 2 + 1); |
| 839 | std.testing.expect(slice[0] == 0x12); | |
| 840 | std.testing.expect(slice[60] == 0x34); | |
| 839 | try std.testing.expect(slice[0] == 0x12); | |
| 840 | try std.testing.expect(slice[60] == 0x34); | |
| 841 | 841 | |
| 842 | 842 | slice = try allocator.realloc(slice, page_size * 2); |
| 843 | std.testing.expect(slice[0] == 0x12); | |
| 844 | std.testing.expect(slice[60] == 0x34); | |
| 843 | try std.testing.expect(slice[0] == 0x12); | |
| 844 | try std.testing.expect(slice[60] == 0x34); | |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | test "shrink large object to large object with larger alignment" { |
| 848 | 848 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 849 | defer std.testing.expect(!gpa.deinit()); | |
| 849 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 850 | 850 | const allocator = &gpa.allocator; |
| 851 | 851 | |
| 852 | 852 | var debug_buffer: [1000]u8 = undefined; |
| ... | ... | @@ -875,13 +875,13 @@ test "shrink large object to large object with larger alignment" { |
| 875 | 875 | slice[60] = 0x34; |
| 876 | 876 | |
| 877 | 877 | slice = try allocator.reallocAdvanced(slice, big_alignment, alloc_size / 2, .exact); |
| 878 | std.testing.expect(slice[0] == 0x12); | |
| 879 | std.testing.expect(slice[60] == 0x34); | |
| 878 | try std.testing.expect(slice[0] == 0x12); | |
| 879 | try std.testing.expect(slice[60] == 0x34); | |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | test "realloc large object to small object" { |
| 883 | 883 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 884 | defer std.testing.expect(!gpa.deinit()); | |
| 884 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 885 | 885 | const allocator = &gpa.allocator; |
| 886 | 886 | |
| 887 | 887 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| ... | ... | @@ -890,8 +890,8 @@ test "realloc large object to small object" { |
| 890 | 890 | slice[16] = 0x34; |
| 891 | 891 | |
| 892 | 892 | slice = try allocator.realloc(slice, 19); |
| 893 | std.testing.expect(slice[0] == 0x12); | |
| 894 | std.testing.expect(slice[16] == 0x34); | |
| 893 | try std.testing.expect(slice[0] == 0x12); | |
| 894 | try std.testing.expect(slice[16] == 0x34); | |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | test "overrideable mutexes" { |
| ... | ... | @@ -899,7 +899,7 @@ test "overrideable mutexes" { |
| 899 | 899 | .backing_allocator = std.testing.allocator, |
| 900 | 900 | .mutex = std.Thread.Mutex{}, |
| 901 | 901 | }; |
| 902 | defer std.testing.expect(!gpa.deinit()); | |
| 902 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 903 | 903 | const allocator = &gpa.allocator; |
| 904 | 904 | |
| 905 | 905 | const ptr = try allocator.create(i32); |
| ... | ... | @@ -908,7 +908,7 @@ test "overrideable mutexes" { |
| 908 | 908 | |
| 909 | 909 | test "non-page-allocator backing allocator" { |
| 910 | 910 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator }; |
| 911 | defer std.testing.expect(!gpa.deinit()); | |
| 911 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 912 | 912 | const allocator = &gpa.allocator; |
| 913 | 913 | |
| 914 | 914 | const ptr = try allocator.create(i32); |
| ... | ... | @@ -917,7 +917,7 @@ test "non-page-allocator backing allocator" { |
| 917 | 917 | |
| 918 | 918 | test "realloc large object to larger alignment" { |
| 919 | 919 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 920 | defer std.testing.expect(!gpa.deinit()); | |
| 920 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 921 | 921 | const allocator = &gpa.allocator; |
| 922 | 922 | |
| 923 | 923 | var debug_buffer: [1000]u8 = undefined; |
| ... | ... | @@ -943,22 +943,22 @@ test "realloc large object to larger alignment" { |
| 943 | 943 | slice[16] = 0x34; |
| 944 | 944 | |
| 945 | 945 | slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 100, .exact); |
| 946 | std.testing.expect(slice[0] == 0x12); | |
| 947 | std.testing.expect(slice[16] == 0x34); | |
| 946 | try std.testing.expect(slice[0] == 0x12); | |
| 947 | try std.testing.expect(slice[16] == 0x34); | |
| 948 | 948 | |
| 949 | 949 | slice = try allocator.reallocAdvanced(slice, 32, page_size * 2 + 25, .exact); |
| 950 | std.testing.expect(slice[0] == 0x12); | |
| 951 | std.testing.expect(slice[16] == 0x34); | |
| 950 | try std.testing.expect(slice[0] == 0x12); | |
| 951 | try std.testing.expect(slice[16] == 0x34); | |
| 952 | 952 | |
| 953 | 953 | slice = try allocator.reallocAdvanced(slice, big_alignment, page_size * 2 + 100, .exact); |
| 954 | std.testing.expect(slice[0] == 0x12); | |
| 955 | std.testing.expect(slice[16] == 0x34); | |
| 954 | try std.testing.expect(slice[0] == 0x12); | |
| 955 | try std.testing.expect(slice[16] == 0x34); | |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | test "large object shrinks to small but allocation fails during shrink" { |
| 959 | 959 | var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3); |
| 960 | 960 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator }; |
| 961 | defer std.testing.expect(!gpa.deinit()); | |
| 961 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 962 | 962 | const allocator = &gpa.allocator; |
| 963 | 963 | |
| 964 | 964 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| ... | ... | @@ -969,13 +969,13 @@ test "large object shrinks to small but allocation fails during shrink" { |
| 969 | 969 | // Next allocation will fail in the backing allocator of the GeneralPurposeAllocator |
| 970 | 970 | |
| 971 | 971 | slice = allocator.shrink(slice, 4); |
| 972 | std.testing.expect(slice[0] == 0x12); | |
| 973 | std.testing.expect(slice[3] == 0x34); | |
| 972 | try std.testing.expect(slice[0] == 0x12); | |
| 973 | try std.testing.expect(slice[3] == 0x34); | |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | test "objects of size 1024 and 2048" { |
| 977 | 977 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 978 | defer std.testing.expect(!gpa.deinit()); | |
| 978 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 979 | 979 | const allocator = &gpa.allocator; |
| 980 | 980 | |
| 981 | 981 | const slice = try allocator.alloc(u8, 1025); |
| ... | ... | @@ -987,26 +987,26 @@ test "objects of size 1024 and 2048" { |
| 987 | 987 | |
| 988 | 988 | test "setting a memory cap" { |
| 989 | 989 | var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){}; |
| 990 | defer std.testing.expect(!gpa.deinit()); | |
| 990 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | |
| 991 | 991 | const allocator = &gpa.allocator; |
| 992 | 992 | |
| 993 | 993 | gpa.setRequestedMemoryLimit(1010); |
| 994 | 994 | |
| 995 | 995 | const small = try allocator.create(i32); |
| 996 | std.testing.expect(gpa.total_requested_bytes == 4); | |
| 996 | try std.testing.expect(gpa.total_requested_bytes == 4); | |
| 997 | 997 | |
| 998 | 998 | const big = try allocator.alloc(u8, 1000); |
| 999 | std.testing.expect(gpa.total_requested_bytes == 1004); | |
| 999 | try std.testing.expect(gpa.total_requested_bytes == 1004); | |
| 1000 | 1000 | |
| 1001 | std.testing.expectError(error.OutOfMemory, allocator.create(u64)); | |
| 1001 | try std.testing.expectError(error.OutOfMemory, allocator.create(u64)); | |
| 1002 | 1002 | |
| 1003 | 1003 | allocator.destroy(small); |
| 1004 | std.testing.expect(gpa.total_requested_bytes == 1000); | |
| 1004 | try std.testing.expect(gpa.total_requested_bytes == 1000); | |
| 1005 | 1005 | |
| 1006 | 1006 | allocator.free(big); |
| 1007 | std.testing.expect(gpa.total_requested_bytes == 0); | |
| 1007 | try std.testing.expect(gpa.total_requested_bytes == 0); | |
| 1008 | 1008 | |
| 1009 | 1009 | const exact = try allocator.alloc(u8, 1010); |
| 1010 | std.testing.expect(gpa.total_requested_bytes == 1010); | |
| 1010 | try std.testing.expect(gpa.total_requested_bytes == 1010); | |
| 1011 | 1011 | allocator.free(exact); |
| 1012 | 1012 | } |
lib/std/heap/logging_allocator.zig+3-3| ... | ... | @@ -93,11 +93,11 @@ test "LoggingAllocator" { |
| 93 | 93 | |
| 94 | 94 | var a = try allocator.alloc(u8, 10); |
| 95 | 95 | a = allocator.shrink(a, 5); |
| 96 | std.testing.expect(a.len == 5); | |
| 97 | std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20)); | |
| 96 | try std.testing.expect(a.len == 5); | |
| 97 | try std.testing.expectError(error.OutOfMemory, allocator.resize(a, 20)); | |
| 98 | 98 | allocator.free(a); |
| 99 | 99 | |
| 100 | std.testing.expectEqualSlices(u8, | |
| 100 | try std.testing.expectEqualSlices(u8, | |
| 101 | 101 | \\alloc : 10 success! |
| 102 | 102 | \\shrink: 10 to 5 |
| 103 | 103 | \\expand: 5 to 20 failure! |
lib/std/io/bit_reader.zig+38-38| ... | ... | @@ -185,64 +185,64 @@ test "api coverage" { |
| 185 | 185 | const expect = testing.expect; |
| 186 | 186 | const expectError = testing.expectError; |
| 187 | 187 | |
| 188 | expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 189 | expect(out_bits == 1); | |
| 190 | expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 191 | expect(out_bits == 2); | |
| 192 | expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 193 | expect(out_bits == 3); | |
| 194 | expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 195 | expect(out_bits == 4); | |
| 196 | expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 197 | expect(out_bits == 5); | |
| 198 | expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 199 | expect(out_bits == 1); | |
| 188 | try expect(1 == try bit_stream_be.readBits(u2, 1, &out_bits)); | |
| 189 | try expect(out_bits == 1); | |
| 190 | try expect(2 == try bit_stream_be.readBits(u5, 2, &out_bits)); | |
| 191 | try expect(out_bits == 2); | |
| 192 | try expect(3 == try bit_stream_be.readBits(u128, 3, &out_bits)); | |
| 193 | try expect(out_bits == 3); | |
| 194 | try expect(4 == try bit_stream_be.readBits(u8, 4, &out_bits)); | |
| 195 | try expect(out_bits == 4); | |
| 196 | try expect(5 == try bit_stream_be.readBits(u9, 5, &out_bits)); | |
| 197 | try expect(out_bits == 5); | |
| 198 | try expect(1 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 199 | try expect(out_bits == 1); | |
| 200 | 200 | |
| 201 | 201 | mem_in_be.pos = 0; |
| 202 | 202 | bit_stream_be.bit_count = 0; |
| 203 | expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 204 | expect(out_bits == 15); | |
| 203 | try expect(0b110011010000101 == try bit_stream_be.readBits(u15, 15, &out_bits)); | |
| 204 | try expect(out_bits == 15); | |
| 205 | 205 | |
| 206 | 206 | mem_in_be.pos = 0; |
| 207 | 207 | bit_stream_be.bit_count = 0; |
| 208 | expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 209 | expect(out_bits == 16); | |
| 208 | try expect(0b1100110100001011 == try bit_stream_be.readBits(u16, 16, &out_bits)); | |
| 209 | try expect(out_bits == 16); | |
| 210 | 210 | |
| 211 | 211 | _ = try bit_stream_be.readBits(u0, 0, &out_bits); |
| 212 | 212 | |
| 213 | expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 214 | expect(out_bits == 0); | |
| 215 | expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | |
| 213 | try expect(0 == try bit_stream_be.readBits(u1, 1, &out_bits)); | |
| 214 | try expect(out_bits == 0); | |
| 215 | try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | |
| 216 | 216 | |
| 217 | 217 | var mem_in_le = io.fixedBufferStream(&mem_le); |
| 218 | 218 | var bit_stream_le = bitReader(.Little, mem_in_le.reader()); |
| 219 | 219 | |
| 220 | expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 221 | expect(out_bits == 1); | |
| 222 | expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 223 | expect(out_bits == 2); | |
| 224 | expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 225 | expect(out_bits == 3); | |
| 226 | expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 227 | expect(out_bits == 4); | |
| 228 | expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 229 | expect(out_bits == 5); | |
| 230 | expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 231 | expect(out_bits == 1); | |
| 220 | try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | |
| 221 | try expect(out_bits == 1); | |
| 222 | try expect(2 == try bit_stream_le.readBits(u5, 2, &out_bits)); | |
| 223 | try expect(out_bits == 2); | |
| 224 | try expect(3 == try bit_stream_le.readBits(u128, 3, &out_bits)); | |
| 225 | try expect(out_bits == 3); | |
| 226 | try expect(4 == try bit_stream_le.readBits(u8, 4, &out_bits)); | |
| 227 | try expect(out_bits == 4); | |
| 228 | try expect(5 == try bit_stream_le.readBits(u9, 5, &out_bits)); | |
| 229 | try expect(out_bits == 5); | |
| 230 | try expect(1 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 231 | try expect(out_bits == 1); | |
| 232 | 232 | |
| 233 | 233 | mem_in_le.pos = 0; |
| 234 | 234 | bit_stream_le.bit_count = 0; |
| 235 | expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 236 | expect(out_bits == 15); | |
| 235 | try expect(0b001010100011101 == try bit_stream_le.readBits(u15, 15, &out_bits)); | |
| 236 | try expect(out_bits == 15); | |
| 237 | 237 | |
| 238 | 238 | mem_in_le.pos = 0; |
| 239 | 239 | bit_stream_le.bit_count = 0; |
| 240 | expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 241 | expect(out_bits == 16); | |
| 240 | try expect(0b1001010100011101 == try bit_stream_le.readBits(u16, 16, &out_bits)); | |
| 241 | try expect(out_bits == 16); | |
| 242 | 242 | |
| 243 | 243 | _ = try bit_stream_le.readBits(u0, 0, &out_bits); |
| 244 | 244 | |
| 245 | expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 246 | expect(out_bits == 0); | |
| 247 | expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); | |
| 245 | try expect(0 == try bit_stream_le.readBits(u1, 1, &out_bits)); | |
| 246 | try expect(out_bits == 0); | |
| 247 | try expectError(error.EndOfStream, bit_stream_le.readBitsNoEof(u1, 1)); | |
| 248 | 248 | } |
lib/std/io/bit_writer.zig+6-6| ... | ... | @@ -163,17 +163,17 @@ test "api coverage" { |
| 163 | 163 | try bit_stream_be.writeBits(@as(u9, 5), 5); |
| 164 | 164 | try bit_stream_be.writeBits(@as(u1, 1), 1); |
| 165 | 165 | |
| 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); | |
| 167 | 167 | |
| 168 | 168 | mem_out_be.pos = 0; |
| 169 | 169 | |
| 170 | 170 | try bit_stream_be.writeBits(@as(u15, 0b110011010000101), 15); |
| 171 | 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); | |
| 173 | 173 | |
| 174 | 174 | mem_out_be.pos = 0; |
| 175 | 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); | |
| 177 | 177 | |
| 178 | 178 | try bit_stream_be.writeBits(@as(u0, 0), 0); |
| 179 | 179 | |
| ... | ... | @@ -187,16 +187,16 @@ test "api coverage" { |
| 187 | 187 | try bit_stream_le.writeBits(@as(u9, 5), 5); |
| 188 | 188 | try bit_stream_le.writeBits(@as(u1, 1), 1); |
| 189 | 189 | |
| 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); | |
| 191 | 191 | |
| 192 | 192 | mem_out_le.pos = 0; |
| 193 | 193 | try bit_stream_le.writeBits(@as(u15, 0b110011010000101), 15); |
| 194 | 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); | |
| 196 | 196 | |
| 197 | 197 | mem_out_le.pos = 0; |
| 198 | 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); | |
| 200 | 200 | |
| 201 | 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 | 87 | |
| 88 | 88 | const res = try stream.readAllAlloc(testing.allocator, str.len + 1); |
| 89 | 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 | 41 | |
| 42 | 42 | //read and discard all bytes |
| 43 | 43 | while (stream.readByte()) |_| {} else |err| { |
| 44 | testing.expect(err == error.EndOfStream); | |
| 44 | try testing.expect(err == error.EndOfStream); | |
| 45 | 45 | } |
| 46 | 46 | |
| 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 | 40 | |
| 41 | 41 | const bytes = "yay" ** 100; |
| 42 | 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 | 134 | const stream = fbs.writer(); |
| 135 | 135 | |
| 136 | 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 | } |
| 139 | 139 | |
| 140 | 140 | test "FixedBufferStream output 2" { |
| ... | ... | @@ -142,19 +142,19 @@ test "FixedBufferStream output 2" { |
| 142 | 142 | var fbs = fixedBufferStream(&buffer); |
| 143 | 143 | |
| 144 | 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")); | |
| 146 | 146 | |
| 147 | 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")); | |
| 149 | 149 | |
| 150 | testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!")); | |
| 151 | testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld")); | |
| 150 | try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("!")); | |
| 151 | try testing.expect(mem.eql(u8, fbs.getWritten(), "Helloworld")); | |
| 152 | 152 | |
| 153 | 153 | fbs.reset(); |
| 154 | testing.expect(fbs.getWritten().len == 0); | |
| 154 | try testing.expect(fbs.getWritten().len == 0); | |
| 155 | 155 | |
| 156 | testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!")); | |
| 157 | testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl")); | |
| 156 | try testing.expectError(error.NoSpaceLeft, fbs.writer().writeAll("Hello world!")); | |
| 157 | try testing.expect(mem.eql(u8, fbs.getWritten(), "Hello worl")); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | test "FixedBufferStream input" { |
| ... | ... | @@ -164,13 +164,13 @@ test "FixedBufferStream input" { |
| 164 | 164 | var dest: [4]u8 = undefined; |
| 165 | 165 | |
| 166 | 166 | var read = try fbs.reader().read(dest[0..4]); |
| 167 | testing.expect(read == 4); | |
| 168 | testing.expect(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 167 | try testing.expect(read == 4); | |
| 168 | try testing.expect(mem.eql(u8, dest[0..4], bytes[0..4])); | |
| 169 | 169 | |
| 170 | 170 | read = try fbs.reader().read(dest[0..4]); |
| 171 | testing.expect(read == 3); | |
| 172 | testing.expect(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 171 | try testing.expect(read == 3); | |
| 172 | try testing.expect(mem.eql(u8, dest[0..3], bytes[4..7])); | |
| 173 | 173 | |
| 174 | 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 | 43 | var early_stream = limitedReader(fbs.reader(), 3); |
| 44 | 44 | |
| 45 | 45 | var buf: [5]u8 = undefined; |
| 46 | testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf)); | |
| 47 | testing.expectEqualSlices(u8, data[0..3], buf[0..3]); | |
| 48 | testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf)); | |
| 49 | testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{})); | |
| 46 | try testing.expectEqual(@as(usize, 3), try early_stream.reader().read(&buf)); | |
| 47 | try testing.expectEqualSlices(u8, data[0..3], buf[0..3]); | |
| 48 | try testing.expectEqual(@as(usize, 0), try early_stream.reader().read(&buf)); | |
| 49 | try testing.expectError(error.EndOfStream, early_stream.reader().skipBytes(10, .{})); | |
| 50 | 50 | } |
lib/std/io/multi_writer.zig+2-2| ... | ... | @@ -52,6 +52,6 @@ test "MultiWriter" { |
| 52 | 52 | var fbs2 = io.fixedBufferStream(&buf2); |
| 53 | 53 | var stream = multiWriter(.{ fbs1.writer(), fbs2.writer() }); |
| 54 | 54 | try stream.writer().print("HI", .{}); |
| 55 | testing.expectEqualSlices(u8, "HI", fbs1.getWritten()); | |
| 56 | testing.expectEqualSlices(u8, "HI", fbs2.getWritten()); | |
| 55 | try testing.expectEqualSlices(u8, "HI", fbs1.getWritten()); | |
| 56 | try testing.expectEqualSlices(u8, "HI", fbs2.getWritten()); | |
| 57 | 57 | } |
lib/std/io/peek_stream.zig+11-11| ... | ... | @@ -94,24 +94,24 @@ test "PeekStream" { |
| 94 | 94 | try ps.putBackByte(10); |
| 95 | 95 | |
| 96 | 96 | var read = try ps.reader().read(dest[0..4]); |
| 97 | testing.expect(read == 4); | |
| 98 | testing.expect(dest[0] == 10); | |
| 99 | testing.expect(dest[1] == 9); | |
| 100 | testing.expect(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 97 | try testing.expect(read == 4); | |
| 98 | try testing.expect(dest[0] == 10); | |
| 99 | try testing.expect(dest[1] == 9); | |
| 100 | try testing.expect(mem.eql(u8, dest[2..4], bytes[0..2])); | |
| 101 | 101 | |
| 102 | 102 | read = try ps.reader().read(dest[0..4]); |
| 103 | testing.expect(read == 4); | |
| 104 | testing.expect(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 103 | try testing.expect(read == 4); | |
| 104 | try testing.expect(mem.eql(u8, dest[0..4], bytes[2..6])); | |
| 105 | 105 | |
| 106 | 106 | read = try ps.reader().read(dest[0..4]); |
| 107 | testing.expect(read == 2); | |
| 108 | testing.expect(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 107 | try testing.expect(read == 2); | |
| 108 | try testing.expect(mem.eql(u8, dest[0..2], bytes[6..8])); | |
| 109 | 109 | |
| 110 | 110 | try ps.putBackByte(11); |
| 111 | 111 | try ps.putBackByte(12); |
| 112 | 112 | |
| 113 | 113 | read = try ps.reader().read(dest[0..4]); |
| 114 | testing.expect(read == 2); | |
| 115 | testing.expect(dest[0] == 12); | |
| 116 | testing.expect(dest[1] == 11); | |
| 114 | try testing.expect(read == 2); | |
| 115 | try testing.expect(dest[0] == 12); | |
| 116 | try testing.expect(dest[1] == 11); | |
| 117 | 117 | } |
lib/std/io/reader.zig+7-7| ... | ... | @@ -329,26 +329,26 @@ pub fn Reader( |
| 329 | 329 | test "Reader" { |
| 330 | 330 | var buf = "a\x02".*; |
| 331 | 331 | const reader = std.io.fixedBufferStream(&buf).reader(); |
| 332 | testing.expect((try reader.readByte()) == 'a'); | |
| 333 | testing.expect((try reader.readEnum(enum(u8) { | |
| 332 | try testing.expect((try reader.readByte()) == 'a'); | |
| 333 | try testing.expect((try reader.readEnum(enum(u8) { | |
| 334 | 334 | a = 0, |
| 335 | 335 | b = 99, |
| 336 | 336 | c = 2, |
| 337 | 337 | d = 3, |
| 338 | 338 | }, undefined)) == .c); |
| 339 | testing.expectError(error.EndOfStream, reader.readByte()); | |
| 339 | try testing.expectError(error.EndOfStream, reader.readByte()); | |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | test "Reader.isBytes" { |
| 343 | 343 | const reader = std.io.fixedBufferStream("foobar").reader(); |
| 344 | testing.expectEqual(true, try reader.isBytes("foo")); | |
| 345 | testing.expectEqual(false, try reader.isBytes("qux")); | |
| 344 | try testing.expectEqual(true, try reader.isBytes("foo")); | |
| 345 | try testing.expectEqual(false, try reader.isBytes("qux")); | |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | test "Reader.skipBytes" { |
| 349 | 349 | const reader = std.io.fixedBufferStream("foobar").reader(); |
| 350 | 350 | try reader.skipBytes(3, .{}); |
| 351 | testing.expect(try reader.isBytes("bar")); | |
| 351 | try testing.expect(try reader.isBytes("bar")); | |
| 352 | 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 | 40 | |
| 41 | 41 | { |
| 42 | 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 | } |
| 45 | 45 | |
| 46 | 46 | { |
| ... | ... | @@ -49,16 +49,16 @@ test "write a file, read it, then delete it" { |
| 49 | 49 | |
| 50 | 50 | const file_size = try file.getEndPos(); |
| 51 | 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); | |
| 53 | 53 | |
| 54 | 54 | var buf_stream = io.bufferedReader(file.reader()); |
| 55 | 55 | const st = buf_stream.reader(); |
| 56 | 56 | const contents = try st.readAllAlloc(std.testing.allocator, 2 * 1024); |
| 57 | 57 | defer std.testing.allocator.free(contents); |
| 58 | 58 | |
| 59 | expect(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 60 | expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data)); | |
| 61 | expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 59 | try expect(mem.eql(u8, contents[0.."begin".len], "begin")); | |
| 60 | try expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data)); | |
| 61 | try expect(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | |
| 62 | 62 | } |
| 63 | 63 | try tmp.dir.deleteFile(tmp_file_name); |
| 64 | 64 | } |
| ... | ... | @@ -90,20 +90,20 @@ test "BitStreams with File Stream" { |
| 90 | 90 | |
| 91 | 91 | var out_bits: usize = undefined; |
| 92 | 92 | |
| 93 | expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 94 | expect(out_bits == 1); | |
| 95 | expect(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 96 | expect(out_bits == 2); | |
| 97 | expect(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 98 | expect(out_bits == 3); | |
| 99 | expect(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 100 | expect(out_bits == 4); | |
| 101 | expect(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 102 | expect(out_bits == 5); | |
| 103 | expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 104 | expect(out_bits == 1); | |
| 105 | ||
| 106 | expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); | |
| 93 | try expect(1 == try bit_stream.readBits(u2, 1, &out_bits)); | |
| 94 | try expect(out_bits == 1); | |
| 95 | try expect(2 == try bit_stream.readBits(u5, 2, &out_bits)); | |
| 96 | try expect(out_bits == 2); | |
| 97 | try expect(3 == try bit_stream.readBits(u128, 3, &out_bits)); | |
| 98 | try expect(out_bits == 3); | |
| 99 | try expect(4 == try bit_stream.readBits(u8, 4, &out_bits)); | |
| 100 | try expect(out_bits == 4); | |
| 101 | try expect(5 == try bit_stream.readBits(u9, 5, &out_bits)); | |
| 102 | try expect(out_bits == 5); | |
| 103 | try expect(1 == try bit_stream.readBits(u1, 1, &out_bits)); | |
| 104 | try expect(out_bits == 1); | |
| 105 | ||
| 106 | try expectError(error.EndOfStream, bit_stream.readBitsNoEof(u1, 1)); | |
| 107 | 107 | } |
| 108 | 108 | try tmp.dir.deleteFile(tmp_file_name); |
| 109 | 109 | } |
| ... | ... | @@ -123,16 +123,16 @@ test "File seek ops" { |
| 123 | 123 | |
| 124 | 124 | // Seek to the end |
| 125 | 125 | try file.seekFromEnd(0); |
| 126 | expect((try file.getPos()) == try file.getEndPos()); | |
| 126 | try expect((try file.getPos()) == try file.getEndPos()); | |
| 127 | 127 | // Negative delta |
| 128 | 128 | try file.seekBy(-4096); |
| 129 | expect((try file.getPos()) == 4096); | |
| 129 | try expect((try file.getPos()) == 4096); | |
| 130 | 130 | // Positive delta |
| 131 | 131 | try file.seekBy(10); |
| 132 | expect((try file.getPos()) == 4106); | |
| 132 | try expect((try file.getPos()) == 4106); | |
| 133 | 133 | // Absolute position |
| 134 | 134 | try file.seekTo(1234); |
| 135 | expect((try file.getPos()) == 1234); | |
| 135 | try expect((try file.getPos()) == 1234); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "setEndPos" { |
| ... | ... | @@ -147,18 +147,18 @@ test "setEndPos" { |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // Verify that the file size changes and the file offset is not moved |
| 150 | std.testing.expect((try file.getEndPos()) == 0); | |
| 151 | std.testing.expect((try file.getPos()) == 0); | |
| 150 | try std.testing.expect((try file.getEndPos()) == 0); | |
| 151 | try std.testing.expect((try file.getPos()) == 0); | |
| 152 | 152 | try file.setEndPos(8192); |
| 153 | std.testing.expect((try file.getEndPos()) == 8192); | |
| 154 | std.testing.expect((try file.getPos()) == 0); | |
| 153 | try std.testing.expect((try file.getEndPos()) == 8192); | |
| 154 | try std.testing.expect((try file.getPos()) == 0); | |
| 155 | 155 | try file.seekTo(100); |
| 156 | 156 | try file.setEndPos(4096); |
| 157 | std.testing.expect((try file.getEndPos()) == 4096); | |
| 158 | std.testing.expect((try file.getPos()) == 100); | |
| 157 | try std.testing.expect((try file.getEndPos()) == 4096); | |
| 158 | try std.testing.expect((try file.getPos()) == 100); | |
| 159 | 159 | try file.setEndPos(0); |
| 160 | std.testing.expect((try file.getEndPos()) == 0); | |
| 161 | std.testing.expect((try file.getPos()) == 100); | |
| 160 | try std.testing.expect((try file.getEndPos()) == 0); | |
| 161 | try std.testing.expect((try file.getPos()) == 100); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | test "updateTimes" { |
| ... | ... | @@ -178,6 +178,6 @@ test "updateTimes" { |
| 178 | 178 | stat_old.mtime - 5 * std.time.ns_per_s, |
| 179 | 179 | ); |
| 180 | 180 | var stat_new = try file.stat(); |
| 181 | expect(stat_new.atime < stat_old.atime); | |
| 182 | expect(stat_new.mtime < stat_old.mtime); | |
| 181 | try expect(stat_new.atime < stat_old.atime); | |
| 182 | try expect(stat_new.mtime < stat_old.mtime); | |
| 183 | 183 | } |
lib/std/json.zig+139-139| ... | ... | @@ -79,18 +79,18 @@ fn encodesTo(decoded: []const u8, encoded: []const u8) bool { |
| 79 | 79 | |
| 80 | 80 | test "encodesTo" { |
| 81 | 81 | // same |
| 82 | testing.expectEqual(true, encodesTo("false", "false")); | |
| 82 | try testing.expectEqual(true, encodesTo("false", "false")); | |
| 83 | 83 | // totally different |
| 84 | testing.expectEqual(false, encodesTo("false", "true")); | |
| 84 | try testing.expectEqual(false, encodesTo("false", "true")); | |
| 85 | 85 | // different lengths |
| 86 | testing.expectEqual(false, encodesTo("false", "other")); | |
| 86 | try testing.expectEqual(false, encodesTo("false", "other")); | |
| 87 | 87 | // with escape |
| 88 | testing.expectEqual(true, encodesTo("\\", "\\\\")); | |
| 89 | testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape")); | |
| 88 | try testing.expectEqual(true, encodesTo("\\", "\\\\")); | |
| 89 | try testing.expectEqual(true, encodesTo("with\nescape", "with\\nescape")); | |
| 90 | 90 | // with unicode |
| 91 | testing.expectEqual(true, encodesTo("ą", "\\u0105")); | |
| 92 | testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02")); | |
| 93 | testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02")); | |
| 91 | try testing.expectEqual(true, encodesTo("ą", "\\u0105")); | |
| 92 | try testing.expectEqual(true, encodesTo("😂", "\\ud83d\\ude02")); | |
| 93 | try testing.expectEqual(true, encodesTo("withąunicode😂", "with\\u0105unicode\\ud83d\\ude02")); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /// A single token slice into the parent string. |
| ... | ... | @@ -1138,9 +1138,9 @@ pub const TokenStream = struct { |
| 1138 | 1138 | } |
| 1139 | 1139 | }; |
| 1140 | 1140 | |
| 1141 | fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) void { | |
| 1141 | fn checkNext(p: *TokenStream, id: std.meta.Tag(Token)) !void { | |
| 1142 | 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 | } |
| 1145 | 1145 | |
| 1146 | 1146 | test "json.token" { |
| ... | ... | @@ -1163,46 +1163,46 @@ test "json.token" { |
| 1163 | 1163 | |
| 1164 | 1164 | var p = TokenStream.init(s); |
| 1165 | 1165 | |
| 1166 | checkNext(&p, .ObjectBegin); | |
| 1167 | checkNext(&p, .String); // Image | |
| 1168 | checkNext(&p, .ObjectBegin); | |
| 1169 | checkNext(&p, .String); // Width | |
| 1170 | checkNext(&p, .Number); | |
| 1171 | checkNext(&p, .String); // Height | |
| 1172 | checkNext(&p, .Number); | |
| 1173 | checkNext(&p, .String); // Title | |
| 1174 | checkNext(&p, .String); | |
| 1175 | checkNext(&p, .String); // Thumbnail | |
| 1176 | checkNext(&p, .ObjectBegin); | |
| 1177 | checkNext(&p, .String); // Url | |
| 1178 | checkNext(&p, .String); | |
| 1179 | checkNext(&p, .String); // Height | |
| 1180 | checkNext(&p, .Number); | |
| 1181 | checkNext(&p, .String); // Width | |
| 1182 | checkNext(&p, .Number); | |
| 1183 | checkNext(&p, .ObjectEnd); | |
| 1184 | checkNext(&p, .String); // Animated | |
| 1185 | checkNext(&p, .False); | |
| 1186 | checkNext(&p, .String); // IDs | |
| 1187 | checkNext(&p, .ArrayBegin); | |
| 1188 | checkNext(&p, .Number); | |
| 1189 | checkNext(&p, .Number); | |
| 1190 | checkNext(&p, .Number); | |
| 1191 | checkNext(&p, .Number); | |
| 1192 | checkNext(&p, .ArrayEnd); | |
| 1193 | checkNext(&p, .ObjectEnd); | |
| 1194 | checkNext(&p, .ObjectEnd); | |
| 1195 | ||
| 1196 | testing.expect((try p.next()) == null); | |
| 1166 | try checkNext(&p, .ObjectBegin); | |
| 1167 | try checkNext(&p, .String); // Image | |
| 1168 | try checkNext(&p, .ObjectBegin); | |
| 1169 | try checkNext(&p, .String); // Width | |
| 1170 | try checkNext(&p, .Number); | |
| 1171 | try checkNext(&p, .String); // Height | |
| 1172 | try checkNext(&p, .Number); | |
| 1173 | try checkNext(&p, .String); // Title | |
| 1174 | try checkNext(&p, .String); | |
| 1175 | try checkNext(&p, .String); // Thumbnail | |
| 1176 | try checkNext(&p, .ObjectBegin); | |
| 1177 | try checkNext(&p, .String); // Url | |
| 1178 | try checkNext(&p, .String); | |
| 1179 | try checkNext(&p, .String); // Height | |
| 1180 | try checkNext(&p, .Number); | |
| 1181 | try checkNext(&p, .String); // Width | |
| 1182 | try checkNext(&p, .Number); | |
| 1183 | try checkNext(&p, .ObjectEnd); | |
| 1184 | try checkNext(&p, .String); // Animated | |
| 1185 | try checkNext(&p, .False); | |
| 1186 | try checkNext(&p, .String); // IDs | |
| 1187 | try checkNext(&p, .ArrayBegin); | |
| 1188 | try checkNext(&p, .Number); | |
| 1189 | try checkNext(&p, .Number); | |
| 1190 | try checkNext(&p, .Number); | |
| 1191 | try checkNext(&p, .Number); | |
| 1192 | try checkNext(&p, .ArrayEnd); | |
| 1193 | try checkNext(&p, .ObjectEnd); | |
| 1194 | try checkNext(&p, .ObjectEnd); | |
| 1195 | ||
| 1196 | try testing.expect((try p.next()) == null); | |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | test "json.token mismatched close" { |
| 1200 | 1200 | var p = TokenStream.init("[102, 111, 111 }"); |
| 1201 | checkNext(&p, .ArrayBegin); | |
| 1202 | checkNext(&p, .Number); | |
| 1203 | checkNext(&p, .Number); | |
| 1204 | checkNext(&p, .Number); | |
| 1205 | testing.expectError(error.UnexpectedClosingBrace, p.next()); | |
| 1201 | try checkNext(&p, .ArrayBegin); | |
| 1202 | try checkNext(&p, .Number); | |
| 1203 | try checkNext(&p, .Number); | |
| 1204 | try checkNext(&p, .Number); | |
| 1205 | try testing.expectError(error.UnexpectedClosingBrace, p.next()); | |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | /// 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 | 1223 | } |
| 1224 | 1224 | |
| 1225 | 1225 | test "json.validate" { |
| 1226 | testing.expectEqual(true, validate("{}")); | |
| 1227 | testing.expectEqual(true, validate("[]")); | |
| 1228 | testing.expectEqual(true, validate("[{[[[[{}]]]]}]")); | |
| 1229 | testing.expectEqual(false, validate("{]")); | |
| 1230 | testing.expectEqual(false, validate("[}")); | |
| 1231 | testing.expectEqual(false, validate("{{{{[]}}}]")); | |
| 1226 | try testing.expectEqual(true, validate("{}")); | |
| 1227 | try testing.expectEqual(true, validate("[]")); | |
| 1228 | try testing.expectEqual(true, validate("[{[[[[{}]]]]}]")); | |
| 1229 | try testing.expectEqual(false, validate("{]")); | |
| 1230 | try testing.expectEqual(false, validate("[}")); | |
| 1231 | try testing.expectEqual(false, validate("{{{{[]}}}]")); | |
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | const Allocator = std.mem.Allocator; |
| ... | ... | @@ -1326,37 +1326,37 @@ test "Value.jsonStringify" { |
| 1326 | 1326 | var buffer: [10]u8 = undefined; |
| 1327 | 1327 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1328 | 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 | 1332 | var buffer: [10]u8 = undefined; |
| 1333 | 1333 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1334 | 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 | 1338 | var buffer: [10]u8 = undefined; |
| 1339 | 1339 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1340 | 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 | 1344 | var buffer: [10]u8 = undefined; |
| 1345 | 1345 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1346 | 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 | 1350 | var buffer: [10]u8 = undefined; |
| 1351 | 1351 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1352 | 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 | 1356 | var buffer: [10]u8 = undefined; |
| 1357 | 1357 | var fbs = std.io.fixedBufferStream(&buffer); |
| 1358 | 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 | 1362 | var buffer: [10]u8 = undefined; |
| ... | ... | @@ -1369,7 +1369,7 @@ test "Value.jsonStringify" { |
| 1369 | 1369 | try (Value{ |
| 1370 | 1370 | .Array = Array.fromOwnedSlice(undefined, &vals), |
| 1371 | 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 | 1375 | var buffer: [10]u8 = undefined; |
| ... | ... | @@ -1378,7 +1378,7 @@ test "Value.jsonStringify" { |
| 1378 | 1378 | defer obj.deinit(); |
| 1379 | 1379 | try obj.putNoClobber("a", .{ .String = "b" }); |
| 1380 | 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 | } |
| 1384 | 1384 | |
| ... | ... | @@ -1751,17 +1751,17 @@ pub fn parseFree(comptime T: type, value: T, options: ParseOptions) void { |
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | 1753 | test "parse" { |
| 1754 | testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{})); | |
| 1755 | testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{})); | |
| 1756 | testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{})); | |
| 1757 | testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{})); | |
| 1758 | testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{})); | |
| 1759 | testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{})); | |
| 1760 | testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{})); | |
| 1761 | testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{})); | |
| 1762 | ||
| 1763 | testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{})); | |
| 1764 | testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{})); | |
| 1754 | try testing.expectEqual(false, try parse(bool, &TokenStream.init("false"), ParseOptions{})); | |
| 1755 | try testing.expectEqual(true, try parse(bool, &TokenStream.init("true"), ParseOptions{})); | |
| 1756 | try testing.expectEqual(@as(u1, 1), try parse(u1, &TokenStream.init("1"), ParseOptions{})); | |
| 1757 | try testing.expectError(error.Overflow, parse(u1, &TokenStream.init("50"), ParseOptions{})); | |
| 1758 | try testing.expectEqual(@as(u64, 42), try parse(u64, &TokenStream.init("42"), ParseOptions{})); | |
| 1759 | try testing.expectEqual(@as(f64, 42), try parse(f64, &TokenStream.init("42.0"), ParseOptions{})); | |
| 1760 | try testing.expectEqual(@as(?bool, null), try parse(?bool, &TokenStream.init("null"), ParseOptions{})); | |
| 1761 | try testing.expectEqual(@as(?bool, true), try parse(?bool, &TokenStream.init("true"), ParseOptions{})); | |
| 1762 | ||
| 1763 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{})); | |
| 1764 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{})); | |
| 1765 | 1765 | } |
| 1766 | 1766 | |
| 1767 | 1767 | test "parse into enum" { |
| ... | ... | @@ -1770,31 +1770,31 @@ test "parse into enum" { |
| 1770 | 1770 | Bar, |
| 1771 | 1771 | @"with\\escape", |
| 1772 | 1772 | }; |
| 1773 | testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{})); | |
| 1774 | testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{})); | |
| 1775 | testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{})); | |
| 1776 | testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{})); | |
| 1777 | testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{})); | |
| 1773 | try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("\"Foo\""), ParseOptions{})); | |
| 1774 | try testing.expectEqual(@as(T, .Foo), try parse(T, &TokenStream.init("42"), ParseOptions{})); | |
| 1775 | try testing.expectEqual(@as(T, .@"with\\escape"), try parse(T, &TokenStream.init("\"with\\\\escape\""), ParseOptions{})); | |
| 1776 | try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("5"), ParseOptions{})); | |
| 1777 | try testing.expectError(error.InvalidEnumTag, parse(T, &TokenStream.init("\"Qux\""), ParseOptions{})); | |
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | 1780 | test "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{})); | |
| 1782 | 1782 | |
| 1783 | 1783 | const options = ParseOptions{ .allocator = testing.allocator }; |
| 1784 | 1784 | { |
| 1785 | 1785 | const r = try parse([]u8, &TokenStream.init("\"foo\""), options); |
| 1786 | 1786 | defer parseFree([]u8, r, options); |
| 1787 | testing.expectEqualSlices(u8, "foo", r); | |
| 1787 | try testing.expectEqualSlices(u8, "foo", r); | |
| 1788 | 1788 | } |
| 1789 | 1789 | { |
| 1790 | 1790 | const r = try parse([]u8, &TokenStream.init("[102, 111, 111]"), options); |
| 1791 | 1791 | defer parseFree([]u8, r, options); |
| 1792 | testing.expectEqualSlices(u8, "foo", r); | |
| 1792 | try testing.expectEqualSlices(u8, "foo", r); | |
| 1793 | 1793 | } |
| 1794 | 1794 | { |
| 1795 | 1795 | const r = try parse([]u8, &TokenStream.init("\"with\\\\escape\""), options); |
| 1796 | 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 | } |
| 1800 | 1800 | |
| ... | ... | @@ -1805,7 +1805,7 @@ test "parse into tagged union" { |
| 1805 | 1805 | float: f64, |
| 1806 | 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 | } |
| 1810 | 1810 | |
| 1811 | 1811 | { // failing allocations should be bubbled up instantly without trying next member |
| ... | ... | @@ -1816,7 +1816,7 @@ test "parse into tagged union" { |
| 1816 | 1816 | string: []const u8, |
| 1817 | 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 | } |
| 1821 | 1821 | |
| 1822 | 1822 | { |
| ... | ... | @@ -1825,7 +1825,7 @@ test "parse into tagged union" { |
| 1825 | 1825 | x: u8, |
| 1826 | 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 | } |
| 1830 | 1830 | |
| 1831 | 1831 | { // needs to back out when first union member doesn't match |
| ... | ... | @@ -1833,7 +1833,7 @@ test "parse into tagged union" { |
| 1833 | 1833 | A: struct { x: u32 }, |
| 1834 | 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 | } |
| 1839 | 1839 | |
| ... | ... | @@ -1843,7 +1843,7 @@ test "parse union bubbles up AllocatorRequired" { |
| 1843 | 1843 | string: []const u8, |
| 1844 | 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 | } |
| 1848 | 1848 | |
| 1849 | 1849 | { // string member not first in union (and matching) |
| ... | ... | @@ -1852,7 +1852,7 @@ test "parse union bubbles up AllocatorRequired" { |
| 1852 | 1852 | float: f64, |
| 1853 | 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 | } |
| 1858 | 1858 | |
| ... | ... | @@ -1866,11 +1866,11 @@ test "parseFree descends into tagged union" { |
| 1866 | 1866 | }; |
| 1867 | 1867 | // use a string with unicode escape so we know result can't be a reference to global constant |
| 1868 | 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)); | |
| 1870 | testing.expectEqualSlices(u8, "withąunicode", r.string); | |
| 1871 | testing.expectEqual(@as(usize, 0), fail_alloc.deallocations); | |
| 1869 | try testing.expectEqual(std.meta.Tag(T).string, @as(std.meta.Tag(T), r)); | |
| 1870 | try testing.expectEqualSlices(u8, "withąunicode", r.string); | |
| 1871 | try testing.expectEqual(@as(usize, 0), fail_alloc.deallocations); | |
| 1872 | 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 | } |
| 1875 | 1875 | |
| 1876 | 1876 | test "parse with comptime field" { |
| ... | ... | @@ -1879,7 +1879,7 @@ test "parse with comptime field" { |
| 1879 | 1879 | comptime a: i32 = 0, |
| 1880 | 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 | 1884 | \\ "a": 0, |
| 1885 | 1885 | \\ "b": true |
| ... | ... | @@ -1912,7 +1912,7 @@ test "parse with comptime field" { |
| 1912 | 1912 | |
| 1913 | 1913 | test "parse into struct with no fields" { |
| 1914 | 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 | } |
| 1917 | 1917 | |
| 1918 | 1918 | test "parse into struct with misc fields" { |
| ... | ... | @@ -1968,24 +1968,24 @@ test "parse into struct with misc fields" { |
| 1968 | 1968 | \\} |
| 1969 | 1969 | ), options); |
| 1970 | 1970 | defer parseFree(T, r, options); |
| 1971 | testing.expectEqual(@as(i64, 420), r.int); | |
| 1972 | testing.expectEqual(@as(f64, 3.14), r.float); | |
| 1973 | testing.expectEqual(true, r.@"with\\escape"); | |
| 1974 | testing.expectEqual(false, r.@"withąunicode😂"); | |
| 1975 | testing.expectEqualSlices(u8, "zig", r.language); | |
| 1976 | testing.expectEqual(@as(?bool, null), r.optional); | |
| 1977 | testing.expectEqual(@as(i32, 42), r.default_field); | |
| 1978 | testing.expectEqual(@as(f64, 66.6), r.static_array[0]); | |
| 1979 | testing.expectEqual(@as(f64, 420.420), r.static_array[1]); | |
| 1980 | testing.expectEqual(@as(f64, 69.69), r.static_array[2]); | |
| 1981 | testing.expectEqual(@as(usize, 3), r.dynamic_array.len); | |
| 1982 | testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]); | |
| 1983 | testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]); | |
| 1984 | testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]); | |
| 1985 | testing.expectEqualSlices(u8, r.complex.nested, "zig"); | |
| 1986 | testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo); | |
| 1987 | testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo); | |
| 1988 | testing.expectEqual(T.Union{ .float = 100000 }, r.a_union); | |
| 1971 | try testing.expectEqual(@as(i64, 420), r.int); | |
| 1972 | try testing.expectEqual(@as(f64, 3.14), r.float); | |
| 1973 | try testing.expectEqual(true, r.@"with\\escape"); | |
| 1974 | try testing.expectEqual(false, r.@"withąunicode😂"); | |
| 1975 | try testing.expectEqualSlices(u8, "zig", r.language); | |
| 1976 | try testing.expectEqual(@as(?bool, null), r.optional); | |
| 1977 | try testing.expectEqual(@as(i32, 42), r.default_field); | |
| 1978 | try testing.expectEqual(@as(f64, 66.6), r.static_array[0]); | |
| 1979 | try testing.expectEqual(@as(f64, 420.420), r.static_array[1]); | |
| 1980 | try testing.expectEqual(@as(f64, 69.69), r.static_array[2]); | |
| 1981 | try testing.expectEqual(@as(usize, 3), r.dynamic_array.len); | |
| 1982 | try testing.expectEqual(@as(f64, 66.6), r.dynamic_array[0]); | |
| 1983 | try testing.expectEqual(@as(f64, 420.420), r.dynamic_array[1]); | |
| 1984 | try testing.expectEqual(@as(f64, 69.69), r.dynamic_array[2]); | |
| 1985 | try testing.expectEqualSlices(u8, r.complex.nested, "zig"); | |
| 1986 | try testing.expectEqualSlices(u8, "zig", r.veryComplex[0].foo); | |
| 1987 | try testing.expectEqualSlices(u8, "rocks", r.veryComplex[1].foo); | |
| 1988 | try testing.expectEqual(T.Union{ .float = 100000 }, r.a_union); | |
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | 1991 | /// A non-stream JSON parser which constructs a tree of Value's. |
| ... | ... | @@ -2320,28 +2320,28 @@ test "json.parser.dynamic" { |
| 2320 | 2320 | var image = root.Object.get("Image").?; |
| 2321 | 2321 | |
| 2322 | 2322 | const width = image.Object.get("Width").?; |
| 2323 | testing.expect(width.Integer == 800); | |
| 2323 | try testing.expect(width.Integer == 800); | |
| 2324 | 2324 | |
| 2325 | 2325 | const height = image.Object.get("Height").?; |
| 2326 | testing.expect(height.Integer == 600); | |
| 2326 | try testing.expect(height.Integer == 600); | |
| 2327 | 2327 | |
| 2328 | 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")); | |
| 2330 | 2330 | |
| 2331 | 2331 | const animated = image.Object.get("Animated").?; |
| 2332 | testing.expect(animated.Bool == false); | |
| 2332 | try testing.expect(animated.Bool == false); | |
| 2333 | 2333 | |
| 2334 | 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); | |
| 2336 | 2336 | |
| 2337 | 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")); | |
| 2339 | 2339 | |
| 2340 | 2340 | const double = image.Object.get("double").?; |
| 2341 | testing.expect(double.Float == 1.3412); | |
| 2341 | try testing.expect(double.Float == 1.3412); | |
| 2342 | 2342 | |
| 2343 | 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 | } |
| 2346 | 2346 | |
| 2347 | 2347 | test "import more json tests" { |
| ... | ... | @@ -2388,12 +2388,12 @@ test "write json then parse it" { |
| 2388 | 2388 | var tree = try parser.parse(fixed_buffer_stream.getWritten()); |
| 2389 | 2389 | defer tree.deinit(); |
| 2390 | 2390 | |
| 2391 | testing.expect(tree.root.Object.get("f").?.Bool == false); | |
| 2392 | testing.expect(tree.root.Object.get("t").?.Bool == true); | |
| 2393 | testing.expect(tree.root.Object.get("int").?.Integer == 1234); | |
| 2394 | testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {}); | |
| 2395 | testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34); | |
| 2396 | testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello")); | |
| 2391 | try testing.expect(tree.root.Object.get("f").?.Bool == false); | |
| 2392 | try testing.expect(tree.root.Object.get("t").?.Bool == true); | |
| 2393 | try testing.expect(tree.root.Object.get("int").?.Integer == 1234); | |
| 2394 | try testing.expect(tree.root.Object.get("array").?.Array.items[0].Null == {}); | |
| 2395 | try testing.expect(tree.root.Object.get("array").?.Array.items[1].Float == 12.34); | |
| 2396 | try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello")); | |
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | 2399 | 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 |
| 2404 | 2404 | test "parsing empty string gives appropriate error" { |
| 2405 | 2405 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 2406 | 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 | } |
| 2409 | 2409 | |
| 2410 | 2410 | test "integer after float has proper type" { |
| ... | ... | @@ -2416,7 +2416,7 @@ test "integer after float has proper type" { |
| 2416 | 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 | } |
| 2421 | 2421 | |
| 2422 | 2422 | test "escaped characters" { |
| ... | ... | @@ -2439,16 +2439,16 @@ test "escaped characters" { |
| 2439 | 2439 | |
| 2440 | 2440 | const obj = (try test_parse(&arena_allocator.allocator, input)).Object; |
| 2441 | 2441 | |
| 2442 | testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\"); | |
| 2443 | testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/"); | |
| 2444 | testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n"); | |
| 2445 | testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r"); | |
| 2446 | testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t"); | |
| 2447 | testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C"); | |
| 2448 | testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08"); | |
| 2449 | testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\""); | |
| 2450 | testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą"); | |
| 2451 | testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂"); | |
| 2442 | try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\"); | |
| 2443 | try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/"); | |
| 2444 | try testing.expectEqualSlices(u8, obj.get("newline").?.String, "\n"); | |
| 2445 | try testing.expectEqualSlices(u8, obj.get("carriagereturn").?.String, "\r"); | |
| 2446 | try testing.expectEqualSlices(u8, obj.get("tab").?.String, "\t"); | |
| 2447 | try testing.expectEqualSlices(u8, obj.get("formfeed").?.String, "\x0C"); | |
| 2448 | try testing.expectEqualSlices(u8, obj.get("backspace").?.String, "\x08"); | |
| 2449 | try testing.expectEqualSlices(u8, obj.get("doublequote").?.String, "\""); | |
| 2450 | try testing.expectEqualSlices(u8, obj.get("unicode").?.String, "ą"); | |
| 2451 | try testing.expectEqualSlices(u8, obj.get("surrogatepair").?.String, "😂"); | |
| 2452 | 2452 | } |
| 2453 | 2453 | |
| 2454 | 2454 | test "string copy option" { |
| ... | ... | @@ -2471,7 +2471,7 @@ test "string copy option" { |
| 2471 | 2471 | const obj_copy = tree_copy.root.Object; |
| 2472 | 2472 | |
| 2473 | 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 | } |
| 2476 | 2476 | |
| 2477 | 2477 | const nocopy_addr = &obj_nocopy.get("noescape").?.String[0]; |
| ... | ... | @@ -2479,12 +2479,12 @@ test "string copy option" { |
| 2479 | 2479 | |
| 2480 | 2480 | var found_nocopy = false; |
| 2481 | 2481 | for (input) |_, index| { |
| 2482 | testing.expect(copy_addr != &input[index]); | |
| 2482 | try testing.expect(copy_addr != &input[index]); | |
| 2483 | 2483 | if (nocopy_addr == &input[index]) { |
| 2484 | 2484 | found_nocopy = true; |
| 2485 | 2485 | } |
| 2486 | 2486 | } |
| 2487 | testing.expect(found_nocopy); | |
| 2487 | try testing.expect(found_nocopy); | |
| 2488 | 2488 | } |
| 2489 | 2489 | |
| 2490 | 2490 | pub const StringifyOptions = struct { |
lib/std/json/test.zig+275-275| ... | ... | @@ -21,37 +21,37 @@ fn testNonStreaming(s: []const u8) !void { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | fn ok(s: []const u8) !void { |
| 24 | testing.expect(json.validate(s)); | |
| 24 | try testing.expect(json.validate(s)); | |
| 25 | 25 | |
| 26 | 26 | try testNonStreaming(s); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | fn err(s: []const u8) void { | |
| 30 | testing.expect(!json.validate(s)); | |
| 29 | fn err(s: []const u8) !void { | |
| 30 | try testing.expect(!json.validate(s)); | |
| 31 | 31 | |
| 32 | testing.expect(std.meta.isError(testNonStreaming(s))); | |
| 32 | try testing.expect(std.meta.isError(testNonStreaming(s))); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | fn utf8Error(s: []const u8) void { | |
| 36 | testing.expect(!json.validate(s)); | |
| 35 | fn utf8Error(s: []const u8) !void { | |
| 36 | try testing.expect(!json.validate(s)); | |
| 37 | 37 | |
| 38 | testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s)); | |
| 38 | try testing.expectError(error.InvalidUtf8Byte, testNonStreaming(s)); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | fn any(s: []const u8) void { | |
| 41 | fn any(s: []const u8) !void { | |
| 42 | 42 | _ = json.validate(s); |
| 43 | 43 | |
| 44 | 44 | testNonStreaming(s) catch {}; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | fn anyStreamingErrNonStreaming(s: []const u8) void { | |
| 47 | fn anyStreamingErrNonStreaming(s: []const u8) !void { | |
| 48 | 48 | _ = json.validate(s); |
| 49 | 49 | |
| 50 | testing.expect(std.meta.isError(testNonStreaming(s))); | |
| 50 | try testing.expect(std.meta.isError(testNonStreaming(s))); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | fn roundTrip(s: []const u8) !void { |
| 54 | testing.expect(json.validate(s)); | |
| 54 | try testing.expect(json.validate(s)); | |
| 55 | 55 | |
| 56 | 56 | var p = json.Parser.init(testing.allocator, false); |
| 57 | 57 | defer p.deinit(); |
| ... | ... | @@ -63,7 +63,7 @@ fn roundTrip(s: []const u8) !void { |
| 63 | 63 | var fbs = std.io.fixedBufferStream(&buf); |
| 64 | 64 | try tree.root.jsonStringify(.{}, fbs.writer()); |
| 65 | 65 | |
| 66 | testing.expectEqualStrings(s, fbs.getWritten()); | |
| 66 | try testing.expectEqualStrings(s, fbs.getWritten()); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | @@ -642,109 +642,109 @@ test "y_structure_whitespace_array" { |
| 642 | 642 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 643 | 643 | |
| 644 | 644 | test "n_array_1_true_without_comma" { |
| 645 | err( | |
| 645 | try err( | |
| 646 | 646 | \\[1 true] |
| 647 | 647 | ); |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | test "n_array_a_invalid_utf8" { |
| 651 | err( | |
| 651 | try err( | |
| 652 | 652 | \\[aå] |
| 653 | 653 | ); |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | test "n_array_colon_instead_of_comma" { |
| 657 | err( | |
| 657 | try err( | |
| 658 | 658 | \\["": 1] |
| 659 | 659 | ); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | test "n_array_comma_after_close" { |
| 663 | err( | |
| 663 | try err( | |
| 664 | 664 | \\[""], |
| 665 | 665 | ); |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | test "n_array_comma_and_number" { |
| 669 | err( | |
| 669 | try err( | |
| 670 | 670 | \\[,1] |
| 671 | 671 | ); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | test "n_array_double_comma" { |
| 675 | err( | |
| 675 | try err( | |
| 676 | 676 | \\[1,,2] |
| 677 | 677 | ); |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | test "n_array_double_extra_comma" { |
| 681 | err( | |
| 681 | try err( | |
| 682 | 682 | \\["x",,] |
| 683 | 683 | ); |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | test "n_array_extra_close" { |
| 687 | err( | |
| 687 | try err( | |
| 688 | 688 | \\["x"]] |
| 689 | 689 | ); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | test "n_array_extra_comma" { |
| 693 | err( | |
| 693 | try err( | |
| 694 | 694 | \\["",] |
| 695 | 695 | ); |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | test "n_array_incomplete_invalid_value" { |
| 699 | err( | |
| 699 | try err( | |
| 700 | 700 | \\[x |
| 701 | 701 | ); |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | test "n_array_incomplete" { |
| 705 | err( | |
| 705 | try err( | |
| 706 | 706 | \\["x" |
| 707 | 707 | ); |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | test "n_array_inner_array_no_comma" { |
| 711 | err( | |
| 711 | try err( | |
| 712 | 712 | \\[3[4]] |
| 713 | 713 | ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | test "n_array_invalid_utf8" { |
| 717 | err( | |
| 717 | try err( | |
| 718 | 718 | \\[ÿ] |
| 719 | 719 | ); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | test "n_array_items_separated_by_semicolon" { |
| 723 | err( | |
| 723 | try err( | |
| 724 | 724 | \\[1:2] |
| 725 | 725 | ); |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | test "n_array_just_comma" { |
| 729 | err( | |
| 729 | try err( | |
| 730 | 730 | \\[,] |
| 731 | 731 | ); |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | test "n_array_just_minus" { |
| 735 | err( | |
| 735 | try err( | |
| 736 | 736 | \\[-] |
| 737 | 737 | ); |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | test "n_array_missing_value" { |
| 741 | err( | |
| 741 | try err( | |
| 742 | 742 | \\[ , ""] |
| 743 | 743 | ); |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | test "n_array_newlines_unclosed" { |
| 747 | err( | |
| 747 | try err( | |
| 748 | 748 | \\["a", |
| 749 | 749 | \\4 |
| 750 | 750 | \\,1, |
| ... | ... | @@ -752,41 +752,41 @@ test "n_array_newlines_unclosed" { |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | test "n_array_number_and_comma" { |
| 755 | err( | |
| 755 | try err( | |
| 756 | 756 | \\[1,] |
| 757 | 757 | ); |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | test "n_array_number_and_several_commas" { |
| 761 | err( | |
| 761 | try err( | |
| 762 | 762 | \\[1,,] |
| 763 | 763 | ); |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | test "n_array_spaces_vertical_tab_formfeed" { |
| 767 | err("[\"\x0aa\"\\f]"); | |
| 767 | try err("[\"\x0aa\"\\f]"); | |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | test "n_array_star_inside" { |
| 771 | err( | |
| 771 | try err( | |
| 772 | 772 | \\[*] |
| 773 | 773 | ); |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | test "n_array_unclosed" { |
| 777 | err( | |
| 777 | try err( | |
| 778 | 778 | \\["" |
| 779 | 779 | ); |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | test "n_array_unclosed_trailing_comma" { |
| 783 | err( | |
| 783 | try err( | |
| 784 | 784 | \\[1, |
| 785 | 785 | ); |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | test "n_array_unclosed_with_new_lines" { |
| 789 | err( | |
| 789 | try err( | |
| 790 | 790 | \\[1, |
| 791 | 791 | \\1 |
| 792 | 792 | \\,1 |
| ... | ... | @@ -794,956 +794,956 @@ test "n_array_unclosed_with_new_lines" { |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | test "n_array_unclosed_with_object_inside" { |
| 797 | err( | |
| 797 | try err( | |
| 798 | 798 | \\[{} |
| 799 | 799 | ); |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | test "n_incomplete_false" { |
| 803 | err( | |
| 803 | try err( | |
| 804 | 804 | \\[fals] |
| 805 | 805 | ); |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | test "n_incomplete_null" { |
| 809 | err( | |
| 809 | try err( | |
| 810 | 810 | \\[nul] |
| 811 | 811 | ); |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | test "n_incomplete_true" { |
| 815 | err( | |
| 815 | try err( | |
| 816 | 816 | \\[tru] |
| 817 | 817 | ); |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | test "n_multidigit_number_then_00" { |
| 821 | err("123\x00"); | |
| 821 | try err("123\x00"); | |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | test "n_number_0.1.2" { |
| 825 | err( | |
| 825 | try err( | |
| 826 | 826 | \\[0.1.2] |
| 827 | 827 | ); |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | test "n_number_-01" { |
| 831 | err( | |
| 831 | try err( | |
| 832 | 832 | \\[-01] |
| 833 | 833 | ); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | test "n_number_0.3e" { |
| 837 | err( | |
| 837 | try err( | |
| 838 | 838 | \\[0.3e] |
| 839 | 839 | ); |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | test "n_number_0.3e+" { |
| 843 | err( | |
| 843 | try err( | |
| 844 | 844 | \\[0.3e+] |
| 845 | 845 | ); |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | test "n_number_0_capital_E" { |
| 849 | err( | |
| 849 | try err( | |
| 850 | 850 | \\[0E] |
| 851 | 851 | ); |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | test "n_number_0_capital_E+" { |
| 855 | err( | |
| 855 | try err( | |
| 856 | 856 | \\[0E+] |
| 857 | 857 | ); |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | test "n_number_0.e1" { |
| 861 | err( | |
| 861 | try err( | |
| 862 | 862 | \\[0.e1] |
| 863 | 863 | ); |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | test "n_number_0e" { |
| 867 | err( | |
| 867 | try err( | |
| 868 | 868 | \\[0e] |
| 869 | 869 | ); |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | test "n_number_0e+" { |
| 873 | err( | |
| 873 | try err( | |
| 874 | 874 | \\[0e+] |
| 875 | 875 | ); |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | test "n_number_1_000" { |
| 879 | err( | |
| 879 | try err( | |
| 880 | 880 | \\[1 000.0] |
| 881 | 881 | ); |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | test "n_number_1.0e-" { |
| 885 | err( | |
| 885 | try err( | |
| 886 | 886 | \\[1.0e-] |
| 887 | 887 | ); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | test "n_number_1.0e" { |
| 891 | err( | |
| 891 | try err( | |
| 892 | 892 | \\[1.0e] |
| 893 | 893 | ); |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | test "n_number_1.0e+" { |
| 897 | err( | |
| 897 | try err( | |
| 898 | 898 | \\[1.0e+] |
| 899 | 899 | ); |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | test "n_number_-1.0." { |
| 903 | err( | |
| 903 | try err( | |
| 904 | 904 | \\[-1.0.] |
| 905 | 905 | ); |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | test "n_number_1eE2" { |
| 909 | err( | |
| 909 | try err( | |
| 910 | 910 | \\[1eE2] |
| 911 | 911 | ); |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | test "n_number_.-1" { |
| 915 | err( | |
| 915 | try err( | |
| 916 | 916 | \\[.-1] |
| 917 | 917 | ); |
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | test "n_number_+1" { |
| 921 | err( | |
| 921 | try err( | |
| 922 | 922 | \\[+1] |
| 923 | 923 | ); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | test "n_number_.2e-3" { |
| 927 | err( | |
| 927 | try err( | |
| 928 | 928 | \\[.2e-3] |
| 929 | 929 | ); |
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | test "n_number_2.e-3" { |
| 933 | err( | |
| 933 | try err( | |
| 934 | 934 | \\[2.e-3] |
| 935 | 935 | ); |
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | test "n_number_2.e+3" { |
| 939 | err( | |
| 939 | try err( | |
| 940 | 940 | \\[2.e+3] |
| 941 | 941 | ); |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | test "n_number_2.e3" { |
| 945 | err( | |
| 945 | try err( | |
| 946 | 946 | \\[2.e3] |
| 947 | 947 | ); |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | test "n_number_-2." { |
| 951 | err( | |
| 951 | try err( | |
| 952 | 952 | \\[-2.] |
| 953 | 953 | ); |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | test "n_number_9.e+" { |
| 957 | err( | |
| 957 | try err( | |
| 958 | 958 | \\[9.e+] |
| 959 | 959 | ); |
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | test "n_number_expression" { |
| 963 | err( | |
| 963 | try err( | |
| 964 | 964 | \\[1+2] |
| 965 | 965 | ); |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | test "n_number_hex_1_digit" { |
| 969 | err( | |
| 969 | try err( | |
| 970 | 970 | \\[0x1] |
| 971 | 971 | ); |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | test "n_number_hex_2_digits" { |
| 975 | err( | |
| 975 | try err( | |
| 976 | 976 | \\[0x42] |
| 977 | 977 | ); |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | test "n_number_infinity" { |
| 981 | err( | |
| 981 | try err( | |
| 982 | 982 | \\[Infinity] |
| 983 | 983 | ); |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | 986 | test "n_number_+Inf" { |
| 987 | err( | |
| 987 | try err( | |
| 988 | 988 | \\[+Inf] |
| 989 | 989 | ); |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | test "n_number_Inf" { |
| 993 | err( | |
| 993 | try err( | |
| 994 | 994 | \\[Inf] |
| 995 | 995 | ); |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | test "n_number_invalid+-" { |
| 999 | err( | |
| 999 | try err( | |
| 1000 | 1000 | \\[0e+-1] |
| 1001 | 1001 | ); |
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | test "n_number_invalid-negative-real" { |
| 1005 | err( | |
| 1005 | try err( | |
| 1006 | 1006 | \\[-123.123foo] |
| 1007 | 1007 | ); |
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | test "n_number_invalid-utf-8-in-bigger-int" { |
| 1011 | err( | |
| 1011 | try err( | |
| 1012 | 1012 | \\[123å] |
| 1013 | 1013 | ); |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | test "n_number_invalid-utf-8-in-exponent" { |
| 1017 | err( | |
| 1017 | try err( | |
| 1018 | 1018 | \\[1e1å] |
| 1019 | 1019 | ); |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | test "n_number_invalid-utf-8-in-int" { |
| 1023 | err( | |
| 1023 | try err( | |
| 1024 | 1024 | \\[0å] |
| 1025 | 1025 | ); |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | test "n_number_++" { |
| 1029 | err( | |
| 1029 | try err( | |
| 1030 | 1030 | \\[++1234] |
| 1031 | 1031 | ); |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | test "n_number_minus_infinity" { |
| 1035 | err( | |
| 1035 | try err( | |
| 1036 | 1036 | \\[-Infinity] |
| 1037 | 1037 | ); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | test "n_number_minus_sign_with_trailing_garbage" { |
| 1041 | err( | |
| 1041 | try err( | |
| 1042 | 1042 | \\[-foo] |
| 1043 | 1043 | ); |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | test "n_number_minus_space_1" { |
| 1047 | err( | |
| 1047 | try err( | |
| 1048 | 1048 | \\[- 1] |
| 1049 | 1049 | ); |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | test "n_number_-NaN" { |
| 1053 | err( | |
| 1053 | try err( | |
| 1054 | 1054 | \\[-NaN] |
| 1055 | 1055 | ); |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | test "n_number_NaN" { |
| 1059 | err( | |
| 1059 | try err( | |
| 1060 | 1060 | \\[NaN] |
| 1061 | 1061 | ); |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | test "n_number_neg_int_starting_with_zero" { |
| 1065 | err( | |
| 1065 | try err( | |
| 1066 | 1066 | \\[-012] |
| 1067 | 1067 | ); |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | test "n_number_neg_real_without_int_part" { |
| 1071 | err( | |
| 1071 | try err( | |
| 1072 | 1072 | \\[-.123] |
| 1073 | 1073 | ); |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | test "n_number_neg_with_garbage_at_end" { |
| 1077 | err( | |
| 1077 | try err( | |
| 1078 | 1078 | \\[-1x] |
| 1079 | 1079 | ); |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | test "n_number_real_garbage_after_e" { |
| 1083 | err( | |
| 1083 | try err( | |
| 1084 | 1084 | \\[1ea] |
| 1085 | 1085 | ); |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | test "n_number_real_with_invalid_utf8_after_e" { |
| 1089 | err( | |
| 1089 | try err( | |
| 1090 | 1090 | \\[1eå] |
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | test "n_number_real_without_fractional_part" { |
| 1095 | err( | |
| 1095 | try err( | |
| 1096 | 1096 | \\[1.] |
| 1097 | 1097 | ); |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | test "n_number_starting_with_dot" { |
| 1101 | err( | |
| 1101 | try err( | |
| 1102 | 1102 | \\[.123] |
| 1103 | 1103 | ); |
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | test "n_number_U+FF11_fullwidth_digit_one" { |
| 1107 | err( | |
| 1107 | try err( | |
| 1108 | 1108 | \\[ï¼] |
| 1109 | 1109 | ); |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | test "n_number_with_alpha_char" { |
| 1113 | err( | |
| 1113 | try err( | |
| 1114 | 1114 | \\[1.8011670033376514H-308] |
| 1115 | 1115 | ); |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | test "n_number_with_alpha" { |
| 1119 | err( | |
| 1119 | try err( | |
| 1120 | 1120 | \\[1.2a-3] |
| 1121 | 1121 | ); |
| 1122 | 1122 | } |
| 1123 | 1123 | |
| 1124 | 1124 | test "n_number_with_leading_zero" { |
| 1125 | err( | |
| 1125 | try err( | |
| 1126 | 1126 | \\[012] |
| 1127 | 1127 | ); |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | test "n_object_bad_value" { |
| 1131 | err( | |
| 1131 | try err( | |
| 1132 | 1132 | \\["x", truth] |
| 1133 | 1133 | ); |
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | test "n_object_bracket_key" { |
| 1137 | err( | |
| 1137 | try err( | |
| 1138 | 1138 | \\{[: "x"} |
| 1139 | 1139 | ); |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | test "n_object_comma_instead_of_colon" { |
| 1143 | err( | |
| 1143 | try err( | |
| 1144 | 1144 | \\{"x", null} |
| 1145 | 1145 | ); |
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | test "n_object_double_colon" { |
| 1149 | err( | |
| 1149 | try err( | |
| 1150 | 1150 | \\{"x"::"b"} |
| 1151 | 1151 | ); |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | test "n_object_emoji" { |
| 1155 | err( | |
| 1155 | try err( | |
| 1156 | 1156 | \\{ð¨ð} |
| 1157 | 1157 | ); |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | test "n_object_garbage_at_end" { |
| 1161 | err( | |
| 1161 | try err( | |
| 1162 | 1162 | \\{"a":"a" 123} |
| 1163 | 1163 | ); |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | test "n_object_key_with_single_quotes" { |
| 1167 | err( | |
| 1167 | try err( | |
| 1168 | 1168 | \\{key: 'value'} |
| 1169 | 1169 | ); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | test "n_object_lone_continuation_byte_in_key_and_trailing_comma" { |
| 1173 | err( | |
| 1173 | try err( | |
| 1174 | 1174 | \\{"¹":"0",} |
| 1175 | 1175 | ); |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | test "n_object_missing_colon" { |
| 1179 | err( | |
| 1179 | try err( | |
| 1180 | 1180 | \\{"a" b} |
| 1181 | 1181 | ); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | test "n_object_missing_key" { |
| 1185 | err( | |
| 1185 | try err( | |
| 1186 | 1186 | \\{:"b"} |
| 1187 | 1187 | ); |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | test "n_object_missing_semicolon" { |
| 1191 | err( | |
| 1191 | try err( | |
| 1192 | 1192 | \\{"a" "b"} |
| 1193 | 1193 | ); |
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | 1196 | test "n_object_missing_value" { |
| 1197 | err( | |
| 1197 | try err( | |
| 1198 | 1198 | \\{"a": |
| 1199 | 1199 | ); |
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | test "n_object_no-colon" { |
| 1203 | err( | |
| 1203 | try err( | |
| 1204 | 1204 | \\{"a" |
| 1205 | 1205 | ); |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | test "n_object_non_string_key_but_huge_number_instead" { |
| 1209 | err( | |
| 1209 | try err( | |
| 1210 | 1210 | \\{9999E9999:1} |
| 1211 | 1211 | ); |
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | test "n_object_non_string_key" { |
| 1215 | err( | |
| 1215 | try err( | |
| 1216 | 1216 | \\{1:1} |
| 1217 | 1217 | ); |
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | test "n_object_repeated_null_null" { |
| 1221 | err( | |
| 1221 | try err( | |
| 1222 | 1222 | \\{null:null,null:null} |
| 1223 | 1223 | ); |
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | test "n_object_several_trailing_commas" { |
| 1227 | err( | |
| 1227 | try err( | |
| 1228 | 1228 | \\{"id":0,,,,,} |
| 1229 | 1229 | ); |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | test "n_object_single_quote" { |
| 1233 | err( | |
| 1233 | try err( | |
| 1234 | 1234 | \\{'a':0} |
| 1235 | 1235 | ); |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | test "n_object_trailing_comma" { |
| 1239 | err( | |
| 1239 | try err( | |
| 1240 | 1240 | \\{"id":0,} |
| 1241 | 1241 | ); |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | test "n_object_trailing_comment" { |
| 1245 | err( | |
| 1245 | try err( | |
| 1246 | 1246 | \\{"a":"b"}/**/ |
| 1247 | 1247 | ); |
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | test "n_object_trailing_comment_open" { |
| 1251 | err( | |
| 1251 | try err( | |
| 1252 | 1252 | \\{"a":"b"}/**// |
| 1253 | 1253 | ); |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | test "n_object_trailing_comment_slash_open_incomplete" { |
| 1257 | err( | |
| 1257 | try err( | |
| 1258 | 1258 | \\{"a":"b"}/ |
| 1259 | 1259 | ); |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | test "n_object_trailing_comment_slash_open" { |
| 1263 | err( | |
| 1263 | try err( | |
| 1264 | 1264 | \\{"a":"b"}// |
| 1265 | 1265 | ); |
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | test "n_object_two_commas_in_a_row" { |
| 1269 | err( | |
| 1269 | try err( | |
| 1270 | 1270 | \\{"a":"b",,"c":"d"} |
| 1271 | 1271 | ); |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | test "n_object_unquoted_key" { |
| 1275 | err( | |
| 1275 | try err( | |
| 1276 | 1276 | \\{a: "b"} |
| 1277 | 1277 | ); |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | test "n_object_unterminated-value" { |
| 1281 | err( | |
| 1281 | try err( | |
| 1282 | 1282 | \\{"a":"a |
| 1283 | 1283 | ); |
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | test "n_object_with_single_string" { |
| 1287 | err( | |
| 1287 | try err( | |
| 1288 | 1288 | \\{ "foo" : "bar", "a" } |
| 1289 | 1289 | ); |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | test "n_object_with_trailing_garbage" { |
| 1293 | err( | |
| 1293 | try err( | |
| 1294 | 1294 | \\{"a":"b"}# |
| 1295 | 1295 | ); |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | test "n_single_space" { |
| 1299 | err(" "); | |
| 1299 | try err(" "); | |
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | 1302 | test "n_string_1_surrogate_then_escape" { |
| 1303 | err( | |
| 1303 | try err( | |
| 1304 | 1304 | \\["\uD800\"] |
| 1305 | 1305 | ); |
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | test "n_string_1_surrogate_then_escape_u1" { |
| 1309 | err( | |
| 1309 | try err( | |
| 1310 | 1310 | \\["\uD800\u1"] |
| 1311 | 1311 | ); |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | test "n_string_1_surrogate_then_escape_u1x" { |
| 1315 | err( | |
| 1315 | try err( | |
| 1316 | 1316 | \\["\uD800\u1x"] |
| 1317 | 1317 | ); |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | 1320 | test "n_string_1_surrogate_then_escape_u" { |
| 1321 | err( | |
| 1321 | try err( | |
| 1322 | 1322 | \\["\uD800\u"] |
| 1323 | 1323 | ); |
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | test "n_string_accentuated_char_no_quotes" { |
| 1327 | err( | |
| 1327 | try err( | |
| 1328 | 1328 | \\[é] |
| 1329 | 1329 | ); |
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | test "n_string_backslash_00" { |
| 1333 | err("[\"\x00\"]"); | |
| 1333 | try err("[\"\x00\"]"); | |
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | 1336 | test "n_string_escaped_backslash_bad" { |
| 1337 | err( | |
| 1337 | try err( | |
| 1338 | 1338 | \\["\\\"] |
| 1339 | 1339 | ); |
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | test "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 | } |
| 1345 | 1345 | |
| 1346 | 1346 | test "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 | } |
| 1349 | 1349 | |
| 1350 | 1350 | test "n_string_escape_x" { |
| 1351 | err( | |
| 1351 | try err( | |
| 1352 | 1352 | \\["\x00"] |
| 1353 | 1353 | ); |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | 1356 | test "n_string_incomplete_escaped_character" { |
| 1357 | err( | |
| 1357 | try err( | |
| 1358 | 1358 | \\["\u00A"] |
| 1359 | 1359 | ); |
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | test "n_string_incomplete_escape" { |
| 1363 | err( | |
| 1363 | try err( | |
| 1364 | 1364 | \\["\"] |
| 1365 | 1365 | ); |
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | test "n_string_incomplete_surrogate_escape_invalid" { |
| 1369 | err( | |
| 1369 | try err( | |
| 1370 | 1370 | \\["\uD800\uD800\x"] |
| 1371 | 1371 | ); |
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | test "n_string_incomplete_surrogate" { |
| 1375 | err( | |
| 1375 | try err( | |
| 1376 | 1376 | \\["\uD834\uDd"] |
| 1377 | 1377 | ); |
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | test "n_string_invalid_backslash_esc" { |
| 1381 | err( | |
| 1381 | try err( | |
| 1382 | 1382 | \\["\a"] |
| 1383 | 1383 | ); |
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | test "n_string_invalid_unicode_escape" { |
| 1387 | err( | |
| 1387 | try err( | |
| 1388 | 1388 | \\["\uqqqq"] |
| 1389 | 1389 | ); |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | test "n_string_invalid_utf8_after_escape" { |
| 1393 | err("[\"\\\x75\xc3\xa5\"]"); | |
| 1393 | try err("[\"\\\x75\xc3\xa5\"]"); | |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | 1396 | test "n_string_invalid-utf-8-in-escape" { |
| 1397 | err( | |
| 1397 | try err( | |
| 1398 | 1398 | \\["\uå"] |
| 1399 | 1399 | ); |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | 1402 | test "n_string_leading_uescaped_thinspace" { |
| 1403 | err( | |
| 1403 | try err( | |
| 1404 | 1404 | \\[\u0020"asd"] |
| 1405 | 1405 | ); |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | test "n_string_no_quotes_with_bad_escape" { |
| 1409 | err( | |
| 1409 | try err( | |
| 1410 | 1410 | \\[\n] |
| 1411 | 1411 | ); |
| 1412 | 1412 | } |
| 1413 | 1413 | |
| 1414 | 1414 | test "n_string_single_doublequote" { |
| 1415 | err( | |
| 1415 | try err( | |
| 1416 | 1416 | \\" |
| 1417 | 1417 | ); |
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | test "n_string_single_quote" { |
| 1421 | err( | |
| 1421 | try err( | |
| 1422 | 1422 | \\['single quote'] |
| 1423 | 1423 | ); |
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | test "n_string_single_string_no_double_quotes" { |
| 1427 | err( | |
| 1427 | try err( | |
| 1428 | 1428 | \\abc |
| 1429 | 1429 | ); |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | test "n_string_start_escape_unclosed" { |
| 1433 | err( | |
| 1433 | try err( | |
| 1434 | 1434 | \\["\ |
| 1435 | 1435 | ); |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | test "n_string_unescaped_crtl_char" { |
| 1439 | err("[\"a\x00a\"]"); | |
| 1439 | try err("[\"a\x00a\"]"); | |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | test "n_string_unescaped_newline" { |
| 1443 | err( | |
| 1443 | try err( | |
| 1444 | 1444 | \\["new |
| 1445 | 1445 | \\line"] |
| 1446 | 1446 | ); |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | test "n_string_unescaped_tab" { |
| 1450 | err("[\"\t\"]"); | |
| 1450 | try err("[\"\t\"]"); | |
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | test "n_string_unicode_CapitalU" { |
| 1454 | err( | |
| 1454 | try err( | |
| 1455 | 1455 | \\"\UA66D" |
| 1456 | 1456 | ); |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | test "n_string_with_trailing_garbage" { |
| 1460 | err( | |
| 1460 | try err( | |
| 1461 | 1461 | \\""x |
| 1462 | 1462 | ); |
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | test "n_structure_100000_opening_arrays" { |
| 1466 | err("[" ** 100000); | |
| 1466 | try err("[" ** 100000); | |
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | test "n_structure_angle_bracket_." { |
| 1470 | err( | |
| 1470 | try err( | |
| 1471 | 1471 | \\<.> |
| 1472 | 1472 | ); |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | test "n_structure_angle_bracket_null" { |
| 1476 | err( | |
| 1476 | try err( | |
| 1477 | 1477 | \\[<null>] |
| 1478 | 1478 | ); |
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | test "n_structure_array_trailing_garbage" { |
| 1482 | err( | |
| 1482 | try err( | |
| 1483 | 1483 | \\[1]x |
| 1484 | 1484 | ); |
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | test "n_structure_array_with_extra_array_close" { |
| 1488 | err( | |
| 1488 | try err( | |
| 1489 | 1489 | \\[1]] |
| 1490 | 1490 | ); |
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | test "n_structure_array_with_unclosed_string" { |
| 1494 | err( | |
| 1494 | try err( | |
| 1495 | 1495 | \\["asd] |
| 1496 | 1496 | ); |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | 1499 | test "n_structure_ascii-unicode-identifier" { |
| 1500 | err( | |
| 1500 | try err( | |
| 1501 | 1501 | \\aå |
| 1502 | 1502 | ); |
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | test "n_structure_capitalized_True" { |
| 1506 | err( | |
| 1506 | try err( | |
| 1507 | 1507 | \\[True] |
| 1508 | 1508 | ); |
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | test "n_structure_close_unopened_array" { |
| 1512 | err( | |
| 1512 | try err( | |
| 1513 | 1513 | \\1] |
| 1514 | 1514 | ); |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | test "n_structure_comma_instead_of_closing_brace" { |
| 1518 | err( | |
| 1518 | try err( | |
| 1519 | 1519 | \\{"x": true, |
| 1520 | 1520 | ); |
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | 1523 | test "n_structure_double_array" { |
| 1524 | err( | |
| 1524 | try err( | |
| 1525 | 1525 | \\[][] |
| 1526 | 1526 | ); |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | 1529 | test "n_structure_end_array" { |
| 1530 | err( | |
| 1530 | try err( | |
| 1531 | 1531 | \\] |
| 1532 | 1532 | ); |
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | test "n_structure_incomplete_UTF8_BOM" { |
| 1536 | err( | |
| 1536 | try err( | |
| 1537 | 1537 | \\ï»{} |
| 1538 | 1538 | ); |
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | test "n_structure_lone-invalid-utf-8" { |
| 1542 | err( | |
| 1542 | try err( | |
| 1543 | 1543 | \\å |
| 1544 | 1544 | ); |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | test "n_structure_lone-open-bracket" { |
| 1548 | err( | |
| 1548 | try err( | |
| 1549 | 1549 | \\[ |
| 1550 | 1550 | ); |
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | 1553 | test "n_structure_no_data" { |
| 1554 | err( | |
| 1554 | try err( | |
| 1555 | 1555 | \\ |
| 1556 | 1556 | ); |
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | test "n_structure_null-byte-outside-string" { |
| 1560 | err("[\x00]"); | |
| 1560 | try err("[\x00]"); | |
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | test "n_structure_number_with_trailing_garbage" { |
| 1564 | err( | |
| 1564 | try err( | |
| 1565 | 1565 | \\2@ |
| 1566 | 1566 | ); |
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | test "n_structure_object_followed_by_closing_object" { |
| 1570 | err( | |
| 1570 | try err( | |
| 1571 | 1571 | \\{}} |
| 1572 | 1572 | ); |
| 1573 | 1573 | } |
| 1574 | 1574 | |
| 1575 | 1575 | test "n_structure_object_unclosed_no_value" { |
| 1576 | err( | |
| 1576 | try err( | |
| 1577 | 1577 | \\{"": |
| 1578 | 1578 | ); |
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | test "n_structure_object_with_comment" { |
| 1582 | err( | |
| 1582 | try err( | |
| 1583 | 1583 | \\{"a":/*comment*/"b"} |
| 1584 | 1584 | ); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | test "n_structure_object_with_trailing_garbage" { |
| 1588 | err( | |
| 1588 | try err( | |
| 1589 | 1589 | \\{"a": true} "x" |
| 1590 | 1590 | ); |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | test "n_structure_open_array_apostrophe" { |
| 1594 | err( | |
| 1594 | try err( | |
| 1595 | 1595 | \\[' |
| 1596 | 1596 | ); |
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | test "n_structure_open_array_comma" { |
| 1600 | err( | |
| 1600 | try err( | |
| 1601 | 1601 | \\[, |
| 1602 | 1602 | ); |
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | test "n_structure_open_array_object" { |
| 1606 | err("[{\"\":" ** 50000); | |
| 1606 | try err("[{\"\":" ** 50000); | |
| 1607 | 1607 | } |
| 1608 | 1608 | |
| 1609 | 1609 | test "n_structure_open_array_open_object" { |
| 1610 | err( | |
| 1610 | try err( | |
| 1611 | 1611 | \\[{ |
| 1612 | 1612 | ); |
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | test "n_structure_open_array_open_string" { |
| 1616 | err( | |
| 1616 | try err( | |
| 1617 | 1617 | \\["a |
| 1618 | 1618 | ); |
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | test "n_structure_open_array_string" { |
| 1622 | err( | |
| 1622 | try err( | |
| 1623 | 1623 | \\["a" |
| 1624 | 1624 | ); |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | 1627 | test "n_structure_open_object_close_array" { |
| 1628 | err( | |
| 1628 | try err( | |
| 1629 | 1629 | \\{] |
| 1630 | 1630 | ); |
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | test "n_structure_open_object_comma" { |
| 1634 | err( | |
| 1634 | try err( | |
| 1635 | 1635 | \\{, |
| 1636 | 1636 | ); |
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | 1639 | test "n_structure_open_object" { |
| 1640 | err( | |
| 1640 | try err( | |
| 1641 | 1641 | \\{ |
| 1642 | 1642 | ); |
| 1643 | 1643 | } |
| 1644 | 1644 | |
| 1645 | 1645 | test "n_structure_open_object_open_array" { |
| 1646 | err( | |
| 1646 | try err( | |
| 1647 | 1647 | \\{[ |
| 1648 | 1648 | ); |
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | test "n_structure_open_object_open_string" { |
| 1652 | err( | |
| 1652 | try err( | |
| 1653 | 1653 | \\{"a |
| 1654 | 1654 | ); |
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | test "n_structure_open_object_string_with_apostrophes" { |
| 1658 | err( | |
| 1658 | try err( | |
| 1659 | 1659 | \\{'a' |
| 1660 | 1660 | ); |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | test "n_structure_open_open" { |
| 1664 | err( | |
| 1664 | try err( | |
| 1665 | 1665 | \\["\{["\{["\{["\{ |
| 1666 | 1666 | ); |
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | test "n_structure_single_eacute" { |
| 1670 | err( | |
| 1670 | try err( | |
| 1671 | 1671 | \\é |
| 1672 | 1672 | ); |
| 1673 | 1673 | } |
| 1674 | 1674 | |
| 1675 | 1675 | test "n_structure_single_star" { |
| 1676 | err( | |
| 1676 | try err( | |
| 1677 | 1677 | \\* |
| 1678 | 1678 | ); |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | 1681 | test "n_structure_trailing_#" { |
| 1682 | err( | |
| 1682 | try err( | |
| 1683 | 1683 | \\{"a":"b"}#{} |
| 1684 | 1684 | ); |
| 1685 | 1685 | } |
| 1686 | 1686 | |
| 1687 | 1687 | test "n_structure_U+2060_word_joined" { |
| 1688 | err( | |
| 1688 | try err( | |
| 1689 | 1689 | \\[â ] |
| 1690 | 1690 | ); |
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | test "n_structure_uescaped_LF_before_string" { |
| 1694 | err( | |
| 1694 | try err( | |
| 1695 | 1695 | \\[\u000A""] |
| 1696 | 1696 | ); |
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | 1699 | test "n_structure_unclosed_array" { |
| 1700 | err( | |
| 1700 | try err( | |
| 1701 | 1701 | \\[1 |
| 1702 | 1702 | ); |
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | test "n_structure_unclosed_array_partial_null" { |
| 1706 | err( | |
| 1706 | try err( | |
| 1707 | 1707 | \\[ false, nul |
| 1708 | 1708 | ); |
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | test "n_structure_unclosed_array_unfinished_false" { |
| 1712 | err( | |
| 1712 | try err( | |
| 1713 | 1713 | \\[ true, fals |
| 1714 | 1714 | ); |
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | test "n_structure_unclosed_array_unfinished_true" { |
| 1718 | err( | |
| 1718 | try err( | |
| 1719 | 1719 | \\[ false, tru |
| 1720 | 1720 | ); |
| 1721 | 1721 | } |
| 1722 | 1722 | |
| 1723 | 1723 | test "n_structure_unclosed_object" { |
| 1724 | err( | |
| 1724 | try err( | |
| 1725 | 1725 | \\{"asd":"asd" |
| 1726 | 1726 | ); |
| 1727 | 1727 | } |
| 1728 | 1728 | |
| 1729 | 1729 | test "n_structure_unicode-identifier" { |
| 1730 | err( | |
| 1730 | try err( | |
| 1731 | 1731 | \\Ã¥ |
| 1732 | 1732 | ); |
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | test "n_structure_UTF8_BOM_no_data" { |
| 1736 | err( | |
| 1736 | try err( | |
| 1737 | 1737 | \\ |
| 1738 | 1738 | ); |
| 1739 | 1739 | } |
| 1740 | 1740 | |
| 1741 | 1741 | test "n_structure_whitespace_formfeed" { |
| 1742 | err("[\x0c]"); | |
| 1742 | try err("[\x0c]"); | |
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | 1745 | test "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 | 1751 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1752 | 1752 | |
| 1753 | 1753 | test "i_number_double_huge_neg_exp" { |
| 1754 | any( | |
| 1754 | try any( | |
| 1755 | 1755 | \\[123.456e-789] |
| 1756 | 1756 | ); |
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | 1759 | test "i_number_huge_exp" { |
| 1760 | any( | |
| 1760 | try any( | |
| 1761 | 1761 | \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] |
| 1762 | 1762 | ); |
| 1763 | 1763 | } |
| 1764 | 1764 | |
| 1765 | 1765 | test "i_number_neg_int_huge_exp" { |
| 1766 | any( | |
| 1766 | try any( | |
| 1767 | 1767 | \\[-1e+9999] |
| 1768 | 1768 | ); |
| 1769 | 1769 | } |
| 1770 | 1770 | |
| 1771 | 1771 | test "i_number_pos_double_huge_exp" { |
| 1772 | any( | |
| 1772 | try any( | |
| 1773 | 1773 | \\[1.5e+9999] |
| 1774 | 1774 | ); |
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | 1777 | test "i_number_real_neg_overflow" { |
| 1778 | any( | |
| 1778 | try any( | |
| 1779 | 1779 | \\[-123123e100000] |
| 1780 | 1780 | ); |
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | test "i_number_real_pos_overflow" { |
| 1784 | any( | |
| 1784 | try any( | |
| 1785 | 1785 | \\[123123e100000] |
| 1786 | 1786 | ); |
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | 1789 | test "i_number_real_underflow" { |
| 1790 | any( | |
| 1790 | try any( | |
| 1791 | 1791 | \\[123e-10000000] |
| 1792 | 1792 | ); |
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | 1795 | test "i_number_too_big_neg_int" { |
| 1796 | any( | |
| 1796 | try any( | |
| 1797 | 1797 | \\[-123123123123123123123123123123] |
| 1798 | 1798 | ); |
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | 1801 | test "i_number_too_big_pos_int" { |
| 1802 | any( | |
| 1802 | try any( | |
| 1803 | 1803 | \\[100000000000000000000] |
| 1804 | 1804 | ); |
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | test "i_number_very_big_negative_int" { |
| 1808 | any( | |
| 1808 | try any( | |
| 1809 | 1809 | \\[-237462374673276894279832749832423479823246327846] |
| 1810 | 1810 | ); |
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | test "i_object_key_lone_2nd_surrogate" { |
| 1814 | anyStreamingErrNonStreaming( | |
| 1814 | try anyStreamingErrNonStreaming( | |
| 1815 | 1815 | \\{"\uDFAA":0} |
| 1816 | 1816 | ); |
| 1817 | 1817 | } |
| 1818 | 1818 | |
| 1819 | 1819 | test "i_string_1st_surrogate_but_2nd_missing" { |
| 1820 | anyStreamingErrNonStreaming( | |
| 1820 | try anyStreamingErrNonStreaming( | |
| 1821 | 1821 | \\["\uDADA"] |
| 1822 | 1822 | ); |
| 1823 | 1823 | } |
| 1824 | 1824 | |
| 1825 | 1825 | test "i_string_1st_valid_surrogate_2nd_invalid" { |
| 1826 | anyStreamingErrNonStreaming( | |
| 1826 | try anyStreamingErrNonStreaming( | |
| 1827 | 1827 | \\["\uD888\u1234"] |
| 1828 | 1828 | ); |
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | 1831 | test "i_string_incomplete_surrogate_and_escape_valid" { |
| 1832 | anyStreamingErrNonStreaming( | |
| 1832 | try anyStreamingErrNonStreaming( | |
| 1833 | 1833 | \\["\uD800\n"] |
| 1834 | 1834 | ); |
| 1835 | 1835 | } |
| 1836 | 1836 | |
| 1837 | 1837 | test "i_string_incomplete_surrogate_pair" { |
| 1838 | anyStreamingErrNonStreaming( | |
| 1838 | try anyStreamingErrNonStreaming( | |
| 1839 | 1839 | \\["\uDd1ea"] |
| 1840 | 1840 | ); |
| 1841 | 1841 | } |
| 1842 | 1842 | |
| 1843 | 1843 | test "i_string_incomplete_surrogates_escape_valid" { |
| 1844 | anyStreamingErrNonStreaming( | |
| 1844 | try anyStreamingErrNonStreaming( | |
| 1845 | 1845 | \\["\uD800\uD800\n"] |
| 1846 | 1846 | ); |
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | 1849 | test "i_string_invalid_lonely_surrogate" { |
| 1850 | anyStreamingErrNonStreaming( | |
| 1850 | try anyStreamingErrNonStreaming( | |
| 1851 | 1851 | \\["\ud800"] |
| 1852 | 1852 | ); |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | test "i_string_invalid_surrogate" { |
| 1856 | anyStreamingErrNonStreaming( | |
| 1856 | try anyStreamingErrNonStreaming( | |
| 1857 | 1857 | \\["\ud800abc"] |
| 1858 | 1858 | ); |
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | test "i_string_invalid_utf-8" { |
| 1862 | any( | |
| 1862 | try any( | |
| 1863 | 1863 | \\["ÿ"] |
| 1864 | 1864 | ); |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | 1867 | test "i_string_inverted_surrogates_U+1D11E" { |
| 1868 | anyStreamingErrNonStreaming( | |
| 1868 | try anyStreamingErrNonStreaming( | |
| 1869 | 1869 | \\["\uDd1e\uD834"] |
| 1870 | 1870 | ); |
| 1871 | 1871 | } |
| 1872 | 1872 | |
| 1873 | 1873 | test "i_string_iso_latin_1" { |
| 1874 | any( | |
| 1874 | try any( | |
| 1875 | 1875 | \\["é"] |
| 1876 | 1876 | ); |
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | test "i_string_lone_second_surrogate" { |
| 1880 | anyStreamingErrNonStreaming( | |
| 1880 | try anyStreamingErrNonStreaming( | |
| 1881 | 1881 | \\["\uDFAA"] |
| 1882 | 1882 | ); |
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | test "i_string_lone_utf8_continuation_byte" { |
| 1886 | any( | |
| 1886 | try any( | |
| 1887 | 1887 | \\[""] |
| 1888 | 1888 | ); |
| 1889 | 1889 | } |
| 1890 | 1890 | |
| 1891 | 1891 | test "i_string_not_in_unicode_range" { |
| 1892 | any( | |
| 1892 | try any( | |
| 1893 | 1893 | \\["ô¿¿¿"] |
| 1894 | 1894 | ); |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | test "i_string_overlong_sequence_2_bytes" { |
| 1898 | any( | |
| 1898 | try any( | |
| 1899 | 1899 | \\["À¯"] |
| 1900 | 1900 | ); |
| 1901 | 1901 | } |
| 1902 | 1902 | |
| 1903 | 1903 | test "i_string_overlong_sequence_6_bytes" { |
| 1904 | any( | |
| 1904 | try any( | |
| 1905 | 1905 | \\["ü¿¿¿¿"] |
| 1906 | 1906 | ); |
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | 1909 | test "i_string_overlong_sequence_6_bytes_null" { |
| 1910 | any( | |
| 1910 | try any( | |
| 1911 | 1911 | \\["ü"] |
| 1912 | 1912 | ); |
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | test "i_string_truncated-utf-8" { |
| 1916 | any( | |
| 1916 | try any( | |
| 1917 | 1917 | \\["àÿ"] |
| 1918 | 1918 | ); |
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | test "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 | } |
| 1924 | 1924 | |
| 1925 | 1925 | test "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 | } |
| 1928 | 1928 | |
| 1929 | 1929 | test "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 | } |
| 1932 | 1932 | |
| 1933 | 1933 | test "i_string_UTF-8_invalid_sequence" { |
| 1934 | any( | |
| 1934 | try any( | |
| 1935 | 1935 | \\["æ¥Ñú"] |
| 1936 | 1936 | ); |
| 1937 | 1937 | } |
| 1938 | 1938 | |
| 1939 | 1939 | test "i_string_UTF8_surrogate_U+D800" { |
| 1940 | any( | |
| 1940 | try any( | |
| 1941 | 1941 | \\["í "] |
| 1942 | 1942 | ); |
| 1943 | 1943 | } |
| 1944 | 1944 | |
| 1945 | 1945 | test "i_structure_500_nested_arrays" { |
| 1946 | any(("[" ** 500) ++ ("]" ** 500)); | |
| 1946 | try any(("[" ** 500) ++ ("]" ** 500)); | |
| 1947 | 1947 | } |
| 1948 | 1948 | |
| 1949 | 1949 | test "i_structure_UTF-8_BOM_empty_object" { |
| 1950 | any( | |
| 1950 | try any( | |
| 1951 | 1951 | \\{} |
| 1952 | 1952 | ); |
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | test "truncated UTF-8 sequence" { |
| 1956 | utf8Error("\"\xc2\""); | |
| 1957 | utf8Error("\"\xdf\""); | |
| 1958 | utf8Error("\"\xed\xa0\""); | |
| 1959 | utf8Error("\"\xf0\x80\""); | |
| 1960 | utf8Error("\"\xf0\x80\x80\""); | |
| 1956 | try utf8Error("\"\xc2\""); | |
| 1957 | try utf8Error("\"\xdf\""); | |
| 1958 | try utf8Error("\"\xed\xa0\""); | |
| 1959 | try utf8Error("\"\xf0\x80\""); | |
| 1960 | try utf8Error("\"\xf0\x80\x80\""); | |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | 1963 | test "invalid continuation byte" { |
| 1964 | utf8Error("\"\xc2\x00\""); | |
| 1965 | utf8Error("\"\xc2\x7f\""); | |
| 1966 | utf8Error("\"\xc2\xc0\""); | |
| 1967 | utf8Error("\"\xc3\xc1\""); | |
| 1968 | utf8Error("\"\xc4\xf5\""); | |
| 1969 | utf8Error("\"\xc5\xff\""); | |
| 1970 | utf8Error("\"\xe4\x80\x00\""); | |
| 1971 | utf8Error("\"\xe5\x80\x10\""); | |
| 1972 | utf8Error("\"\xe6\x80\xc0\""); | |
| 1973 | utf8Error("\"\xe7\x80\xf5\""); | |
| 1974 | utf8Error("\"\xe8\x00\x80\""); | |
| 1975 | utf8Error("\"\xf2\x00\x80\x80\""); | |
| 1976 | utf8Error("\"\xf0\x80\x00\x80\""); | |
| 1977 | utf8Error("\"\xf1\x80\xc0\x80\""); | |
| 1978 | utf8Error("\"\xf2\x80\x80\x00\""); | |
| 1979 | utf8Error("\"\xf3\x80\x80\xc0\""); | |
| 1980 | utf8Error("\"\xf4\x80\x80\xf5\""); | |
| 1964 | try utf8Error("\"\xc2\x00\""); | |
| 1965 | try utf8Error("\"\xc2\x7f\""); | |
| 1966 | try utf8Error("\"\xc2\xc0\""); | |
| 1967 | try utf8Error("\"\xc3\xc1\""); | |
| 1968 | try utf8Error("\"\xc4\xf5\""); | |
| 1969 | try utf8Error("\"\xc5\xff\""); | |
| 1970 | try utf8Error("\"\xe4\x80\x00\""); | |
| 1971 | try utf8Error("\"\xe5\x80\x10\""); | |
| 1972 | try utf8Error("\"\xe6\x80\xc0\""); | |
| 1973 | try utf8Error("\"\xe7\x80\xf5\""); | |
| 1974 | try utf8Error("\"\xe8\x00\x80\""); | |
| 1975 | try utf8Error("\"\xf2\x00\x80\x80\""); | |
| 1976 | try utf8Error("\"\xf0\x80\x00\x80\""); | |
| 1977 | try utf8Error("\"\xf1\x80\xc0\x80\""); | |
| 1978 | try utf8Error("\"\xf2\x80\x80\x00\""); | |
| 1979 | try utf8Error("\"\xf3\x80\x80\xc0\""); | |
| 1980 | try utf8Error("\"\xf4\x80\x80\xf5\""); | |
| 1981 | 1981 | } |
| 1982 | 1982 | |
| 1983 | 1983 | test "disallowed overlong form" { |
| 1984 | utf8Error("\"\xc0\x80\""); | |
| 1985 | utf8Error("\"\xc0\x90\""); | |
| 1986 | utf8Error("\"\xc1\x80\""); | |
| 1987 | utf8Error("\"\xc1\x90\""); | |
| 1988 | utf8Error("\"\xe0\x80\x80\""); | |
| 1989 | utf8Error("\"\xf0\x80\x80\x80\""); | |
| 1984 | try utf8Error("\"\xc0\x80\""); | |
| 1985 | try utf8Error("\"\xc0\x90\""); | |
| 1986 | try utf8Error("\"\xc1\x80\""); | |
| 1987 | try utf8Error("\"\xc1\x90\""); | |
| 1988 | try utf8Error("\"\xe0\x80\x80\""); | |
| 1989 | try utf8Error("\"\xf0\x80\x80\x80\""); | |
| 1990 | 1990 | } |
| 1991 | 1991 | |
| 1992 | 1992 | test "out of UTF-16 range" { |
| 1993 | utf8Error("\"\xf4\x90\x80\x80\""); | |
| 1994 | utf8Error("\"\xf5\x80\x80\x80\""); | |
| 1995 | utf8Error("\"\xf6\x80\x80\x80\""); | |
| 1996 | utf8Error("\"\xf7\x80\x80\x80\""); | |
| 1997 | utf8Error("\"\xf8\x80\x80\x80\""); | |
| 1998 | utf8Error("\"\xf9\x80\x80\x80\""); | |
| 1999 | utf8Error("\"\xfa\x80\x80\x80\""); | |
| 2000 | utf8Error("\"\xfb\x80\x80\x80\""); | |
| 2001 | utf8Error("\"\xfc\x80\x80\x80\""); | |
| 2002 | utf8Error("\"\xfd\x80\x80\x80\""); | |
| 2003 | utf8Error("\"\xfe\x80\x80\x80\""); | |
| 2004 | utf8Error("\"\xff\x80\x80\x80\""); | |
| 1993 | try utf8Error("\"\xf4\x90\x80\x80\""); | |
| 1994 | try utf8Error("\"\xf5\x80\x80\x80\""); | |
| 1995 | try utf8Error("\"\xf6\x80\x80\x80\""); | |
| 1996 | try utf8Error("\"\xf7\x80\x80\x80\""); | |
| 1997 | try utf8Error("\"\xf8\x80\x80\x80\""); | |
| 1998 | try utf8Error("\"\xf9\x80\x80\x80\""); | |
| 1999 | try utf8Error("\"\xfa\x80\x80\x80\""); | |
| 2000 | try utf8Error("\"\xfb\x80\x80\x80\""); | |
| 2001 | try utf8Error("\"\xfc\x80\x80\x80\""); | |
| 2002 | try utf8Error("\"\xfd\x80\x80\x80\""); | |
| 2003 | try utf8Error("\"\xfe\x80\x80\x80\""); | |
| 2004 | try utf8Error("\"\xff\x80\x80\x80\""); | |
| 2005 | 2005 | } |
lib/std/json/write_stream.zig+1-1| ... | ... | @@ -288,7 +288,7 @@ test "json write stream" { |
| 288 | 288 | \\ "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 | } |
| 293 | 293 | |
| 294 | 294 | fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value { |
lib/std/leb128.zig+68-68| ... | ... | @@ -152,22 +152,22 @@ test "writeUnsignedFixed" { |
| 152 | 152 | { |
| 153 | 153 | var buf: [4]u8 = undefined; |
| 154 | 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 | 158 | var buf: [4]u8 = undefined; |
| 159 | 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 | 163 | var buf: [4]u8 = undefined; |
| 164 | 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 | 168 | var buf: [4]u8 = undefined; |
| 169 | 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 | } |
| 173 | 173 | |
| ... | ... | @@ -212,44 +212,44 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u |
| 212 | 212 | |
| 213 | 213 | test "deserialize signed LEB128" { |
| 214 | 214 | // Truncated |
| 215 | testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80")); | |
| 215 | try testing.expectError(error.EndOfStream, test_read_stream_ileb128(i64, "\x80")); | |
| 216 | 216 | |
| 217 | 217 | // Overflow |
| 218 | testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40")); | |
| 219 | testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40")); | |
| 220 | testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40")); | |
| 221 | testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 222 | testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e")); | |
| 218 | try testing.expectError(error.Overflow, test_read_ileb128(i8, "\x80\x80\x40")); | |
| 219 | try testing.expectError(error.Overflow, test_read_ileb128(i16, "\x80\x80\x80\x40")); | |
| 220 | try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40")); | |
| 221 | try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 222 | try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e")); | |
| 223 | 223 | |
| 224 | 224 | // Decode SLEB128 |
| 225 | testing.expect((try test_read_ileb128(i64, "\x00")) == 0); | |
| 226 | testing.expect((try test_read_ileb128(i64, "\x01")) == 1); | |
| 227 | testing.expect((try test_read_ileb128(i64, "\x3f")) == 63); | |
| 228 | testing.expect((try test_read_ileb128(i64, "\x40")) == -64); | |
| 229 | testing.expect((try test_read_ileb128(i64, "\x41")) == -63); | |
| 230 | testing.expect((try test_read_ileb128(i64, "\x7f")) == -1); | |
| 231 | testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128); | |
| 232 | testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129); | |
| 233 | testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129); | |
| 234 | testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128); | |
| 235 | testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127); | |
| 236 | testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64); | |
| 237 | testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345); | |
| 238 | testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1); | |
| 239 | testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1); | |
| 240 | testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1); | |
| 241 | testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000); | |
| 242 | testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000))); | |
| 243 | testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000); | |
| 244 | testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000); | |
| 225 | try testing.expect((try test_read_ileb128(i64, "\x00")) == 0); | |
| 226 | try testing.expect((try test_read_ileb128(i64, "\x01")) == 1); | |
| 227 | try testing.expect((try test_read_ileb128(i64, "\x3f")) == 63); | |
| 228 | try testing.expect((try test_read_ileb128(i64, "\x40")) == -64); | |
| 229 | try testing.expect((try test_read_ileb128(i64, "\x41")) == -63); | |
| 230 | try testing.expect((try test_read_ileb128(i64, "\x7f")) == -1); | |
| 231 | try testing.expect((try test_read_ileb128(i64, "\x80\x01")) == 128); | |
| 232 | try testing.expect((try test_read_ileb128(i64, "\x81\x01")) == 129); | |
| 233 | try testing.expect((try test_read_ileb128(i64, "\xff\x7e")) == -129); | |
| 234 | try testing.expect((try test_read_ileb128(i64, "\x80\x7f")) == -128); | |
| 235 | try testing.expect((try test_read_ileb128(i64, "\x81\x7f")) == -127); | |
| 236 | try testing.expect((try test_read_ileb128(i64, "\xc0\x00")) == 64); | |
| 237 | try testing.expect((try test_read_ileb128(i64, "\xc7\x9f\x7f")) == -12345); | |
| 238 | try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1); | |
| 239 | try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1); | |
| 240 | try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1); | |
| 241 | try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000); | |
| 242 | try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000))); | |
| 243 | try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000); | |
| 244 | try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000); | |
| 245 | 245 | |
| 246 | 246 | // Decode unnormalized SLEB128 with extra padding bytes. |
| 247 | testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0); | |
| 248 | testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0); | |
| 249 | testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f); | |
| 250 | testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f); | |
| 251 | testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80); | |
| 252 | testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80); | |
| 247 | try testing.expect((try test_read_ileb128(i64, "\x80\x00")) == 0); | |
| 248 | try testing.expect((try test_read_ileb128(i64, "\x80\x80\x00")) == 0); | |
| 249 | try testing.expect((try test_read_ileb128(i64, "\xff\x00")) == 0x7f); | |
| 250 | try testing.expect((try test_read_ileb128(i64, "\xff\x80\x00")) == 0x7f); | |
| 251 | try testing.expect((try test_read_ileb128(i64, "\x80\x81\x00")) == 0x80); | |
| 252 | try testing.expect((try test_read_ileb128(i64, "\x80\x81\x80\x00")) == 0x80); | |
| 253 | 253 | |
| 254 | 254 | // Decode sequence of SLEB128 values |
| 255 | 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 | 257 | |
| 258 | 258 | test "deserialize unsigned LEB128" { |
| 259 | 259 | // Truncated |
| 260 | testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80")); | |
| 260 | try testing.expectError(error.EndOfStream, test_read_stream_uleb128(u64, "\x80")); | |
| 261 | 261 | |
| 262 | 262 | // Overflow |
| 263 | testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02")); | |
| 264 | testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40")); | |
| 265 | testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84")); | |
| 266 | testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40")); | |
| 267 | testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90")); | |
| 268 | testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40")); | |
| 269 | testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 263 | try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x02")); | |
| 264 | try testing.expectError(error.Overflow, test_read_uleb128(u8, "\x80\x80\x40")); | |
| 265 | try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x84")); | |
| 266 | try testing.expectError(error.Overflow, test_read_uleb128(u16, "\x80\x80\x80\x40")); | |
| 267 | try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x90")); | |
| 268 | try testing.expectError(error.Overflow, test_read_uleb128(u32, "\x80\x80\x80\x80\x40")); | |
| 269 | try testing.expectError(error.Overflow, test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | |
| 270 | 270 | |
| 271 | 271 | // Decode ULEB128 |
| 272 | testing.expect((try test_read_uleb128(u64, "\x00")) == 0); | |
| 273 | testing.expect((try test_read_uleb128(u64, "\x01")) == 1); | |
| 274 | testing.expect((try test_read_uleb128(u64, "\x3f")) == 63); | |
| 275 | testing.expect((try test_read_uleb128(u64, "\x40")) == 64); | |
| 276 | testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f); | |
| 277 | testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80); | |
| 278 | testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81); | |
| 279 | testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90); | |
| 280 | testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff); | |
| 281 | testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100); | |
| 282 | testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101); | |
| 283 | testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616); | |
| 284 | testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000); | |
| 272 | try testing.expect((try test_read_uleb128(u64, "\x00")) == 0); | |
| 273 | try testing.expect((try test_read_uleb128(u64, "\x01")) == 1); | |
| 274 | try testing.expect((try test_read_uleb128(u64, "\x3f")) == 63); | |
| 275 | try testing.expect((try test_read_uleb128(u64, "\x40")) == 64); | |
| 276 | try testing.expect((try test_read_uleb128(u64, "\x7f")) == 0x7f); | |
| 277 | try testing.expect((try test_read_uleb128(u64, "\x80\x01")) == 0x80); | |
| 278 | try testing.expect((try test_read_uleb128(u64, "\x81\x01")) == 0x81); | |
| 279 | try testing.expect((try test_read_uleb128(u64, "\x90\x01")) == 0x90); | |
| 280 | try testing.expect((try test_read_uleb128(u64, "\xff\x01")) == 0xff); | |
| 281 | try testing.expect((try test_read_uleb128(u64, "\x80\x02")) == 0x100); | |
| 282 | try testing.expect((try test_read_uleb128(u64, "\x81\x02")) == 0x101); | |
| 283 | try testing.expect((try test_read_uleb128(u64, "\x80\xc1\x80\x80\x10")) == 4294975616); | |
| 284 | try testing.expect((try test_read_uleb128(u64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == 0x8000000000000000); | |
| 285 | 285 | |
| 286 | 286 | // Decode ULEB128 with extra padding bytes |
| 287 | testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0); | |
| 288 | testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0); | |
| 289 | testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f); | |
| 290 | testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f); | |
| 291 | testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80); | |
| 292 | testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80); | |
| 287 | try testing.expect((try test_read_uleb128(u64, "\x80\x00")) == 0); | |
| 288 | try testing.expect((try test_read_uleb128(u64, "\x80\x80\x00")) == 0); | |
| 289 | try testing.expect((try test_read_uleb128(u64, "\xff\x00")) == 0x7f); | |
| 290 | try testing.expect((try test_read_uleb128(u64, "\xff\x80\x00")) == 0x7f); | |
| 291 | try testing.expect((try test_read_uleb128(u64, "\x80\x81\x00")) == 0x80); | |
| 292 | try testing.expect((try test_read_uleb128(u64, "\x80\x81\x80\x00")) == 0x80); | |
| 293 | 293 | |
| 294 | 294 | // Decode sequence of ULEB128 values |
| 295 | 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 | 326 | // stream write |
| 327 | 327 | try writeStream(fbs.writer(), value); |
| 328 | 328 | const w1_pos = fbs.pos; |
| 329 | testing.expect(w1_pos == bytes_needed); | |
| 329 | try testing.expect(w1_pos == bytes_needed); | |
| 330 | 330 | |
| 331 | 331 | // stream read |
| 332 | 332 | fbs.pos = 0; |
| 333 | 333 | const sr = try readStream(T, fbs.reader()); |
| 334 | testing.expect(fbs.pos == w1_pos); | |
| 335 | testing.expect(sr == value); | |
| 334 | try testing.expect(fbs.pos == w1_pos); | |
| 335 | try testing.expect(sr == value); | |
| 336 | 336 | |
| 337 | 337 | // bigger type stream read |
| 338 | 338 | fbs.pos = 0; |
| 339 | 339 | const bsr = try readStream(B, fbs.reader()); |
| 340 | testing.expect(fbs.pos == w1_pos); | |
| 341 | testing.expect(bsr == value); | |
| 340 | try testing.expect(fbs.pos == w1_pos); | |
| 341 | try testing.expect(bsr == value); | |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | test "serialize unsigned LEB128" { |
lib/std/linked_list.zig+20-20| ... | ... | @@ -123,7 +123,7 @@ test "basic SinglyLinkedList test" { |
| 123 | 123 | const L = SinglyLinkedList(u32); |
| 124 | 124 | var list = L{}; |
| 125 | 125 | |
| 126 | testing.expect(list.len() == 0); | |
| 126 | try testing.expect(list.len() == 0); | |
| 127 | 127 | |
| 128 | 128 | var one = L.Node{ .data = 1 }; |
| 129 | 129 | var two = L.Node{ .data = 2 }; |
| ... | ... | @@ -137,14 +137,14 @@ test "basic SinglyLinkedList test" { |
| 137 | 137 | two.insertAfter(&three); // {1, 2, 3, 5} |
| 138 | 138 | three.insertAfter(&four); // {1, 2, 3, 4, 5} |
| 139 | 139 | |
| 140 | testing.expect(list.len() == 5); | |
| 140 | try testing.expect(list.len() == 5); | |
| 141 | 141 | |
| 142 | 142 | // Traverse forwards. |
| 143 | 143 | { |
| 144 | 144 | var it = list.first; |
| 145 | 145 | var index: u32 = 1; |
| 146 | 146 | while (it) |node| : (it = node.next) { |
| 147 | testing.expect(node.data == index); | |
| 147 | try testing.expect(node.data == index); | |
| 148 | 148 | index += 1; |
| 149 | 149 | } |
| 150 | 150 | } |
| ... | ... | @@ -153,9 +153,9 @@ test "basic SinglyLinkedList test" { |
| 153 | 153 | _ = list.remove(&five); // {2, 3, 4} |
| 154 | 154 | _ = two.removeNext(); // {2, 4} |
| 155 | 155 | |
| 156 | testing.expect(list.first.?.data == 2); | |
| 157 | testing.expect(list.first.?.next.?.data == 4); | |
| 158 | testing.expect(list.first.?.next.?.next == null); | |
| 156 | try testing.expect(list.first.?.data == 2); | |
| 157 | try testing.expect(list.first.?.next.?.data == 4); | |
| 158 | try testing.expect(list.first.?.next.?.next == null); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /// 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 | 344 | var it = list.first; |
| 345 | 345 | var index: u32 = 1; |
| 346 | 346 | while (it) |node| : (it = node.next) { |
| 347 | testing.expect(node.data == index); | |
| 347 | try testing.expect(node.data == index); | |
| 348 | 348 | index += 1; |
| 349 | 349 | } |
| 350 | 350 | } |
| ... | ... | @@ -354,7 +354,7 @@ test "basic TailQueue test" { |
| 354 | 354 | var it = list.last; |
| 355 | 355 | var index: u32 = 1; |
| 356 | 356 | while (it) |node| : (it = node.prev) { |
| 357 | testing.expect(node.data == (6 - index)); | |
| 357 | try testing.expect(node.data == (6 - index)); | |
| 358 | 358 | index += 1; |
| 359 | 359 | } |
| 360 | 360 | } |
| ... | ... | @@ -363,9 +363,9 @@ test "basic TailQueue test" { |
| 363 | 363 | var last = list.pop(); // {2, 3, 4} |
| 364 | 364 | list.remove(&three); // {2, 4} |
| 365 | 365 | |
| 366 | testing.expect(list.first.?.data == 2); | |
| 367 | testing.expect(list.last.?.data == 4); | |
| 368 | testing.expect(list.len == 2); | |
| 366 | try testing.expect(list.first.?.data == 2); | |
| 367 | try testing.expect(list.last.?.data == 4); | |
| 368 | try testing.expect(list.len == 2); | |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | test "TailQueue concatenation" { |
| ... | ... | @@ -387,18 +387,18 @@ test "TailQueue concatenation" { |
| 387 | 387 | |
| 388 | 388 | list1.concatByMoving(&list2); |
| 389 | 389 | |
| 390 | testing.expect(list1.last == &five); | |
| 391 | testing.expect(list1.len == 5); | |
| 392 | testing.expect(list2.first == null); | |
| 393 | testing.expect(list2.last == null); | |
| 394 | testing.expect(list2.len == 0); | |
| 390 | try testing.expect(list1.last == &five); | |
| 391 | try testing.expect(list1.len == 5); | |
| 392 | try testing.expect(list2.first == null); | |
| 393 | try testing.expect(list2.last == null); | |
| 394 | try testing.expect(list2.len == 0); | |
| 395 | 395 | |
| 396 | 396 | // Traverse forwards. |
| 397 | 397 | { |
| 398 | 398 | var it = list1.first; |
| 399 | 399 | var index: u32 = 1; |
| 400 | 400 | while (it) |node| : (it = node.next) { |
| 401 | testing.expect(node.data == index); | |
| 401 | try testing.expect(node.data == index); | |
| 402 | 402 | index += 1; |
| 403 | 403 | } |
| 404 | 404 | } |
| ... | ... | @@ -408,7 +408,7 @@ test "TailQueue concatenation" { |
| 408 | 408 | var it = list1.last; |
| 409 | 409 | var index: u32 = 1; |
| 410 | 410 | while (it) |node| : (it = node.prev) { |
| 411 | testing.expect(node.data == (6 - index)); | |
| 411 | try testing.expect(node.data == (6 - index)); | |
| 412 | 412 | index += 1; |
| 413 | 413 | } |
| 414 | 414 | } |
| ... | ... | @@ -421,7 +421,7 @@ test "TailQueue concatenation" { |
| 421 | 421 | var it = list2.first; |
| 422 | 422 | var index: u32 = 1; |
| 423 | 423 | while (it) |node| : (it = node.next) { |
| 424 | testing.expect(node.data == index); | |
| 424 | try testing.expect(node.data == index); | |
| 425 | 425 | index += 1; |
| 426 | 426 | } |
| 427 | 427 | } |
| ... | ... | @@ -431,7 +431,7 @@ test "TailQueue concatenation" { |
| 431 | 431 | var it = list2.last; |
| 432 | 432 | var index: u32 = 1; |
| 433 | 433 | while (it) |node| : (it = node.prev) { |
| 434 | testing.expect(node.data == (6 - index)); | |
| 434 | try testing.expect(node.data == (6 - index)); | |
| 435 | 435 | index += 1; |
| 436 | 436 | } |
| 437 | 437 | } |
lib/std/math.zig+353-353| ... | ... | @@ -177,20 +177,20 @@ test "approxEqAbs and approxEqRel" { |
| 177 | 177 | else => unreachable, |
| 178 | 178 | }; |
| 179 | 179 | |
| 180 | testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value)); | |
| 181 | testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value)); | |
| 182 | testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value)); | |
| 183 | testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value)); | |
| 184 | testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value)); | |
| 185 | testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value)); | |
| 186 | testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value)); | |
| 187 | testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value)); | |
| 188 | testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value)); | |
| 189 | testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value)); | |
| 190 | testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value)); | |
| 191 | testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value)); | |
| 192 | testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2)); | |
| 193 | testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2)); | |
| 180 | try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value)); | |
| 181 | try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value)); | |
| 182 | try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value)); | |
| 183 | try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value)); | |
| 184 | try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value)); | |
| 185 | try testing.expect(!approxEqAbs(T, 1.0 + 2 * epsilon(T), 1.0, eps_value)); | |
| 186 | try testing.expect(approxEqAbs(T, 1.0 + 1 * epsilon(T), 1.0, eps_value)); | |
| 187 | try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value)); | |
| 188 | try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value)); | |
| 189 | try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value)); | |
| 190 | try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value)); | |
| 191 | try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value)); | |
| 192 | try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2)); | |
| 193 | try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2)); | |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
| ... | ... | @@ -349,34 +349,34 @@ pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) { |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | test "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 | 354 | var a: u16 = 999; |
| 355 | 355 | var b: u32 = 10; |
| 356 | 356 | var result = min(a, b); |
| 357 | testing.expect(@TypeOf(result) == u16); | |
| 358 | testing.expect(result == 10); | |
| 357 | try testing.expect(@TypeOf(result) == u16); | |
| 358 | try testing.expect(result == 10); | |
| 359 | 359 | } |
| 360 | 360 | { |
| 361 | 361 | var a: f64 = 10.34; |
| 362 | 362 | var b: f32 = 999.12; |
| 363 | 363 | var result = min(a, b); |
| 364 | testing.expect(@TypeOf(result) == f64); | |
| 365 | testing.expect(result == 10.34); | |
| 364 | try testing.expect(@TypeOf(result) == f64); | |
| 365 | try testing.expect(result == 10.34); | |
| 366 | 366 | } |
| 367 | 367 | { |
| 368 | 368 | var a: i8 = -127; |
| 369 | 369 | var b: i16 = -200; |
| 370 | 370 | var result = min(a, b); |
| 371 | testing.expect(@TypeOf(result) == i16); | |
| 372 | testing.expect(result == -200); | |
| 371 | try testing.expect(@TypeOf(result) == i16); | |
| 372 | try testing.expect(result == -200); | |
| 373 | 373 | } |
| 374 | 374 | { |
| 375 | 375 | const a = 10.34; |
| 376 | 376 | var b: f32 = 999.12; |
| 377 | 377 | var result = min(a, b); |
| 378 | testing.expect(@TypeOf(result) == f32); | |
| 379 | testing.expect(result == 10.34); | |
| 378 | try testing.expect(@TypeOf(result) == f32); | |
| 379 | try testing.expect(result == 10.34); | |
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | |
| ... | ... | @@ -385,7 +385,7 @@ pub fn max(x: anytype, y: anytype) @TypeOf(x, y) { |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | test "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 | } |
| 390 | 390 | |
| 391 | 391 | pub 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 | 394 | } |
| 395 | 395 | test "math.clamp" { |
| 396 | 396 | // 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 | 398 | // 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 | 400 | // 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); | |
| 402 | 402 | |
| 403 | 403 | // Floating point |
| 404 | testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0); | |
| 405 | testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5); | |
| 404 | try testing.expect(std.math.clamp(@as(f32, 1.1), @as(f32, 0.0), @as(f32, 1.0)) == 1.0); | |
| 405 | try testing.expect(std.math.clamp(@as(f32, -127.5), @as(f32, -200), @as(f32, -100)) == -127.5); | |
| 406 | 406 | |
| 407 | 407 | // Mix of comptime and non-comptime |
| 408 | 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 | } |
| 411 | 411 | |
| 412 | 412 | pub 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 | 461 | } |
| 462 | 462 | |
| 463 | 463 | test "math.shl" { |
| 464 | testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000); | |
| 465 | testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0); | |
| 466 | testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0); | |
| 467 | testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111); | |
| 468 | testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); | |
| 469 | testing.expect(shl(u8, 0b11111111, 8) == 0); | |
| 470 | testing.expect(shl(u8, 0b11111111, 9) == 0); | |
| 471 | testing.expect(shl(u8, 0b11111111, -2) == 0b00111111); | |
| 472 | testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1); | |
| 473 | testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1); | |
| 474 | testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0); | |
| 464 | try testing.expect(shl(u8, 0b11111111, @as(usize, 3)) == 0b11111000); | |
| 465 | try testing.expect(shl(u8, 0b11111111, @as(usize, 8)) == 0); | |
| 466 | try testing.expect(shl(u8, 0b11111111, @as(usize, 9)) == 0); | |
| 467 | try testing.expect(shl(u8, 0b11111111, @as(isize, -2)) == 0b00111111); | |
| 468 | try testing.expect(shl(u8, 0b11111111, 3) == 0b11111000); | |
| 469 | try testing.expect(shl(u8, 0b11111111, 8) == 0); | |
| 470 | try testing.expect(shl(u8, 0b11111111, 9) == 0); | |
| 471 | try testing.expect(shl(u8, 0b11111111, -2) == 0b00111111); | |
| 472 | try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) << 1); | |
| 473 | try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) >> 1); | |
| 474 | try testing.expect(shl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0); | |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /// Shifts right. Overflowed bits are truncated. |
| ... | ... | @@ -501,17 +501,17 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T { |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | test "math.shr" { |
| 504 | testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111); | |
| 505 | testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0); | |
| 506 | testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0); | |
| 507 | testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100); | |
| 508 | testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); | |
| 509 | testing.expect(shr(u8, 0b11111111, 8) == 0); | |
| 510 | testing.expect(shr(u8, 0b11111111, 9) == 0); | |
| 511 | testing.expect(shr(u8, 0b11111111, -2) == 0b11111100); | |
| 512 | testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1); | |
| 513 | testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1); | |
| 514 | testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0); | |
| 504 | try testing.expect(shr(u8, 0b11111111, @as(usize, 3)) == 0b00011111); | |
| 505 | try testing.expect(shr(u8, 0b11111111, @as(usize, 8)) == 0); | |
| 506 | try testing.expect(shr(u8, 0b11111111, @as(usize, 9)) == 0); | |
| 507 | try testing.expect(shr(u8, 0b11111111, @as(isize, -2)) == 0b11111100); | |
| 508 | try testing.expect(shr(u8, 0b11111111, 3) == 0b00011111); | |
| 509 | try testing.expect(shr(u8, 0b11111111, 8) == 0); | |
| 510 | try testing.expect(shr(u8, 0b11111111, 9) == 0); | |
| 511 | try testing.expect(shr(u8, 0b11111111, -2) == 0b11111100); | |
| 512 | try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(usize, 1))[0] == @as(u32, 42) >> 1); | |
| 513 | try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, @as(isize, -1))[0] == @as(u32, 42) << 1); | |
| 514 | try testing.expect(shr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){42}, 33)[0] == 0); | |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 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 | 533 | } |
| 534 | 534 | |
| 535 | 535 | test "math.rotr" { |
| 536 | testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001); | |
| 537 | testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000); | |
| 538 | testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001); | |
| 539 | testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | |
| 540 | testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); | |
| 541 | testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31); | |
| 542 | testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1); | |
| 536 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 0)) == 0b00000001); | |
| 537 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 9)) == 0b10000000); | |
| 538 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 8)) == 0b00000001); | |
| 539 | try testing.expect(rotr(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | |
| 540 | try testing.expect(rotr(u8, 0b00000001, @as(isize, -1)) == 0b00000010); | |
| 541 | try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(usize, 1))[0] == @as(u32, 1) << 31); | |
| 542 | try testing.expect(rotr(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1}, @as(isize, -1))[0] == @as(u32, 1) << 1); | |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 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 | 561 | } |
| 562 | 562 | |
| 563 | 563 | test "math.rotl" { |
| 564 | testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001); | |
| 565 | testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010); | |
| 566 | testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001); | |
| 567 | testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | |
| 568 | testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); | |
| 569 | testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1); | |
| 570 | testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30); | |
| 564 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 0)) == 0b00000001); | |
| 565 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 9)) == 0b00000010); | |
| 566 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 8)) == 0b00000001); | |
| 567 | try testing.expect(rotl(u8, 0b00000001, @as(usize, 4)) == 0b00010000); | |
| 568 | try testing.expect(rotl(u8, 0b00000001, @as(isize, -1)) == 0b10000000); | |
| 569 | try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(usize, 1))[0] == 1); | |
| 570 | try testing.expect(rotl(std.meta.Vector(1, u32), std.meta.Vector(1, u32){1 << 31}, @as(isize, -1))[0] == @as(u32, 1) << 30); | |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | pub fn Log2Int(comptime T: type) type { |
| ... | ... | @@ -598,62 +598,62 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | test "math.IntFittingRange" { |
| 601 | testing.expect(IntFittingRange(0, 0) == u0); | |
| 602 | testing.expect(IntFittingRange(0, 1) == u1); | |
| 603 | testing.expect(IntFittingRange(0, 2) == u2); | |
| 604 | testing.expect(IntFittingRange(0, 3) == u2); | |
| 605 | testing.expect(IntFittingRange(0, 4) == u3); | |
| 606 | testing.expect(IntFittingRange(0, 7) == u3); | |
| 607 | testing.expect(IntFittingRange(0, 8) == u4); | |
| 608 | testing.expect(IntFittingRange(0, 9) == u4); | |
| 609 | testing.expect(IntFittingRange(0, 15) == u4); | |
| 610 | testing.expect(IntFittingRange(0, 16) == u5); | |
| 611 | testing.expect(IntFittingRange(0, 17) == u5); | |
| 612 | testing.expect(IntFittingRange(0, 4095) == u12); | |
| 613 | testing.expect(IntFittingRange(2000, 4095) == u12); | |
| 614 | testing.expect(IntFittingRange(0, 4096) == u13); | |
| 615 | testing.expect(IntFittingRange(2000, 4096) == u13); | |
| 616 | testing.expect(IntFittingRange(0, 4097) == u13); | |
| 617 | testing.expect(IntFittingRange(2000, 4097) == u13); | |
| 618 | testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87); | |
| 619 | testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177); | |
| 620 | ||
| 621 | testing.expect(IntFittingRange(-1, -1) == i1); | |
| 622 | testing.expect(IntFittingRange(-1, 0) == i1); | |
| 623 | testing.expect(IntFittingRange(-1, 1) == i2); | |
| 624 | testing.expect(IntFittingRange(-2, -2) == i2); | |
| 625 | testing.expect(IntFittingRange(-2, -1) == i2); | |
| 626 | testing.expect(IntFittingRange(-2, 0) == i2); | |
| 627 | testing.expect(IntFittingRange(-2, 1) == i2); | |
| 628 | testing.expect(IntFittingRange(-2, 2) == i3); | |
| 629 | testing.expect(IntFittingRange(-1, 2) == i3); | |
| 630 | testing.expect(IntFittingRange(-1, 3) == i3); | |
| 631 | testing.expect(IntFittingRange(-1, 4) == i4); | |
| 632 | testing.expect(IntFittingRange(-1, 7) == i4); | |
| 633 | testing.expect(IntFittingRange(-1, 8) == i5); | |
| 634 | testing.expect(IntFittingRange(-1, 9) == i5); | |
| 635 | testing.expect(IntFittingRange(-1, 15) == i5); | |
| 636 | testing.expect(IntFittingRange(-1, 16) == i6); | |
| 637 | testing.expect(IntFittingRange(-1, 17) == i6); | |
| 638 | testing.expect(IntFittingRange(-1, 4095) == i13); | |
| 639 | testing.expect(IntFittingRange(-4096, 4095) == i13); | |
| 640 | testing.expect(IntFittingRange(-1, 4096) == i14); | |
| 641 | testing.expect(IntFittingRange(-4097, 4095) == i14); | |
| 642 | testing.expect(IntFittingRange(-1, 4097) == i14); | |
| 643 | testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88); | |
| 644 | testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178); | |
| 601 | try testing.expect(IntFittingRange(0, 0) == u0); | |
| 602 | try testing.expect(IntFittingRange(0, 1) == u1); | |
| 603 | try testing.expect(IntFittingRange(0, 2) == u2); | |
| 604 | try testing.expect(IntFittingRange(0, 3) == u2); | |
| 605 | try testing.expect(IntFittingRange(0, 4) == u3); | |
| 606 | try testing.expect(IntFittingRange(0, 7) == u3); | |
| 607 | try testing.expect(IntFittingRange(0, 8) == u4); | |
| 608 | try testing.expect(IntFittingRange(0, 9) == u4); | |
| 609 | try testing.expect(IntFittingRange(0, 15) == u4); | |
| 610 | try testing.expect(IntFittingRange(0, 16) == u5); | |
| 611 | try testing.expect(IntFittingRange(0, 17) == u5); | |
| 612 | try testing.expect(IntFittingRange(0, 4095) == u12); | |
| 613 | try testing.expect(IntFittingRange(2000, 4095) == u12); | |
| 614 | try testing.expect(IntFittingRange(0, 4096) == u13); | |
| 615 | try testing.expect(IntFittingRange(2000, 4096) == u13); | |
| 616 | try testing.expect(IntFittingRange(0, 4097) == u13); | |
| 617 | try testing.expect(IntFittingRange(2000, 4097) == u13); | |
| 618 | try testing.expect(IntFittingRange(0, 123456789123456798123456789) == u87); | |
| 619 | try testing.expect(IntFittingRange(0, 123456789123456798123456789123456789123456798123456789) == u177); | |
| 620 | ||
| 621 | try testing.expect(IntFittingRange(-1, -1) == i1); | |
| 622 | try testing.expect(IntFittingRange(-1, 0) == i1); | |
| 623 | try testing.expect(IntFittingRange(-1, 1) == i2); | |
| 624 | try testing.expect(IntFittingRange(-2, -2) == i2); | |
| 625 | try testing.expect(IntFittingRange(-2, -1) == i2); | |
| 626 | try testing.expect(IntFittingRange(-2, 0) == i2); | |
| 627 | try testing.expect(IntFittingRange(-2, 1) == i2); | |
| 628 | try testing.expect(IntFittingRange(-2, 2) == i3); | |
| 629 | try testing.expect(IntFittingRange(-1, 2) == i3); | |
| 630 | try testing.expect(IntFittingRange(-1, 3) == i3); | |
| 631 | try testing.expect(IntFittingRange(-1, 4) == i4); | |
| 632 | try testing.expect(IntFittingRange(-1, 7) == i4); | |
| 633 | try testing.expect(IntFittingRange(-1, 8) == i5); | |
| 634 | try testing.expect(IntFittingRange(-1, 9) == i5); | |
| 635 | try testing.expect(IntFittingRange(-1, 15) == i5); | |
| 636 | try testing.expect(IntFittingRange(-1, 16) == i6); | |
| 637 | try testing.expect(IntFittingRange(-1, 17) == i6); | |
| 638 | try testing.expect(IntFittingRange(-1, 4095) == i13); | |
| 639 | try testing.expect(IntFittingRange(-4096, 4095) == i13); | |
| 640 | try testing.expect(IntFittingRange(-1, 4096) == i14); | |
| 641 | try testing.expect(IntFittingRange(-4097, 4095) == i14); | |
| 642 | try testing.expect(IntFittingRange(-1, 4097) == i14); | |
| 643 | try testing.expect(IntFittingRange(-1, 123456789123456798123456789) == i88); | |
| 644 | try testing.expect(IntFittingRange(-1, 123456789123456798123456789123456789123456798123456789) == i178); | |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | test "math overflow functions" { |
| 648 | testOverflow(); | |
| 649 | comptime testOverflow(); | |
| 648 | try testOverflow(); | |
| 649 | comptime try testOverflow(); | |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | fn testOverflow() void { | |
| 653 | testing.expect((mul(i32, 3, 4) catch unreachable) == 12); | |
| 654 | testing.expect((add(i32, 3, 4) catch unreachable) == 7); | |
| 655 | testing.expect((sub(i32, 3, 4) catch unreachable) == -1); | |
| 656 | testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | |
| 652 | fn testOverflow() !void { | |
| 653 | try testing.expect((mul(i32, 3, 4) catch unreachable) == 12); | |
| 654 | try testing.expect((add(i32, 3, 4) catch unreachable) == 7); | |
| 655 | try testing.expect((sub(i32, 3, 4) catch unreachable) == -1); | |
| 656 | try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); | |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | pub fn absInt(x: anytype) !@TypeOf(x) { |
| ... | ... | @@ -670,23 +670,23 @@ pub fn absInt(x: anytype) !@TypeOf(x) { |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | test "math.absInt" { |
| 673 | testAbsInt(); | |
| 674 | comptime testAbsInt(); | |
| 673 | try testAbsInt(); | |
| 674 | comptime try testAbsInt(); | |
| 675 | 675 | } |
| 676 | fn testAbsInt() void { | |
| 677 | testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10); | |
| 678 | testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10); | |
| 676 | fn testAbsInt() !void { | |
| 677 | try testing.expect((absInt(@as(i32, -10)) catch unreachable) == 10); | |
| 678 | try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10); | |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | pub const absFloat = fabs; |
| 682 | 682 | |
| 683 | 683 | test "math.absFloat" { |
| 684 | testAbsFloat(); | |
| 685 | comptime testAbsFloat(); | |
| 684 | try testAbsFloat(); | |
| 685 | comptime try testAbsFloat(); | |
| 686 | 686 | } |
| 687 | fn testAbsFloat() void { | |
| 688 | testing.expect(absFloat(@as(f32, -10.05)) == 10.05); | |
| 689 | testing.expect(absFloat(@as(f32, 10.05)) == 10.05); | |
| 687 | fn testAbsFloat() !void { | |
| 688 | try testing.expect(absFloat(@as(f32, -10.05)) == 10.05); | |
| 689 | try testing.expect(absFloat(@as(f32, 10.05)) == 10.05); | |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | 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 | } |
| 698 | 698 | |
| 699 | 699 | test "math.divTrunc" { |
| 700 | testDivTrunc(); | |
| 701 | comptime testDivTrunc(); | |
| 700 | try testDivTrunc(); | |
| 701 | comptime try testDivTrunc(); | |
| 702 | 702 | } |
| 703 | fn testDivTrunc() void { | |
| 704 | testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1); | |
| 705 | testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1); | |
| 706 | testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0)); | |
| 707 | testing.expectError(error.Overflow, divTrunc(i8, -128, -1)); | |
| 703 | fn testDivTrunc() !void { | |
| 704 | try testing.expect((divTrunc(i32, 5, 3) catch unreachable) == 1); | |
| 705 | try testing.expect((divTrunc(i32, -5, 3) catch unreachable) == -1); | |
| 706 | try testing.expectError(error.DivisionByZero, divTrunc(i8, -5, 0)); | |
| 707 | try testing.expectError(error.Overflow, divTrunc(i8, -128, -1)); | |
| 708 | 708 | |
| 709 | testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 710 | testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); | |
| 709 | try testing.expect((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 710 | try testing.expect((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0); | |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | 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 | } |
| 719 | 719 | |
| 720 | 720 | test "math.divFloor" { |
| 721 | testDivFloor(); | |
| 722 | comptime testDivFloor(); | |
| 721 | try testDivFloor(); | |
| 722 | comptime try testDivFloor(); | |
| 723 | 723 | } |
| 724 | fn testDivFloor() void { | |
| 725 | testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1); | |
| 726 | testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2); | |
| 727 | testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0)); | |
| 728 | testing.expectError(error.Overflow, divFloor(i8, -128, -1)); | |
| 724 | fn testDivFloor() !void { | |
| 725 | try testing.expect((divFloor(i32, 5, 3) catch unreachable) == 1); | |
| 726 | try testing.expect((divFloor(i32, -5, 3) catch unreachable) == -2); | |
| 727 | try testing.expectError(error.DivisionByZero, divFloor(i8, -5, 0)); | |
| 728 | try testing.expectError(error.Overflow, divFloor(i8, -128, -1)); | |
| 729 | 729 | |
| 730 | testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 731 | testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); | |
| 730 | try testing.expect((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0); | |
| 731 | try testing.expect((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0); | |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | 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 | } |
| 753 | 753 | |
| 754 | 754 | test "math.divCeil" { |
| 755 | testDivCeil(); | |
| 756 | comptime testDivCeil(); | |
| 757 | } | |
| 758 | fn testDivCeil() void { | |
| 759 | testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable); | |
| 760 | testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable); | |
| 761 | testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable); | |
| 762 | testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable); | |
| 763 | testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable); | |
| 764 | testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable); | |
| 765 | testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0)); | |
| 766 | testing.expectError(error.Overflow, divCeil(i8, -128, -1)); | |
| 767 | ||
| 768 | testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable); | |
| 769 | testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable); | |
| 770 | testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable); | |
| 771 | testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable); | |
| 772 | testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable); | |
| 773 | ||
| 774 | testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable); | |
| 775 | testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable); | |
| 776 | testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable); | |
| 777 | testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable); | |
| 778 | testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0)); | |
| 779 | ||
| 780 | testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable); | |
| 781 | testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable); | |
| 782 | testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable); | |
| 783 | testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable); | |
| 784 | testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0)); | |
| 755 | try testDivCeil(); | |
| 756 | comptime try testDivCeil(); | |
| 757 | } | |
| 758 | fn testDivCeil() !void { | |
| 759 | try testing.expectEqual(@as(i32, 2), divCeil(i32, 5, 3) catch unreachable); | |
| 760 | try testing.expectEqual(@as(i32, -1), divCeil(i32, -5, 3) catch unreachable); | |
| 761 | try testing.expectEqual(@as(i32, -1), divCeil(i32, 5, -3) catch unreachable); | |
| 762 | try testing.expectEqual(@as(i32, 2), divCeil(i32, -5, -3) catch unreachable); | |
| 763 | try testing.expectEqual(@as(i32, 0), divCeil(i32, 0, 5) catch unreachable); | |
| 764 | try testing.expectEqual(@as(u32, 0), divCeil(u32, 0, 5) catch unreachable); | |
| 765 | try testing.expectError(error.DivisionByZero, divCeil(i8, -5, 0)); | |
| 766 | try testing.expectError(error.Overflow, divCeil(i8, -128, -1)); | |
| 767 | ||
| 768 | try testing.expectEqual(@as(f32, 0.0), divCeil(f32, 0.0, 5.0) catch unreachable); | |
| 769 | try testing.expectEqual(@as(f32, 2.0), divCeil(f32, 5.0, 3.0) catch unreachable); | |
| 770 | try testing.expectEqual(@as(f32, -1.0), divCeil(f32, -5.0, 3.0) catch unreachable); | |
| 771 | try testing.expectEqual(@as(f32, -1.0), divCeil(f32, 5.0, -3.0) catch unreachable); | |
| 772 | try testing.expectEqual(@as(f32, 2.0), divCeil(f32, -5.0, -3.0) catch unreachable); | |
| 773 | ||
| 774 | try testing.expectEqual(6, divCeil(comptime_int, 23, 4) catch unreachable); | |
| 775 | try testing.expectEqual(-5, divCeil(comptime_int, -23, 4) catch unreachable); | |
| 776 | try testing.expectEqual(-5, divCeil(comptime_int, 23, -4) catch unreachable); | |
| 777 | try testing.expectEqual(6, divCeil(comptime_int, -23, -4) catch unreachable); | |
| 778 | try testing.expectError(error.DivisionByZero, divCeil(comptime_int, 23, 0)); | |
| 779 | ||
| 780 | try testing.expectEqual(6.0, divCeil(comptime_float, 23.0, 4.0) catch unreachable); | |
| 781 | try testing.expectEqual(-5.0, divCeil(comptime_float, -23.0, 4.0) catch unreachable); | |
| 782 | try testing.expectEqual(-5.0, divCeil(comptime_float, 23.0, -4.0) catch unreachable); | |
| 783 | try testing.expectEqual(6.0, divCeil(comptime_float, -23.0, -4.0) catch unreachable); | |
| 784 | try testing.expectError(error.DivisionByZero, divCeil(comptime_float, 23.0, 0.0)); | |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | 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 | } |
| 795 | 795 | |
| 796 | 796 | test "math.divExact" { |
| 797 | testDivExact(); | |
| 798 | comptime testDivExact(); | |
| 797 | try testDivExact(); | |
| 798 | comptime try testDivExact(); | |
| 799 | 799 | } |
| 800 | fn testDivExact() void { | |
| 801 | testing.expect((divExact(i32, 10, 5) catch unreachable) == 2); | |
| 802 | testing.expect((divExact(i32, -10, 5) catch unreachable) == -2); | |
| 803 | testing.expectError(error.DivisionByZero, divExact(i8, -5, 0)); | |
| 804 | testing.expectError(error.Overflow, divExact(i8, -128, -1)); | |
| 805 | testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2)); | |
| 800 | fn testDivExact() !void { | |
| 801 | try testing.expect((divExact(i32, 10, 5) catch unreachable) == 2); | |
| 802 | try testing.expect((divExact(i32, -10, 5) catch unreachable) == -2); | |
| 803 | try testing.expectError(error.DivisionByZero, divExact(i8, -5, 0)); | |
| 804 | try testing.expectError(error.Overflow, divExact(i8, -128, -1)); | |
| 805 | try testing.expectError(error.UnexpectedRemainder, divExact(i32, 5, 2)); | |
| 806 | 806 | |
| 807 | testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0); | |
| 808 | testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0); | |
| 809 | testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0)); | |
| 807 | try testing.expect((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0); | |
| 808 | try testing.expect((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0); | |
| 809 | try testing.expectError(error.UnexpectedRemainder, divExact(f32, 5.0, 2.0)); | |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | 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 | } |
| 818 | 818 | |
| 819 | 819 | test "math.mod" { |
| 820 | testMod(); | |
| 821 | comptime testMod(); | |
| 820 | try testMod(); | |
| 821 | comptime try testMod(); | |
| 822 | 822 | } |
| 823 | fn testMod() void { | |
| 824 | testing.expect((mod(i32, -5, 3) catch unreachable) == 1); | |
| 825 | testing.expect((mod(i32, 5, 3) catch unreachable) == 2); | |
| 826 | testing.expectError(error.NegativeDenominator, mod(i32, 10, -1)); | |
| 827 | testing.expectError(error.DivisionByZero, mod(i32, 10, 0)); | |
| 823 | fn testMod() !void { | |
| 824 | try testing.expect((mod(i32, -5, 3) catch unreachable) == 1); | |
| 825 | try testing.expect((mod(i32, 5, 3) catch unreachable) == 2); | |
| 826 | try testing.expectError(error.NegativeDenominator, mod(i32, 10, -1)); | |
| 827 | try testing.expectError(error.DivisionByZero, mod(i32, 10, 0)); | |
| 828 | 828 | |
| 829 | testing.expect((mod(f32, -5, 3) catch unreachable) == 1); | |
| 830 | testing.expect((mod(f32, 5, 3) catch unreachable) == 2); | |
| 831 | testing.expectError(error.NegativeDenominator, mod(f32, 10, -1)); | |
| 832 | testing.expectError(error.DivisionByZero, mod(f32, 10, 0)); | |
| 829 | try testing.expect((mod(f32, -5, 3) catch unreachable) == 1); | |
| 830 | try testing.expect((mod(f32, 5, 3) catch unreachable) == 2); | |
| 831 | try testing.expectError(error.NegativeDenominator, mod(f32, 10, -1)); | |
| 832 | try testing.expectError(error.DivisionByZero, mod(f32, 10, 0)); | |
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | 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 | } |
| 841 | 841 | |
| 842 | 842 | test "math.rem" { |
| 843 | testRem(); | |
| 844 | comptime testRem(); | |
| 843 | try testRem(); | |
| 844 | comptime try testRem(); | |
| 845 | 845 | } |
| 846 | fn testRem() void { | |
| 847 | testing.expect((rem(i32, -5, 3) catch unreachable) == -2); | |
| 848 | testing.expect((rem(i32, 5, 3) catch unreachable) == 2); | |
| 849 | testing.expectError(error.NegativeDenominator, rem(i32, 10, -1)); | |
| 850 | testing.expectError(error.DivisionByZero, rem(i32, 10, 0)); | |
| 846 | fn testRem() !void { | |
| 847 | try testing.expect((rem(i32, -5, 3) catch unreachable) == -2); | |
| 848 | try testing.expect((rem(i32, 5, 3) catch unreachable) == 2); | |
| 849 | try testing.expectError(error.NegativeDenominator, rem(i32, 10, -1)); | |
| 850 | try testing.expectError(error.DivisionByZero, rem(i32, 10, 0)); | |
| 851 | 851 | |
| 852 | testing.expect((rem(f32, -5, 3) catch unreachable) == -2); | |
| 853 | testing.expect((rem(f32, 5, 3) catch unreachable) == 2); | |
| 854 | testing.expectError(error.NegativeDenominator, rem(f32, 10, -1)); | |
| 855 | testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); | |
| 852 | try testing.expect((rem(f32, -5, 3) catch unreachable) == -2); | |
| 853 | try testing.expect((rem(f32, 5, 3) catch unreachable) == 2); | |
| 854 | try testing.expectError(error.NegativeDenominator, rem(f32, 10, -1)); | |
| 855 | try testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); | |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /// Returns the absolute value of the integer parameter. |
| ... | ... | @@ -883,11 +883,11 @@ pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { |
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | test "math.absCast" { |
| 886 | testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1))); | |
| 887 | testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999))); | |
| 888 | testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999))); | |
| 889 | testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32)))); | |
| 890 | testing.expectEqual(999, absCast(-999)); | |
| 886 | try testing.expectEqual(@as(u1, 1), absCast(@as(i1, -1))); | |
| 887 | try testing.expectEqual(@as(u32, 999), absCast(@as(i32, -999))); | |
| 888 | try testing.expectEqual(@as(u32, 999), absCast(@as(i32, 999))); | |
| 889 | try testing.expectEqual(@as(u32, -minInt(i32)), absCast(@as(i32, minInt(i32)))); | |
| 890 | try testing.expectEqual(999, absCast(-999)); | |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 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 | 904 | } |
| 905 | 905 | |
| 906 | 906 | test "math.negateCast" { |
| 907 | testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); | |
| 908 | testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); | |
| 907 | try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); | |
| 908 | try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); | |
| 909 | 909 | |
| 910 | testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); | |
| 911 | testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); | |
| 910 | try testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); | |
| 911 | try testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); | |
| 912 | 912 | |
| 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 | } |
| 915 | 915 | |
| 916 | 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 | 929 | } |
| 930 | 930 | |
| 931 | 931 | test "math.cast" { |
| 932 | testing.expectError(error.Overflow, cast(u8, @as(u32, 300))); | |
| 933 | testing.expectError(error.Overflow, cast(i8, @as(i32, -200))); | |
| 934 | testing.expectError(error.Overflow, cast(u8, @as(i8, -1))); | |
| 935 | testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); | |
| 932 | try testing.expectError(error.Overflow, cast(u8, @as(u32, 300))); | |
| 933 | try testing.expectError(error.Overflow, cast(i8, @as(i32, -200))); | |
| 934 | try testing.expectError(error.Overflow, cast(u8, @as(i8, -1))); | |
| 935 | try testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); | |
| 936 | 936 | |
| 937 | testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); | |
| 938 | testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8); | |
| 937 | try testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); | |
| 938 | try testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8); | |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | pub const AlignCastError = error{UnalignedMemory}; |
| ... | ... | @@ -966,17 +966,17 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T { |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | test "math.floorPowerOfTwo" { |
| 969 | testFloorPowerOfTwo(); | |
| 970 | comptime testFloorPowerOfTwo(); | |
| 969 | try testFloorPowerOfTwo(); | |
| 970 | comptime try testFloorPowerOfTwo(); | |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | fn testFloorPowerOfTwo() void { | |
| 974 | testing.expect(floorPowerOfTwo(u32, 63) == 32); | |
| 975 | testing.expect(floorPowerOfTwo(u32, 64) == 64); | |
| 976 | testing.expect(floorPowerOfTwo(u32, 65) == 64); | |
| 977 | testing.expect(floorPowerOfTwo(u4, 7) == 4); | |
| 978 | testing.expect(floorPowerOfTwo(u4, 8) == 8); | |
| 979 | testing.expect(floorPowerOfTwo(u4, 9) == 8); | |
| 973 | fn testFloorPowerOfTwo() !void { | |
| 974 | try testing.expect(floorPowerOfTwo(u32, 63) == 32); | |
| 975 | try testing.expect(floorPowerOfTwo(u32, 64) == 64); | |
| 976 | try testing.expect(floorPowerOfTwo(u32, 65) == 64); | |
| 977 | try testing.expect(floorPowerOfTwo(u4, 7) == 4); | |
| 978 | try testing.expect(floorPowerOfTwo(u4, 8) == 8); | |
| 979 | try testing.expect(floorPowerOfTwo(u4, 9) == 8); | |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 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 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | test "math.ceilPowerOfTwoPromote" { |
| 1015 | testCeilPowerOfTwoPromote(); | |
| 1016 | comptime testCeilPowerOfTwoPromote(); | |
| 1015 | try testCeilPowerOfTwoPromote(); | |
| 1016 | comptime try testCeilPowerOfTwoPromote(); | |
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | fn testCeilPowerOfTwoPromote() void { | |
| 1020 | testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1)); | |
| 1021 | testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2)); | |
| 1022 | testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63)); | |
| 1023 | testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64)); | |
| 1024 | testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65)); | |
| 1025 | testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7)); | |
| 1026 | testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8)); | |
| 1027 | testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9)); | |
| 1028 | testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); | |
| 1019 | fn testCeilPowerOfTwoPromote() !void { | |
| 1020 | try testing.expectEqual(@as(u33, 1), ceilPowerOfTwoPromote(u32, 1)); | |
| 1021 | try testing.expectEqual(@as(u33, 2), ceilPowerOfTwoPromote(u32, 2)); | |
| 1022 | try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 63)); | |
| 1023 | try testing.expectEqual(@as(u33, 64), ceilPowerOfTwoPromote(u32, 64)); | |
| 1024 | try testing.expectEqual(@as(u33, 128), ceilPowerOfTwoPromote(u32, 65)); | |
| 1025 | try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 7)); | |
| 1026 | try testing.expectEqual(@as(u6, 8), ceilPowerOfTwoPromote(u5, 8)); | |
| 1027 | try testing.expectEqual(@as(u6, 16), ceilPowerOfTwoPromote(u5, 9)); | |
| 1028 | try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); | |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | 1031 | test "math.ceilPowerOfTwo" { |
| ... | ... | @@ -1034,15 +1034,15 @@ test "math.ceilPowerOfTwo" { |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | fn testCeilPowerOfTwo() !void { |
| 1037 | testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1)); | |
| 1038 | testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2)); | |
| 1039 | testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63)); | |
| 1040 | testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64)); | |
| 1041 | testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65)); | |
| 1042 | testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7)); | |
| 1043 | testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8)); | |
| 1044 | testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9)); | |
| 1045 | testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); | |
| 1037 | try testing.expectEqual(@as(u32, 1), try ceilPowerOfTwo(u32, 1)); | |
| 1038 | try testing.expectEqual(@as(u32, 2), try ceilPowerOfTwo(u32, 2)); | |
| 1039 | try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 63)); | |
| 1040 | try testing.expectEqual(@as(u32, 64), try ceilPowerOfTwo(u32, 64)); | |
| 1041 | try testing.expectEqual(@as(u32, 128), try ceilPowerOfTwo(u32, 65)); | |
| 1042 | try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 7)); | |
| 1043 | try testing.expectEqual(@as(u5, 8), try ceilPowerOfTwo(u5, 8)); | |
| 1044 | try testing.expectEqual(@as(u5, 16), try ceilPowerOfTwo(u5, 9)); | |
| 1045 | try testing.expectError(error.Overflow, ceilPowerOfTwo(u4, 9)); | |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | pub 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 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | test "std.math.log2_int_ceil" { |
| 1062 | testing.expect(log2_int_ceil(u32, 1) == 0); | |
| 1063 | testing.expect(log2_int_ceil(u32, 2) == 1); | |
| 1064 | testing.expect(log2_int_ceil(u32, 3) == 2); | |
| 1065 | testing.expect(log2_int_ceil(u32, 4) == 2); | |
| 1066 | testing.expect(log2_int_ceil(u32, 5) == 3); | |
| 1067 | testing.expect(log2_int_ceil(u32, 6) == 3); | |
| 1068 | testing.expect(log2_int_ceil(u32, 7) == 3); | |
| 1069 | testing.expect(log2_int_ceil(u32, 8) == 3); | |
| 1070 | testing.expect(log2_int_ceil(u32, 9) == 4); | |
| 1071 | testing.expect(log2_int_ceil(u32, 10) == 4); | |
| 1062 | try testing.expect(log2_int_ceil(u32, 1) == 0); | |
| 1063 | try testing.expect(log2_int_ceil(u32, 2) == 1); | |
| 1064 | try testing.expect(log2_int_ceil(u32, 3) == 2); | |
| 1065 | try testing.expect(log2_int_ceil(u32, 4) == 2); | |
| 1066 | try testing.expect(log2_int_ceil(u32, 5) == 3); | |
| 1067 | try testing.expect(log2_int_ceil(u32, 6) == 3); | |
| 1068 | try testing.expect(log2_int_ceil(u32, 7) == 3); | |
| 1069 | try testing.expect(log2_int_ceil(u32, 8) == 3); | |
| 1070 | try testing.expect(log2_int_ceil(u32, 9) == 4); | |
| 1071 | try testing.expect(log2_int_ceil(u32, 10) == 4); | |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 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 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | test "math.lossyCast" { |
| 1115 | testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767)); | |
| 1116 | testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0)); | |
| 1117 | testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200)); | |
| 1115 | try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767)); | |
| 1116 | try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0)); | |
| 1117 | try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200)); | |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | test "math.f64_min" { |
| 1121 | 1121 | const f64_min_u64 = 0x0010000000000000; |
| 1122 | 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 | } |
| 1125 | 1125 | |
| 1126 | 1126 | pub fn maxInt(comptime T: type) comptime_int { |
| ... | ... | @@ -1139,45 +1139,45 @@ pub fn minInt(comptime T: type) comptime_int { |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | test "minInt and maxInt" { |
| 1142 | testing.expect(maxInt(u0) == 0); | |
| 1143 | testing.expect(maxInt(u1) == 1); | |
| 1144 | testing.expect(maxInt(u8) == 255); | |
| 1145 | testing.expect(maxInt(u16) == 65535); | |
| 1146 | testing.expect(maxInt(u32) == 4294967295); | |
| 1147 | testing.expect(maxInt(u64) == 18446744073709551615); | |
| 1148 | testing.expect(maxInt(u128) == 340282366920938463463374607431768211455); | |
| 1149 | ||
| 1150 | testing.expect(maxInt(i0) == 0); | |
| 1151 | testing.expect(maxInt(i1) == 0); | |
| 1152 | testing.expect(maxInt(i8) == 127); | |
| 1153 | testing.expect(maxInt(i16) == 32767); | |
| 1154 | testing.expect(maxInt(i32) == 2147483647); | |
| 1155 | testing.expect(maxInt(i63) == 4611686018427387903); | |
| 1156 | testing.expect(maxInt(i64) == 9223372036854775807); | |
| 1157 | testing.expect(maxInt(i128) == 170141183460469231731687303715884105727); | |
| 1158 | ||
| 1159 | testing.expect(minInt(u0) == 0); | |
| 1160 | testing.expect(minInt(u1) == 0); | |
| 1161 | testing.expect(minInt(u8) == 0); | |
| 1162 | testing.expect(minInt(u16) == 0); | |
| 1163 | testing.expect(minInt(u32) == 0); | |
| 1164 | testing.expect(minInt(u63) == 0); | |
| 1165 | testing.expect(minInt(u64) == 0); | |
| 1166 | testing.expect(minInt(u128) == 0); | |
| 1167 | ||
| 1168 | testing.expect(minInt(i0) == 0); | |
| 1169 | testing.expect(minInt(i1) == -1); | |
| 1170 | testing.expect(minInt(i8) == -128); | |
| 1171 | testing.expect(minInt(i16) == -32768); | |
| 1172 | testing.expect(minInt(i32) == -2147483648); | |
| 1173 | testing.expect(minInt(i63) == -4611686018427387904); | |
| 1174 | testing.expect(minInt(i64) == -9223372036854775808); | |
| 1175 | testing.expect(minInt(i128) == -170141183460469231731687303715884105728); | |
| 1142 | try testing.expect(maxInt(u0) == 0); | |
| 1143 | try testing.expect(maxInt(u1) == 1); | |
| 1144 | try testing.expect(maxInt(u8) == 255); | |
| 1145 | try testing.expect(maxInt(u16) == 65535); | |
| 1146 | try testing.expect(maxInt(u32) == 4294967295); | |
| 1147 | try testing.expect(maxInt(u64) == 18446744073709551615); | |
| 1148 | try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455); | |
| 1149 | ||
| 1150 | try testing.expect(maxInt(i0) == 0); | |
| 1151 | try testing.expect(maxInt(i1) == 0); | |
| 1152 | try testing.expect(maxInt(i8) == 127); | |
| 1153 | try testing.expect(maxInt(i16) == 32767); | |
| 1154 | try testing.expect(maxInt(i32) == 2147483647); | |
| 1155 | try testing.expect(maxInt(i63) == 4611686018427387903); | |
| 1156 | try testing.expect(maxInt(i64) == 9223372036854775807); | |
| 1157 | try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727); | |
| 1158 | ||
| 1159 | try testing.expect(minInt(u0) == 0); | |
| 1160 | try testing.expect(minInt(u1) == 0); | |
| 1161 | try testing.expect(minInt(u8) == 0); | |
| 1162 | try testing.expect(minInt(u16) == 0); | |
| 1163 | try testing.expect(minInt(u32) == 0); | |
| 1164 | try testing.expect(minInt(u63) == 0); | |
| 1165 | try testing.expect(minInt(u64) == 0); | |
| 1166 | try testing.expect(minInt(u128) == 0); | |
| 1167 | ||
| 1168 | try testing.expect(minInt(i0) == 0); | |
| 1169 | try testing.expect(minInt(i1) == -1); | |
| 1170 | try testing.expect(minInt(i8) == -128); | |
| 1171 | try testing.expect(minInt(i16) == -32768); | |
| 1172 | try testing.expect(minInt(i32) == -2147483648); | |
| 1173 | try testing.expect(minInt(i63) == -4611686018427387904); | |
| 1174 | try testing.expect(minInt(i64) == -9223372036854775808); | |
| 1175 | try testing.expect(minInt(i128) == -170141183460469231731687303715884105728); | |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | test "max value type" { |
| 1179 | 1179 | const x: u32 = maxInt(i32); |
| 1180 | testing.expect(x == 2147483647); | |
| 1180 | try testing.expect(x == 2147483647); | |
| 1181 | 1181 | } |
| 1182 | 1182 | |
| 1183 | 1183 | pub 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 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | test "math.mulWide" { |
| 1189 | testing.expect(mulWide(u8, 5, 5) == 25); | |
| 1190 | testing.expect(mulWide(i8, 5, -5) == -25); | |
| 1191 | testing.expect(mulWide(u8, 100, 100) == 10000); | |
| 1189 | try testing.expect(mulWide(u8, 5, 5) == 25); | |
| 1190 | try testing.expect(mulWide(i8, 5, -5) == -25); | |
| 1191 | try testing.expect(mulWide(u8, 100, 100) == 10000); | |
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | 1194 | /// See also `CompareOperator`. |
| ... | ... | @@ -1284,51 +1284,51 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool { |
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | test "compare between signed and unsigned" { |
| 1287 | testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255))); | |
| 1288 | testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1))); | |
| 1289 | testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255))); | |
| 1290 | testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1))); | |
| 1291 | testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1))); | |
| 1292 | testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255))); | |
| 1293 | testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255))); | |
| 1294 | testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1))); | |
| 1295 | testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1))); | |
| 1296 | testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255))); | |
| 1297 | testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255))); | |
| 1298 | testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1))); | |
| 1299 | testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1))); | |
| 1300 | testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2))); | |
| 1301 | testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255)); | |
| 1302 | testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1))); | |
| 1303 | testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); | |
| 1287 | try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255))); | |
| 1288 | try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1))); | |
| 1289 | try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255))); | |
| 1290 | try testing.expect(compare(@as(u8, 255), .gt, @as(i8, -1))); | |
| 1291 | try testing.expect(!compare(@as(u8, 255), .lte, @as(i8, -1))); | |
| 1292 | try testing.expect(compare(@as(i8, -1), .lt, @as(u9, 255))); | |
| 1293 | try testing.expect(!compare(@as(i8, -1), .gte, @as(u9, 255))); | |
| 1294 | try testing.expect(compare(@as(u9, 255), .gt, @as(i8, -1))); | |
| 1295 | try testing.expect(!compare(@as(u9, 255), .lte, @as(i8, -1))); | |
| 1296 | try testing.expect(compare(@as(i9, -1), .lt, @as(u8, 255))); | |
| 1297 | try testing.expect(!compare(@as(i9, -1), .gte, @as(u8, 255))); | |
| 1298 | try testing.expect(compare(@as(u8, 255), .gt, @as(i9, -1))); | |
| 1299 | try testing.expect(!compare(@as(u8, 255), .lte, @as(i9, -1))); | |
| 1300 | try testing.expect(compare(@as(u8, 1), .lt, @as(u8, 2))); | |
| 1301 | try testing.expect(@bitCast(u8, @as(i8, -1)) == @as(u8, 255)); | |
| 1302 | try testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1))); | |
| 1303 | try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); | |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | test "order" { |
| 1307 | testing.expect(order(0, 0) == .eq); | |
| 1308 | testing.expect(order(1, 0) == .gt); | |
| 1309 | testing.expect(order(-1, 0) == .lt); | |
| 1307 | try testing.expect(order(0, 0) == .eq); | |
| 1308 | try testing.expect(order(1, 0) == .gt); | |
| 1309 | try testing.expect(order(-1, 0) == .lt); | |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | test "order.invert" { |
| 1313 | testing.expect(Order.invert(order(0, 0)) == .eq); | |
| 1314 | testing.expect(Order.invert(order(1, 0)) == .lt); | |
| 1315 | testing.expect(Order.invert(order(-1, 0)) == .gt); | |
| 1313 | try testing.expect(Order.invert(order(0, 0)) == .eq); | |
| 1314 | try testing.expect(Order.invert(order(1, 0)) == .lt); | |
| 1315 | try testing.expect(Order.invert(order(-1, 0)) == .gt); | |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | test "order.compare" { |
| 1319 | testing.expect(order(-1, 0).compare(.lt)); | |
| 1320 | testing.expect(order(-1, 0).compare(.lte)); | |
| 1321 | testing.expect(order(0, 0).compare(.lte)); | |
| 1322 | testing.expect(order(0, 0).compare(.eq)); | |
| 1323 | testing.expect(order(0, 0).compare(.gte)); | |
| 1324 | testing.expect(order(1, 0).compare(.gte)); | |
| 1325 | testing.expect(order(1, 0).compare(.gt)); | |
| 1326 | testing.expect(order(1, 0).compare(.neq)); | |
| 1319 | try testing.expect(order(-1, 0).compare(.lt)); | |
| 1320 | try testing.expect(order(-1, 0).compare(.lte)); | |
| 1321 | try testing.expect(order(0, 0).compare(.lte)); | |
| 1322 | try testing.expect(order(0, 0).compare(.eq)); | |
| 1323 | try testing.expect(order(0, 0).compare(.gte)); | |
| 1324 | try testing.expect(order(1, 0).compare(.gte)); | |
| 1325 | try testing.expect(order(1, 0).compare(.gt)); | |
| 1326 | try testing.expect(order(1, 0).compare(.neq)); | |
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | test "math.comptime" { |
| 1330 | 1330 | comptime const v = 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 | } |
| 1333 | 1333 | |
| 1334 | 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 | 1354 | |
| 1355 | 1355 | test "boolMask" { |
| 1356 | 1356 | const runTest = struct { |
| 1357 | fn runTest() void { | |
| 1358 | testing.expectEqual(@as(u1, 0), boolMask(u1, false)); | |
| 1359 | testing.expectEqual(@as(u1, 1), boolMask(u1, true)); | |
| 1357 | fn runTest() !void { | |
| 1358 | try testing.expectEqual(@as(u1, 0), boolMask(u1, false)); | |
| 1359 | try testing.expectEqual(@as(u1, 1), boolMask(u1, true)); | |
| 1360 | 1360 | |
| 1361 | testing.expectEqual(@as(i1, 0), boolMask(i1, false)); | |
| 1362 | testing.expectEqual(@as(i1, -1), boolMask(i1, true)); | |
| 1361 | try testing.expectEqual(@as(i1, 0), boolMask(i1, false)); | |
| 1362 | try testing.expectEqual(@as(i1, -1), boolMask(i1, true)); | |
| 1363 | 1363 | |
| 1364 | testing.expectEqual(@as(u13, 0), boolMask(u13, false)); | |
| 1365 | testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true)); | |
| 1364 | try testing.expectEqual(@as(u13, 0), boolMask(u13, false)); | |
| 1365 | try testing.expectEqual(@as(u13, 0x1FFF), boolMask(u13, true)); | |
| 1366 | 1366 | |
| 1367 | testing.expectEqual(@as(i13, 0), boolMask(i13, false)); | |
| 1368 | testing.expectEqual(@as(i13, -1), boolMask(i13, true)); | |
| 1367 | try testing.expectEqual(@as(i13, 0), boolMask(i13, false)); | |
| 1368 | try testing.expectEqual(@as(i13, -1), boolMask(i13, true)); | |
| 1369 | 1369 | |
| 1370 | testing.expectEqual(@as(u32, 0), boolMask(u32, false)); | |
| 1371 | testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true)); | |
| 1370 | try testing.expectEqual(@as(u32, 0), boolMask(u32, false)); | |
| 1371 | try testing.expectEqual(@as(u32, 0xFFFF_FFFF), boolMask(u32, true)); | |
| 1372 | 1372 | |
| 1373 | testing.expectEqual(@as(i32, 0), boolMask(i32, false)); | |
| 1374 | testing.expectEqual(@as(i32, -1), boolMask(i32, true)); | |
| 1373 | try testing.expectEqual(@as(i32, 0), boolMask(i32, false)); | |
| 1374 | try testing.expectEqual(@as(i32, -1), boolMask(i32, true)); | |
| 1375 | 1375 | } |
| 1376 | 1376 | }.runTest; |
| 1377 | runTest(); | |
| 1378 | comptime runTest(); | |
| 1377 | try runTest(); | |
| 1378 | comptime try runTest(); | |
| 1379 | 1379 | } |
lib/std/math/acos.zig+18-18| ... | ... | @@ -154,38 +154,38 @@ fn acos64(x: f64) f64 { |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | test "math.acos" { |
| 157 | expect(acos(@as(f32, 0.0)) == acos32(0.0)); | |
| 158 | expect(acos(@as(f64, 0.0)) == acos64(0.0)); | |
| 157 | try expect(acos(@as(f32, 0.0)) == acos32(0.0)); | |
| 158 | try expect(acos(@as(f64, 0.0)) == acos64(0.0)); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | test "math.acos32" { |
| 162 | 162 | const epsilon = 0.000001; |
| 163 | 163 | |
| 164 | expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon)); | |
| 165 | expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon)); | |
| 166 | expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon)); | |
| 167 | expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon)); | |
| 168 | expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon)); | |
| 169 | expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon)); | |
| 164 | try expect(math.approxEqAbs(f32, acos32(0.0), 1.570796, epsilon)); | |
| 165 | try expect(math.approxEqAbs(f32, acos32(0.2), 1.369438, epsilon)); | |
| 166 | try expect(math.approxEqAbs(f32, acos32(0.3434), 1.220262, epsilon)); | |
| 167 | try expect(math.approxEqAbs(f32, acos32(0.5), 1.047198, epsilon)); | |
| 168 | try expect(math.approxEqAbs(f32, acos32(0.8923), 0.468382, epsilon)); | |
| 169 | try expect(math.approxEqAbs(f32, acos32(-0.2), 1.772154, epsilon)); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "math.acos64" { |
| 173 | 173 | const epsilon = 0.000001; |
| 174 | 174 | |
| 175 | expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon)); | |
| 176 | expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon)); | |
| 177 | expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon)); | |
| 178 | expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon)); | |
| 179 | expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon)); | |
| 180 | expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon)); | |
| 175 | try expect(math.approxEqAbs(f64, acos64(0.0), 1.570796, epsilon)); | |
| 176 | try expect(math.approxEqAbs(f64, acos64(0.2), 1.369438, epsilon)); | |
| 177 | try expect(math.approxEqAbs(f64, acos64(0.3434), 1.220262, epsilon)); | |
| 178 | try expect(math.approxEqAbs(f64, acos64(0.5), 1.047198, epsilon)); | |
| 179 | try expect(math.approxEqAbs(f64, acos64(0.8923), 0.468382, epsilon)); | |
| 180 | try expect(math.approxEqAbs(f64, acos64(-0.2), 1.772154, epsilon)); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | test "math.acos32.special" { |
| 184 | expect(math.isNan(acos32(-2))); | |
| 185 | expect(math.isNan(acos32(1.5))); | |
| 184 | try expect(math.isNan(acos32(-2))); | |
| 185 | try expect(math.isNan(acos32(1.5))); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | test "math.acos64.special" { |
| 189 | expect(math.isNan(acos64(-2))); | |
| 190 | expect(math.isNan(acos64(1.5))); | |
| 189 | try expect(math.isNan(acos64(-2))); | |
| 190 | try expect(math.isNan(acos64(1.5))); | |
| 191 | 191 | } |
lib/std/math/acosh.zig+14-14| ... | ... | @@ -66,34 +66,34 @@ fn acosh64(x: f64) f64 { |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "math.acosh" { |
| 69 | expect(acosh(@as(f32, 1.5)) == acosh32(1.5)); | |
| 70 | expect(acosh(@as(f64, 1.5)) == acosh64(1.5)); | |
| 69 | try expect(acosh(@as(f32, 1.5)) == acosh32(1.5)); | |
| 70 | try expect(acosh(@as(f64, 1.5)) == acosh64(1.5)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | test "math.acosh32" { |
| 74 | 74 | const epsilon = 0.000001; |
| 75 | 75 | |
| 76 | expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon)); | |
| 77 | expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon)); | |
| 78 | expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon)); | |
| 79 | expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon)); | |
| 76 | try expect(math.approxEqAbs(f32, acosh32(1.5), 0.962424, epsilon)); | |
| 77 | try expect(math.approxEqAbs(f32, acosh32(37.45), 4.315976, epsilon)); | |
| 78 | try expect(math.approxEqAbs(f32, acosh32(89.123), 5.183133, epsilon)); | |
| 79 | try expect(math.approxEqAbs(f32, acosh32(123123.234375), 12.414088, epsilon)); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | test "math.acosh64" { |
| 83 | 83 | const epsilon = 0.000001; |
| 84 | 84 | |
| 85 | expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon)); | |
| 86 | expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon)); | |
| 87 | expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon)); | |
| 88 | expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon)); | |
| 85 | try expect(math.approxEqAbs(f64, acosh64(1.5), 0.962424, epsilon)); | |
| 86 | try expect(math.approxEqAbs(f64, acosh64(37.45), 4.315976, epsilon)); | |
| 87 | try expect(math.approxEqAbs(f64, acosh64(89.123), 5.183133, epsilon)); | |
| 88 | try expect(math.approxEqAbs(f64, acosh64(123123.234375), 12.414088, epsilon)); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "math.acosh32.special" { |
| 92 | expect(math.isNan(acosh32(math.nan(f32)))); | |
| 93 | expect(math.isSignalNan(acosh32(0.5))); | |
| 92 | try expect(math.isNan(acosh32(math.nan(f32)))); | |
| 93 | try expect(math.isSignalNan(acosh32(0.5))); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.acosh64.special" { |
| 97 | expect(math.isNan(acosh64(math.nan(f64)))); | |
| 98 | expect(math.isSignalNan(acosh64(0.5))); | |
| 97 | try expect(math.isNan(acosh64(math.nan(f64)))); | |
| 98 | try expect(math.isSignalNan(acosh64(0.5))); | |
| 99 | 99 | } |
lib/std/math/asin.zig+22-22| ... | ... | @@ -147,42 +147,42 @@ fn asin64(x: f64) f64 { |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | test "math.asin" { |
| 150 | expect(asin(@as(f32, 0.0)) == asin32(0.0)); | |
| 151 | expect(asin(@as(f64, 0.0)) == asin64(0.0)); | |
| 150 | try expect(asin(@as(f32, 0.0)) == asin32(0.0)); | |
| 151 | try expect(asin(@as(f64, 0.0)) == asin64(0.0)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.asin32" { |
| 155 | 155 | const epsilon = 0.000001; |
| 156 | 156 | |
| 157 | expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon)); | |
| 158 | expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon)); | |
| 159 | expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon)); | |
| 160 | expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon)); | |
| 161 | expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon)); | |
| 162 | expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon)); | |
| 157 | try expect(math.approxEqAbs(f32, asin32(0.0), 0.0, epsilon)); | |
| 158 | try expect(math.approxEqAbs(f32, asin32(0.2), 0.201358, epsilon)); | |
| 159 | try expect(math.approxEqAbs(f32, asin32(-0.2), -0.201358, epsilon)); | |
| 160 | try expect(math.approxEqAbs(f32, asin32(0.3434), 0.350535, epsilon)); | |
| 161 | try expect(math.approxEqAbs(f32, asin32(0.5), 0.523599, epsilon)); | |
| 162 | try expect(math.approxEqAbs(f32, asin32(0.8923), 1.102415, epsilon)); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | test "math.asin64" { |
| 166 | 166 | const epsilon = 0.000001; |
| 167 | 167 | |
| 168 | expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon)); | |
| 169 | expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon)); | |
| 170 | expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon)); | |
| 171 | expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon)); | |
| 172 | expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon)); | |
| 173 | expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon)); | |
| 168 | try expect(math.approxEqAbs(f64, asin64(0.0), 0.0, epsilon)); | |
| 169 | try expect(math.approxEqAbs(f64, asin64(0.2), 0.201358, epsilon)); | |
| 170 | try expect(math.approxEqAbs(f64, asin64(-0.2), -0.201358, epsilon)); | |
| 171 | try expect(math.approxEqAbs(f64, asin64(0.3434), 0.350535, epsilon)); | |
| 172 | try expect(math.approxEqAbs(f64, asin64(0.5), 0.523599, epsilon)); | |
| 173 | try expect(math.approxEqAbs(f64, asin64(0.8923), 1.102415, epsilon)); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "math.asin32.special" { |
| 177 | expect(asin32(0.0) == 0.0); | |
| 178 | expect(asin32(-0.0) == -0.0); | |
| 179 | expect(math.isNan(asin32(-2))); | |
| 180 | expect(math.isNan(asin32(1.5))); | |
| 177 | try expect(asin32(0.0) == 0.0); | |
| 178 | try expect(asin32(-0.0) == -0.0); | |
| 179 | try expect(math.isNan(asin32(-2))); | |
| 180 | try expect(math.isNan(asin32(1.5))); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | test "math.asin64.special" { |
| 184 | expect(asin64(0.0) == 0.0); | |
| 185 | expect(asin64(-0.0) == -0.0); | |
| 186 | expect(math.isNan(asin64(-2))); | |
| 187 | expect(math.isNan(asin64(1.5))); | |
| 184 | try expect(asin64(0.0) == 0.0); | |
| 185 | try expect(asin64(-0.0) == -0.0); | |
| 186 | try expect(math.isNan(asin64(-2))); | |
| 187 | try expect(math.isNan(asin64(1.5))); | |
| 188 | 188 | } |
lib/std/math/asinh.zig+26-26| ... | ... | @@ -94,46 +94,46 @@ fn asinh64(x: f64) f64 { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.asinh" { |
| 97 | expect(asinh(@as(f32, 0.0)) == asinh32(0.0)); | |
| 98 | expect(asinh(@as(f64, 0.0)) == asinh64(0.0)); | |
| 97 | try expect(asinh(@as(f32, 0.0)) == asinh32(0.0)); | |
| 98 | try expect(asinh(@as(f64, 0.0)) == asinh64(0.0)); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | test "math.asinh32" { |
| 102 | 102 | const epsilon = 0.000001; |
| 103 | 103 | |
| 104 | expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon)); | |
| 105 | expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon)); | |
| 106 | expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon)); | |
| 107 | expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon)); | |
| 108 | expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon)); | |
| 109 | expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon)); | |
| 110 | expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon)); | |
| 104 | try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon)); | |
| 105 | try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon)); | |
| 106 | try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon)); | |
| 107 | try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon)); | |
| 108 | try expect(math.approxEqAbs(f32, asinh32(37.45), 4.316332, epsilon)); | |
| 109 | try expect(math.approxEqAbs(f32, asinh32(89.123), 5.183196, epsilon)); | |
| 110 | try expect(math.approxEqAbs(f32, asinh32(123123.234375), 12.414088, epsilon)); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "math.asinh64" { |
| 114 | 114 | const epsilon = 0.000001; |
| 115 | 115 | |
| 116 | expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon)); | |
| 117 | expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon)); | |
| 118 | expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon)); | |
| 119 | expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon)); | |
| 120 | expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon)); | |
| 121 | expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon)); | |
| 122 | expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon)); | |
| 116 | try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon)); | |
| 117 | try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon)); | |
| 118 | try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon)); | |
| 119 | try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon)); | |
| 120 | try expect(math.approxEqAbs(f64, asinh64(37.45), 4.316332, epsilon)); | |
| 121 | try expect(math.approxEqAbs(f64, asinh64(89.123), 5.183196, epsilon)); | |
| 122 | try expect(math.approxEqAbs(f64, asinh64(123123.234375), 12.414088, epsilon)); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "math.asinh32.special" { |
| 126 | expect(asinh32(0.0) == 0.0); | |
| 127 | expect(asinh32(-0.0) == -0.0); | |
| 128 | expect(math.isPositiveInf(asinh32(math.inf(f32)))); | |
| 129 | expect(math.isNegativeInf(asinh32(-math.inf(f32)))); | |
| 130 | expect(math.isNan(asinh32(math.nan(f32)))); | |
| 126 | try expect(asinh32(0.0) == 0.0); | |
| 127 | try expect(asinh32(-0.0) == -0.0); | |
| 128 | try expect(math.isPositiveInf(asinh32(math.inf(f32)))); | |
| 129 | try expect(math.isNegativeInf(asinh32(-math.inf(f32)))); | |
| 130 | try expect(math.isNan(asinh32(math.nan(f32)))); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "math.asinh64.special" { |
| 134 | expect(asinh64(0.0) == 0.0); | |
| 135 | expect(asinh64(-0.0) == -0.0); | |
| 136 | expect(math.isPositiveInf(asinh64(math.inf(f64)))); | |
| 137 | expect(math.isNegativeInf(asinh64(-math.inf(f64)))); | |
| 138 | expect(math.isNan(asinh64(math.nan(f64)))); | |
| 134 | try expect(asinh64(0.0) == 0.0); | |
| 135 | try expect(asinh64(-0.0) == -0.0); | |
| 136 | try expect(math.isPositiveInf(asinh64(math.inf(f64)))); | |
| 137 | try expect(math.isNegativeInf(asinh64(-math.inf(f64)))); | |
| 138 | try expect(math.isNan(asinh64(math.nan(f64)))); | |
| 139 | 139 | } |
lib/std/math/atan.zig+20-20| ... | ... | @@ -217,44 +217,44 @@ fn atan64(x_: f64) f64 { |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "math.atan" { |
| 220 | expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2))); | |
| 221 | expect(atan(@as(f64, 0.2)) == atan64(0.2)); | |
| 220 | try expect(@bitCast(u32, atan(@as(f32, 0.2))) == @bitCast(u32, atan32(0.2))); | |
| 221 | try expect(atan(@as(f64, 0.2)) == atan64(0.2)); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | test "math.atan32" { |
| 225 | 225 | const epsilon = 0.000001; |
| 226 | 226 | |
| 227 | expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon)); | |
| 228 | expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon)); | |
| 229 | expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon)); | |
| 230 | expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon)); | |
| 231 | expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon)); | |
| 227 | try expect(math.approxEqAbs(f32, atan32(0.2), 0.197396, epsilon)); | |
| 228 | try expect(math.approxEqAbs(f32, atan32(-0.2), -0.197396, epsilon)); | |
| 229 | try expect(math.approxEqAbs(f32, atan32(0.3434), 0.330783, epsilon)); | |
| 230 | try expect(math.approxEqAbs(f32, atan32(0.8923), 0.728545, epsilon)); | |
| 231 | try expect(math.approxEqAbs(f32, atan32(1.5), 0.982794, epsilon)); | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | test "math.atan64" { |
| 235 | 235 | const epsilon = 0.000001; |
| 236 | 236 | |
| 237 | expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon)); | |
| 238 | expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon)); | |
| 239 | expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon)); | |
| 240 | expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon)); | |
| 241 | expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon)); | |
| 237 | try expect(math.approxEqAbs(f64, atan64(0.2), 0.197396, epsilon)); | |
| 238 | try expect(math.approxEqAbs(f64, atan64(-0.2), -0.197396, epsilon)); | |
| 239 | try expect(math.approxEqAbs(f64, atan64(0.3434), 0.330783, epsilon)); | |
| 240 | try expect(math.approxEqAbs(f64, atan64(0.8923), 0.728545, epsilon)); | |
| 241 | try expect(math.approxEqAbs(f64, atan64(1.5), 0.982794, epsilon)); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | test "math.atan32.special" { |
| 245 | 245 | const epsilon = 0.000001; |
| 246 | 246 | |
| 247 | expect(atan32(0.0) == 0.0); | |
| 248 | expect(atan32(-0.0) == -0.0); | |
| 249 | expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon)); | |
| 250 | expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon)); | |
| 247 | try expect(atan32(0.0) == 0.0); | |
| 248 | try expect(atan32(-0.0) == -0.0); | |
| 249 | try expect(math.approxEqAbs(f32, atan32(math.inf(f32)), math.pi / 2.0, epsilon)); | |
| 250 | try expect(math.approxEqAbs(f32, atan32(-math.inf(f32)), -math.pi / 2.0, epsilon)); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | test "math.atan64.special" { |
| 254 | 254 | const epsilon = 0.000001; |
| 255 | 255 | |
| 256 | expect(atan64(0.0) == 0.0); | |
| 257 | expect(atan64(-0.0) == -0.0); | |
| 258 | expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon)); | |
| 259 | expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon)); | |
| 256 | try expect(atan64(0.0) == 0.0); | |
| 257 | try expect(atan64(-0.0) == -0.0); | |
| 258 | try expect(math.approxEqAbs(f64, atan64(math.inf(f64)), math.pi / 2.0, epsilon)); | |
| 259 | try expect(math.approxEqAbs(f64, atan64(-math.inf(f64)), -math.pi / 2.0, epsilon)); | |
| 260 | 260 | } |
lib/std/math/atan2.zig+52-52| ... | ... | @@ -217,78 +217,78 @@ fn atan2_64(y: f64, x: f64) f64 { |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "math.atan2" { |
| 220 | expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21)); | |
| 221 | expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21)); | |
| 220 | try expect(atan2(f32, 0.2, 0.21) == atan2_32(0.2, 0.21)); | |
| 221 | try expect(atan2(f64, 0.2, 0.21) == atan2_64(0.2, 0.21)); | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | test "math.atan2_32" { |
| 225 | 225 | const epsilon = 0.000001; |
| 226 | 226 | |
| 227 | expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon)); | |
| 228 | expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon)); | |
| 229 | expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon)); | |
| 230 | expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon)); | |
| 231 | expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon)); | |
| 232 | expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon)); | |
| 233 | expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon)); | |
| 227 | try expect(math.approxEqAbs(f32, atan2_32(0.0, 0.0), 0.0, epsilon)); | |
| 228 | try expect(math.approxEqAbs(f32, atan2_32(0.2, 0.2), 0.785398, epsilon)); | |
| 229 | try expect(math.approxEqAbs(f32, atan2_32(-0.2, 0.2), -0.785398, epsilon)); | |
| 230 | try expect(math.approxEqAbs(f32, atan2_32(0.2, -0.2), 2.356194, epsilon)); | |
| 231 | try expect(math.approxEqAbs(f32, atan2_32(-0.2, -0.2), -2.356194, epsilon)); | |
| 232 | try expect(math.approxEqAbs(f32, atan2_32(0.34, -0.4), 2.437099, epsilon)); | |
| 233 | try expect(math.approxEqAbs(f32, atan2_32(0.34, 1.243), 0.267001, epsilon)); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | test "math.atan2_64" { |
| 237 | 237 | const epsilon = 0.000001; |
| 238 | 238 | |
| 239 | expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon)); | |
| 240 | expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon)); | |
| 241 | expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon)); | |
| 242 | expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon)); | |
| 243 | expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon)); | |
| 244 | expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon)); | |
| 245 | expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon)); | |
| 239 | try expect(math.approxEqAbs(f64, atan2_64(0.0, 0.0), 0.0, epsilon)); | |
| 240 | try expect(math.approxEqAbs(f64, atan2_64(0.2, 0.2), 0.785398, epsilon)); | |
| 241 | try expect(math.approxEqAbs(f64, atan2_64(-0.2, 0.2), -0.785398, epsilon)); | |
| 242 | try expect(math.approxEqAbs(f64, atan2_64(0.2, -0.2), 2.356194, epsilon)); | |
| 243 | try expect(math.approxEqAbs(f64, atan2_64(-0.2, -0.2), -2.356194, epsilon)); | |
| 244 | try expect(math.approxEqAbs(f64, atan2_64(0.34, -0.4), 2.437099, epsilon)); | |
| 245 | try expect(math.approxEqAbs(f64, atan2_64(0.34, 1.243), 0.267001, epsilon)); | |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | test "math.atan2_32.special" { |
| 249 | 249 | const epsilon = 0.000001; |
| 250 | 250 | |
| 251 | expect(math.isNan(atan2_32(1.0, math.nan(f32)))); | |
| 252 | expect(math.isNan(atan2_32(math.nan(f32), 1.0))); | |
| 253 | expect(atan2_32(0.0, 5.0) == 0.0); | |
| 254 | expect(atan2_32(-0.0, 5.0) == -0.0); | |
| 255 | expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon)); | |
| 251 | try expect(math.isNan(atan2_32(1.0, math.nan(f32)))); | |
| 252 | try expect(math.isNan(atan2_32(math.nan(f32), 1.0))); | |
| 253 | try expect(atan2_32(0.0, 5.0) == 0.0); | |
| 254 | try expect(atan2_32(-0.0, 5.0) == -0.0); | |
| 255 | try expect(math.approxEqAbs(f32, atan2_32(0.0, -5.0), math.pi, epsilon)); | |
| 256 | 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)); | |
| 258 | expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 259 | expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 260 | expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 261 | expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon)); | |
| 262 | expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon)); | |
| 263 | expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon)); | |
| 264 | expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon)); | |
| 265 | expect(atan2_32(1.0, math.inf(f32)) == 0.0); | |
| 266 | expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon)); | |
| 267 | expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon)); | |
| 268 | expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon)); | |
| 269 | expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon)); | |
| 257 | try expect(math.approxEqAbs(f32, atan2_32(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 258 | try expect(math.approxEqAbs(f32, atan2_32(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 259 | try expect(math.approxEqAbs(f32, atan2_32(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 260 | try expect(math.approxEqAbs(f32, atan2_32(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 261 | try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), math.inf(f32)), math.pi / 4.0, epsilon)); | |
| 262 | try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), math.inf(f32)), -math.pi / 4.0, epsilon)); | |
| 263 | try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), -math.inf(f32)), 3.0 * math.pi / 4.0, epsilon)); | |
| 264 | try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), -math.inf(f32)), -3.0 * math.pi / 4.0, epsilon)); | |
| 265 | try expect(atan2_32(1.0, math.inf(f32)) == 0.0); | |
| 266 | try expect(math.approxEqAbs(f32, atan2_32(1.0, -math.inf(f32)), math.pi, epsilon)); | |
| 267 | try expect(math.approxEqAbs(f32, atan2_32(-1.0, -math.inf(f32)), -math.pi, epsilon)); | |
| 268 | try expect(math.approxEqAbs(f32, atan2_32(math.inf(f32), 1.0), math.pi / 2.0, epsilon)); | |
| 269 | try expect(math.approxEqAbs(f32, atan2_32(-math.inf(f32), 1.0), -math.pi / 2.0, epsilon)); | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | test "math.atan2_64.special" { |
| 273 | 273 | const epsilon = 0.000001; |
| 274 | 274 | |
| 275 | expect(math.isNan(atan2_64(1.0, math.nan(f64)))); | |
| 276 | expect(math.isNan(atan2_64(math.nan(f64), 1.0))); | |
| 277 | expect(atan2_64(0.0, 5.0) == 0.0); | |
| 278 | expect(atan2_64(-0.0, 5.0) == -0.0); | |
| 279 | expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon)); | |
| 275 | try expect(math.isNan(atan2_64(1.0, math.nan(f64)))); | |
| 276 | try expect(math.isNan(atan2_64(math.nan(f64), 1.0))); | |
| 277 | try expect(atan2_64(0.0, 5.0) == 0.0); | |
| 278 | try expect(atan2_64(-0.0, 5.0) == -0.0); | |
| 279 | try expect(math.approxEqAbs(f64, atan2_64(0.0, -5.0), math.pi, epsilon)); | |
| 280 | 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)); | |
| 282 | expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 283 | expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 284 | expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 285 | expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon)); | |
| 286 | expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon)); | |
| 287 | expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon)); | |
| 288 | expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon)); | |
| 289 | expect(atan2_64(1.0, math.inf(f64)) == 0.0); | |
| 290 | expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon)); | |
| 291 | expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon)); | |
| 292 | expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon)); | |
| 293 | expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon)); | |
| 281 | try expect(math.approxEqAbs(f64, atan2_64(1.0, 0.0), math.pi / 2.0, epsilon)); | |
| 282 | try expect(math.approxEqAbs(f64, atan2_64(1.0, -0.0), math.pi / 2.0, epsilon)); | |
| 283 | try expect(math.approxEqAbs(f64, atan2_64(-1.0, 0.0), -math.pi / 2.0, epsilon)); | |
| 284 | try expect(math.approxEqAbs(f64, atan2_64(-1.0, -0.0), -math.pi / 2.0, epsilon)); | |
| 285 | try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), math.inf(f64)), math.pi / 4.0, epsilon)); | |
| 286 | try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), math.inf(f64)), -math.pi / 4.0, epsilon)); | |
| 287 | try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), -math.inf(f64)), 3.0 * math.pi / 4.0, epsilon)); | |
| 288 | try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), -math.inf(f64)), -3.0 * math.pi / 4.0, epsilon)); | |
| 289 | try expect(atan2_64(1.0, math.inf(f64)) == 0.0); | |
| 290 | try expect(math.approxEqAbs(f64, atan2_64(1.0, -math.inf(f64)), math.pi, epsilon)); | |
| 291 | try expect(math.approxEqAbs(f64, atan2_64(-1.0, -math.inf(f64)), -math.pi, epsilon)); | |
| 292 | try expect(math.approxEqAbs(f64, atan2_64(math.inf(f64), 1.0), math.pi / 2.0, epsilon)); | |
| 293 | try expect(math.approxEqAbs(f64, atan2_64(-math.inf(f64), 1.0), -math.pi / 2.0, epsilon)); | |
| 294 | 294 | } |
lib/std/math/atanh.zig+18-18| ... | ... | @@ -89,38 +89,38 @@ fn atanh_64(x: f64) f64 { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "math.atanh" { |
| 92 | expect(atanh(@as(f32, 0.0)) == atanh_32(0.0)); | |
| 93 | expect(atanh(@as(f64, 0.0)) == atanh_64(0.0)); | |
| 92 | try expect(atanh(@as(f32, 0.0)) == atanh_32(0.0)); | |
| 93 | try expect(atanh(@as(f64, 0.0)) == atanh_64(0.0)); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.atanh_32" { |
| 97 | 97 | const epsilon = 0.000001; |
| 98 | 98 | |
| 99 | expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon)); | |
| 100 | expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon)); | |
| 101 | expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon)); | |
| 99 | try expect(math.approxEqAbs(f32, atanh_32(0.0), 0.0, epsilon)); | |
| 100 | try expect(math.approxEqAbs(f32, atanh_32(0.2), 0.202733, epsilon)); | |
| 101 | try expect(math.approxEqAbs(f32, atanh_32(0.8923), 1.433099, epsilon)); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | test "math.atanh_64" { |
| 105 | 105 | const epsilon = 0.000001; |
| 106 | 106 | |
| 107 | expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon)); | |
| 108 | expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon)); | |
| 109 | expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon)); | |
| 107 | try expect(math.approxEqAbs(f64, atanh_64(0.0), 0.0, epsilon)); | |
| 108 | try expect(math.approxEqAbs(f64, atanh_64(0.2), 0.202733, epsilon)); | |
| 109 | try expect(math.approxEqAbs(f64, atanh_64(0.8923), 1.433099, epsilon)); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "math.atanh32.special" { |
| 113 | expect(math.isPositiveInf(atanh_32(1))); | |
| 114 | expect(math.isNegativeInf(atanh_32(-1))); | |
| 115 | expect(math.isSignalNan(atanh_32(1.5))); | |
| 116 | expect(math.isSignalNan(atanh_32(-1.5))); | |
| 117 | expect(math.isNan(atanh_32(math.nan(f32)))); | |
| 113 | try expect(math.isPositiveInf(atanh_32(1))); | |
| 114 | try expect(math.isNegativeInf(atanh_32(-1))); | |
| 115 | try expect(math.isSignalNan(atanh_32(1.5))); | |
| 116 | try expect(math.isSignalNan(atanh_32(-1.5))); | |
| 117 | try expect(math.isNan(atanh_32(math.nan(f32)))); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "math.atanh64.special" { |
| 121 | expect(math.isPositiveInf(atanh_64(1))); | |
| 122 | expect(math.isNegativeInf(atanh_64(-1))); | |
| 123 | expect(math.isSignalNan(atanh_64(1.5))); | |
| 124 | expect(math.isSignalNan(atanh_64(-1.5))); | |
| 125 | expect(math.isNan(atanh_64(math.nan(f64)))); | |
| 121 | try expect(math.isPositiveInf(atanh_64(1))); | |
| 122 | try expect(math.isNegativeInf(atanh_64(-1))); | |
| 123 | try expect(math.isSignalNan(atanh_64(1.5))); | |
| 124 | try expect(math.isSignalNan(atanh_64(-1.5))); | |
| 125 | try expect(math.isNan(atanh_64(math.nan(f64)))); | |
| 126 | 126 | } |
lib/std/math/big/int_test.zig+211-211| ... | ... | @@ -30,7 +30,7 @@ test "big.int comptime_int set" { |
| 30 | 30 | const result = @as(Limb, s & maxInt(Limb)); |
| 31 | 31 | s >>= @typeInfo(Limb).Int.bits / 2; |
| 32 | 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 | } |
| 36 | 36 | |
| ... | ... | @@ -38,37 +38,37 @@ test "big.int comptime_int set negative" { |
| 38 | 38 | var a = try Managed.initSet(testing.allocator, -10); |
| 39 | 39 | defer a.deinit(); |
| 40 | 40 | |
| 41 | testing.expect(a.limbs[0] == 10); | |
| 42 | testing.expect(a.isPositive() == false); | |
| 41 | try testing.expect(a.limbs[0] == 10); | |
| 42 | try testing.expect(a.isPositive() == false); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | test "big.int int set unaligned small" { |
| 46 | 46 | var a = try Managed.initSet(testing.allocator, @as(u7, 45)); |
| 47 | 47 | defer a.deinit(); |
| 48 | 48 | |
| 49 | testing.expect(a.limbs[0] == 45); | |
| 50 | testing.expect(a.isPositive() == true); | |
| 49 | try testing.expect(a.limbs[0] == 45); | |
| 50 | try testing.expect(a.isPositive() == true); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | test "big.int comptime_int to" { |
| 54 | 54 | var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab); |
| 55 | 55 | defer a.deinit(); |
| 56 | 56 | |
| 57 | testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab); | |
| 57 | try testing.expect((try a.to(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | test "big.int sub-limb to" { |
| 61 | 61 | var a = try Managed.initSet(testing.allocator, 10); |
| 62 | 62 | defer a.deinit(); |
| 63 | 63 | |
| 64 | testing.expect((try a.to(u8)) == 10); | |
| 64 | try testing.expect((try a.to(u8)) == 10); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | test "big.int to target too small error" { |
| 68 | 68 | var a = try Managed.initSet(testing.allocator, 0xffffffff); |
| 69 | 69 | defer a.deinit(); |
| 70 | 70 | |
| 71 | testing.expectError(error.TargetTooSmall, a.to(u8)); | |
| 71 | try testing.expectError(error.TargetTooSmall, a.to(u8)); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "big.int normalize" { |
| ... | ... | @@ -81,22 +81,22 @@ test "big.int normalize" { |
| 81 | 81 | a.limbs[2] = 3; |
| 82 | 82 | a.limbs[3] = 0; |
| 83 | 83 | a.normalize(4); |
| 84 | testing.expect(a.len() == 3); | |
| 84 | try testing.expect(a.len() == 3); | |
| 85 | 85 | |
| 86 | 86 | a.limbs[0] = 1; |
| 87 | 87 | a.limbs[1] = 2; |
| 88 | 88 | a.limbs[2] = 3; |
| 89 | 89 | a.normalize(3); |
| 90 | testing.expect(a.len() == 3); | |
| 90 | try testing.expect(a.len() == 3); | |
| 91 | 91 | |
| 92 | 92 | a.limbs[0] = 0; |
| 93 | 93 | a.limbs[1] = 0; |
| 94 | 94 | a.normalize(2); |
| 95 | testing.expect(a.len() == 1); | |
| 95 | try testing.expect(a.len() == 1); | |
| 96 | 96 | |
| 97 | 97 | a.limbs[0] = 0; |
| 98 | 98 | a.normalize(1); |
| 99 | testing.expect(a.len() == 1); | |
| 99 | try testing.expect(a.len() == 1); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "big.int normalize multi" { |
| ... | ... | @@ -109,24 +109,24 @@ test "big.int normalize multi" { |
| 109 | 109 | a.limbs[2] = 0; |
| 110 | 110 | a.limbs[3] = 0; |
| 111 | 111 | a.normalize(4); |
| 112 | testing.expect(a.len() == 2); | |
| 112 | try testing.expect(a.len() == 2); | |
| 113 | 113 | |
| 114 | 114 | a.limbs[0] = 1; |
| 115 | 115 | a.limbs[1] = 2; |
| 116 | 116 | a.limbs[2] = 3; |
| 117 | 117 | a.normalize(3); |
| 118 | testing.expect(a.len() == 3); | |
| 118 | try testing.expect(a.len() == 3); | |
| 119 | 119 | |
| 120 | 120 | a.limbs[0] = 0; |
| 121 | 121 | a.limbs[1] = 0; |
| 122 | 122 | a.limbs[2] = 0; |
| 123 | 123 | a.limbs[3] = 0; |
| 124 | 124 | a.normalize(4); |
| 125 | testing.expect(a.len() == 1); | |
| 125 | try testing.expect(a.len() == 1); | |
| 126 | 126 | |
| 127 | 127 | a.limbs[0] = 0; |
| 128 | 128 | a.normalize(1); |
| 129 | testing.expect(a.len() == 1); | |
| 129 | try testing.expect(a.len() == 1); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "big.int parity" { |
| ... | ... | @@ -134,12 +134,12 @@ test "big.int parity" { |
| 134 | 134 | defer a.deinit(); |
| 135 | 135 | |
| 136 | 136 | try a.set(0); |
| 137 | testing.expect(a.isEven()); | |
| 138 | testing.expect(!a.isOdd()); | |
| 137 | try testing.expect(a.isEven()); | |
| 138 | try testing.expect(!a.isOdd()); | |
| 139 | 139 | |
| 140 | 140 | try a.set(7); |
| 141 | testing.expect(!a.isEven()); | |
| 142 | testing.expect(a.isOdd()); | |
| 141 | try testing.expect(!a.isEven()); | |
| 142 | try testing.expect(a.isOdd()); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "big.int bitcount + sizeInBaseUpperBound" { |
| ... | ... | @@ -147,27 +147,27 @@ test "big.int bitcount + sizeInBaseUpperBound" { |
| 147 | 147 | defer a.deinit(); |
| 148 | 148 | |
| 149 | 149 | try a.set(0b100); |
| 150 | testing.expect(a.bitCountAbs() == 3); | |
| 151 | testing.expect(a.sizeInBaseUpperBound(2) >= 3); | |
| 152 | testing.expect(a.sizeInBaseUpperBound(10) >= 1); | |
| 150 | try testing.expect(a.bitCountAbs() == 3); | |
| 151 | try testing.expect(a.sizeInBaseUpperBound(2) >= 3); | |
| 152 | try testing.expect(a.sizeInBaseUpperBound(10) >= 1); | |
| 153 | 153 | |
| 154 | 154 | a.negate(); |
| 155 | testing.expect(a.bitCountAbs() == 3); | |
| 156 | testing.expect(a.sizeInBaseUpperBound(2) >= 4); | |
| 157 | testing.expect(a.sizeInBaseUpperBound(10) >= 2); | |
| 155 | try testing.expect(a.bitCountAbs() == 3); | |
| 156 | try testing.expect(a.sizeInBaseUpperBound(2) >= 4); | |
| 157 | try testing.expect(a.sizeInBaseUpperBound(10) >= 2); | |
| 158 | 158 | |
| 159 | 159 | try a.set(0xffffffff); |
| 160 | testing.expect(a.bitCountAbs() == 32); | |
| 161 | testing.expect(a.sizeInBaseUpperBound(2) >= 32); | |
| 162 | testing.expect(a.sizeInBaseUpperBound(10) >= 10); | |
| 160 | try testing.expect(a.bitCountAbs() == 32); | |
| 161 | try testing.expect(a.sizeInBaseUpperBound(2) >= 32); | |
| 162 | try testing.expect(a.sizeInBaseUpperBound(10) >= 10); | |
| 163 | 163 | |
| 164 | 164 | try a.shiftLeft(a, 5000); |
| 165 | testing.expect(a.bitCountAbs() == 5032); | |
| 166 | testing.expect(a.sizeInBaseUpperBound(2) >= 5032); | |
| 165 | try testing.expect(a.bitCountAbs() == 5032); | |
| 166 | try testing.expect(a.sizeInBaseUpperBound(2) >= 5032); | |
| 167 | 167 | a.setSign(false); |
| 168 | 168 | |
| 169 | testing.expect(a.bitCountAbs() == 5032); | |
| 170 | testing.expect(a.sizeInBaseUpperBound(2) >= 5033); | |
| 169 | try testing.expect(a.bitCountAbs() == 5032); | |
| 170 | try testing.expect(a.sizeInBaseUpperBound(2) >= 5033); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | test "big.int bitcount/to" { |
| ... | ... | @@ -175,30 +175,30 @@ test "big.int bitcount/to" { |
| 175 | 175 | defer a.deinit(); |
| 176 | 176 | |
| 177 | 177 | try a.set(0); |
| 178 | testing.expect(a.bitCountTwosComp() == 0); | |
| 178 | try testing.expect(a.bitCountTwosComp() == 0); | |
| 179 | 179 | |
| 180 | testing.expect((try a.to(u0)) == 0); | |
| 181 | testing.expect((try a.to(i0)) == 0); | |
| 180 | try testing.expect((try a.to(u0)) == 0); | |
| 181 | try testing.expect((try a.to(i0)) == 0); | |
| 182 | 182 | |
| 183 | 183 | try a.set(-1); |
| 184 | testing.expect(a.bitCountTwosComp() == 1); | |
| 185 | testing.expect((try a.to(i1)) == -1); | |
| 184 | try testing.expect(a.bitCountTwosComp() == 1); | |
| 185 | try testing.expect((try a.to(i1)) == -1); | |
| 186 | 186 | |
| 187 | 187 | try a.set(-8); |
| 188 | testing.expect(a.bitCountTwosComp() == 4); | |
| 189 | testing.expect((try a.to(i4)) == -8); | |
| 188 | try testing.expect(a.bitCountTwosComp() == 4); | |
| 189 | try testing.expect((try a.to(i4)) == -8); | |
| 190 | 190 | |
| 191 | 191 | try a.set(127); |
| 192 | testing.expect(a.bitCountTwosComp() == 7); | |
| 193 | testing.expect((try a.to(u7)) == 127); | |
| 192 | try testing.expect(a.bitCountTwosComp() == 7); | |
| 193 | try testing.expect((try a.to(u7)) == 127); | |
| 194 | 194 | |
| 195 | 195 | try a.set(-128); |
| 196 | testing.expect(a.bitCountTwosComp() == 8); | |
| 197 | testing.expect((try a.to(i8)) == -128); | |
| 196 | try testing.expect(a.bitCountTwosComp() == 8); | |
| 197 | try testing.expect((try a.to(i8)) == -128); | |
| 198 | 198 | |
| 199 | 199 | try a.set(-129); |
| 200 | testing.expect(a.bitCountTwosComp() == 9); | |
| 201 | testing.expect((try a.to(i9)) == -129); | |
| 200 | try testing.expect(a.bitCountTwosComp() == 9); | |
| 201 | try testing.expect((try a.to(i9)) == -129); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "big.int fits" { |
| ... | ... | @@ -206,27 +206,27 @@ test "big.int fits" { |
| 206 | 206 | defer a.deinit(); |
| 207 | 207 | |
| 208 | 208 | try a.set(0); |
| 209 | testing.expect(a.fits(u0)); | |
| 210 | testing.expect(a.fits(i0)); | |
| 209 | try testing.expect(a.fits(u0)); | |
| 210 | try testing.expect(a.fits(i0)); | |
| 211 | 211 | |
| 212 | 212 | try a.set(255); |
| 213 | testing.expect(!a.fits(u0)); | |
| 214 | testing.expect(!a.fits(u1)); | |
| 215 | testing.expect(!a.fits(i8)); | |
| 216 | testing.expect(a.fits(u8)); | |
| 217 | testing.expect(a.fits(u9)); | |
| 218 | testing.expect(a.fits(i9)); | |
| 213 | try testing.expect(!a.fits(u0)); | |
| 214 | try testing.expect(!a.fits(u1)); | |
| 215 | try testing.expect(!a.fits(i8)); | |
| 216 | try testing.expect(a.fits(u8)); | |
| 217 | try testing.expect(a.fits(u9)); | |
| 218 | try testing.expect(a.fits(i9)); | |
| 219 | 219 | |
| 220 | 220 | try a.set(-128); |
| 221 | testing.expect(!a.fits(i7)); | |
| 222 | testing.expect(a.fits(i8)); | |
| 223 | testing.expect(a.fits(i9)); | |
| 224 | testing.expect(!a.fits(u9)); | |
| 221 | try testing.expect(!a.fits(i7)); | |
| 222 | try testing.expect(a.fits(i8)); | |
| 223 | try testing.expect(a.fits(i9)); | |
| 224 | try testing.expect(!a.fits(u9)); | |
| 225 | 225 | |
| 226 | 226 | try a.set(0x1ffffffffeeeeeeee); |
| 227 | testing.expect(!a.fits(u32)); | |
| 228 | testing.expect(!a.fits(u64)); | |
| 229 | testing.expect(a.fits(u65)); | |
| 227 | try testing.expect(!a.fits(u32)); | |
| 228 | try testing.expect(!a.fits(u64)); | |
| 229 | try testing.expect(a.fits(u65)); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | test "big.int string set" { |
| ... | ... | @@ -234,7 +234,7 @@ test "big.int string set" { |
| 234 | 234 | defer a.deinit(); |
| 235 | 235 | |
| 236 | 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 | } |
| 239 | 239 | |
| 240 | 240 | test "big.int string negative" { |
| ... | ... | @@ -242,7 +242,7 @@ test "big.int string negative" { |
| 242 | 242 | defer a.deinit(); |
| 243 | 243 | |
| 244 | 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 | } |
| 247 | 247 | |
| 248 | 248 | test "big.int string set number with underscores" { |
| ... | ... | @@ -250,7 +250,7 @@ test "big.int string set number with underscores" { |
| 250 | 250 | defer a.deinit(); |
| 251 | 251 | |
| 252 | 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 | } |
| 255 | 255 | |
| 256 | 256 | test "big.int string set case insensitive number" { |
| ... | ... | @@ -258,19 +258,19 @@ test "big.int string set case insensitive number" { |
| 258 | 258 | defer a.deinit(); |
| 259 | 259 | |
| 260 | 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 | } |
| 263 | 263 | |
| 264 | 264 | test "big.int string set bad char error" { |
| 265 | 265 | var a = try Managed.init(testing.allocator); |
| 266 | 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 | } |
| 269 | 269 | |
| 270 | 270 | test "big.int string set bad base error" { |
| 271 | 271 | var a = try Managed.init(testing.allocator); |
| 272 | 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 | } |
| 275 | 275 | |
| 276 | 276 | test "big.int string to" { |
| ... | ... | @@ -281,14 +281,14 @@ test "big.int string to" { |
| 281 | 281 | defer testing.allocator.free(as); |
| 282 | 282 | const es = "120317241209124781241290847124"; |
| 283 | 283 | |
| 284 | testing.expect(mem.eql(u8, as, es)); | |
| 284 | try testing.expect(mem.eql(u8, as, es)); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | test "big.int string to base base error" { |
| 288 | 288 | var a = try Managed.initSet(testing.allocator, 0xffffffff); |
| 289 | 289 | defer a.deinit(); |
| 290 | 290 | |
| 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 | } |
| 293 | 293 | |
| 294 | 294 | test "big.int string to base 2" { |
| ... | ... | @@ -299,7 +299,7 @@ test "big.int string to base 2" { |
| 299 | 299 | defer testing.allocator.free(as); |
| 300 | 300 | const es = "-1011"; |
| 301 | 301 | |
| 302 | testing.expect(mem.eql(u8, as, es)); | |
| 302 | try testing.expect(mem.eql(u8, as, es)); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | test "big.int string to base 16" { |
| ... | ... | @@ -310,7 +310,7 @@ test "big.int string to base 16" { |
| 310 | 310 | defer testing.allocator.free(as); |
| 311 | 311 | const es = "efffffff00000001eeeeeeefaaaaaaab"; |
| 312 | 312 | |
| 313 | testing.expect(mem.eql(u8, as, es)); | |
| 313 | try testing.expect(mem.eql(u8, as, es)); | |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | test "big.int neg string to" { |
| ... | ... | @@ -321,7 +321,7 @@ test "big.int neg string to" { |
| 321 | 321 | defer testing.allocator.free(as); |
| 322 | 322 | const es = "-123907434"; |
| 323 | 323 | |
| 324 | testing.expect(mem.eql(u8, as, es)); | |
| 324 | try testing.expect(mem.eql(u8, as, es)); | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | test "big.int zero string to" { |
| ... | ... | @@ -332,7 +332,7 @@ test "big.int zero string to" { |
| 332 | 332 | defer testing.allocator.free(as); |
| 333 | 333 | const es = "0"; |
| 334 | 334 | |
| 335 | testing.expect(mem.eql(u8, as, es)); | |
| 335 | try testing.expect(mem.eql(u8, as, es)); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | test "big.int clone" { |
| ... | ... | @@ -341,12 +341,12 @@ test "big.int clone" { |
| 341 | 341 | var b = try a.clone(); |
| 342 | 342 | defer b.deinit(); |
| 343 | 343 | |
| 344 | testing.expect((try a.to(u32)) == 1234); | |
| 345 | testing.expect((try b.to(u32)) == 1234); | |
| 344 | try testing.expect((try a.to(u32)) == 1234); | |
| 345 | try testing.expect((try b.to(u32)) == 1234); | |
| 346 | 346 | |
| 347 | 347 | try a.set(77); |
| 348 | testing.expect((try a.to(u32)) == 77); | |
| 349 | testing.expect((try b.to(u32)) == 1234); | |
| 348 | try testing.expect((try a.to(u32)) == 77); | |
| 349 | try testing.expect((try b.to(u32)) == 1234); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | test "big.int swap" { |
| ... | ... | @@ -355,20 +355,20 @@ test "big.int swap" { |
| 355 | 355 | var b = try Managed.initSet(testing.allocator, 5678); |
| 356 | 356 | defer b.deinit(); |
| 357 | 357 | |
| 358 | testing.expect((try a.to(u32)) == 1234); | |
| 359 | testing.expect((try b.to(u32)) == 5678); | |
| 358 | try testing.expect((try a.to(u32)) == 1234); | |
| 359 | try testing.expect((try b.to(u32)) == 5678); | |
| 360 | 360 | |
| 361 | 361 | a.swap(&b); |
| 362 | 362 | |
| 363 | testing.expect((try a.to(u32)) == 5678); | |
| 364 | testing.expect((try b.to(u32)) == 1234); | |
| 363 | try testing.expect((try a.to(u32)) == 5678); | |
| 364 | try testing.expect((try b.to(u32)) == 1234); | |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | test "big.int to negative" { |
| 368 | 368 | var a = try Managed.initSet(testing.allocator, -10); |
| 369 | 369 | defer a.deinit(); |
| 370 | 370 | |
| 371 | testing.expect((try a.to(i32)) == -10); | |
| 371 | try testing.expect((try a.to(i32)) == -10); | |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | test "big.int compare" { |
| ... | ... | @@ -377,8 +377,8 @@ test "big.int compare" { |
| 377 | 377 | var b = try Managed.initSet(testing.allocator, 10); |
| 378 | 378 | defer b.deinit(); |
| 379 | 379 | |
| 380 | testing.expect(a.orderAbs(b) == .gt); | |
| 381 | testing.expect(a.order(b) == .lt); | |
| 380 | try testing.expect(a.orderAbs(b) == .gt); | |
| 381 | try testing.expect(a.order(b) == .lt); | |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | test "big.int compare similar" { |
| ... | ... | @@ -387,8 +387,8 @@ test "big.int compare similar" { |
| 387 | 387 | var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef); |
| 388 | 388 | defer b.deinit(); |
| 389 | 389 | |
| 390 | testing.expect(a.orderAbs(b) == .lt); | |
| 391 | testing.expect(b.orderAbs(a) == .gt); | |
| 390 | try testing.expect(a.orderAbs(b) == .lt); | |
| 391 | try testing.expect(b.orderAbs(a) == .gt); | |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | test "big.int compare different limb size" { |
| ... | ... | @@ -397,8 +397,8 @@ test "big.int compare different limb size" { |
| 397 | 397 | var b = try Managed.initSet(testing.allocator, 1); |
| 398 | 398 | defer b.deinit(); |
| 399 | 399 | |
| 400 | testing.expect(a.orderAbs(b) == .gt); | |
| 401 | testing.expect(b.orderAbs(a) == .lt); | |
| 400 | try testing.expect(a.orderAbs(b) == .gt); | |
| 401 | try testing.expect(b.orderAbs(a) == .lt); | |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | test "big.int compare multi-limb" { |
| ... | ... | @@ -407,8 +407,8 @@ test "big.int compare multi-limb" { |
| 407 | 407 | var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee); |
| 408 | 408 | defer b.deinit(); |
| 409 | 409 | |
| 410 | testing.expect(a.orderAbs(b) == .gt); | |
| 411 | testing.expect(a.order(b) == .lt); | |
| 410 | try testing.expect(a.orderAbs(b) == .gt); | |
| 411 | try testing.expect(a.order(b) == .lt); | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | test "big.int equality" { |
| ... | ... | @@ -417,8 +417,8 @@ test "big.int equality" { |
| 417 | 417 | var b = try Managed.initSet(testing.allocator, -0xffffffff1); |
| 418 | 418 | defer b.deinit(); |
| 419 | 419 | |
| 420 | testing.expect(a.eqAbs(b)); | |
| 421 | testing.expect(!a.eq(b)); | |
| 420 | try testing.expect(a.eqAbs(b)); | |
| 421 | try testing.expect(!a.eq(b)); | |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | test "big.int abs" { |
| ... | ... | @@ -426,10 +426,10 @@ test "big.int abs" { |
| 426 | 426 | defer a.deinit(); |
| 427 | 427 | |
| 428 | 428 | a.abs(); |
| 429 | testing.expect((try a.to(u32)) == 5); | |
| 429 | try testing.expect((try a.to(u32)) == 5); | |
| 430 | 430 | |
| 431 | 431 | a.abs(); |
| 432 | testing.expect((try a.to(u32)) == 5); | |
| 432 | try testing.expect((try a.to(u32)) == 5); | |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | test "big.int negate" { |
| ... | ... | @@ -437,10 +437,10 @@ test "big.int negate" { |
| 437 | 437 | defer a.deinit(); |
| 438 | 438 | |
| 439 | 439 | a.negate(); |
| 440 | testing.expect((try a.to(i32)) == -5); | |
| 440 | try testing.expect((try a.to(i32)) == -5); | |
| 441 | 441 | |
| 442 | 442 | a.negate(); |
| 443 | testing.expect((try a.to(i32)) == 5); | |
| 443 | try testing.expect((try a.to(i32)) == 5); | |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | test "big.int add single-single" { |
| ... | ... | @@ -453,7 +453,7 @@ test "big.int add single-single" { |
| 453 | 453 | defer c.deinit(); |
| 454 | 454 | try c.add(a.toConst(), b.toConst()); |
| 455 | 455 | |
| 456 | testing.expect((try c.to(u32)) == 55); | |
| 456 | try testing.expect((try c.to(u32)) == 55); | |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | test "big.int add multi-single" { |
| ... | ... | @@ -466,10 +466,10 @@ test "big.int add multi-single" { |
| 466 | 466 | defer c.deinit(); |
| 467 | 467 | |
| 468 | 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); | |
| 470 | 470 | |
| 471 | 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 | } |
| 474 | 474 | |
| 475 | 475 | test "big.int add multi-multi" { |
| ... | ... | @@ -484,7 +484,7 @@ test "big.int add multi-multi" { |
| 484 | 484 | defer c.deinit(); |
| 485 | 485 | try c.add(a.toConst(), b.toConst()); |
| 486 | 486 | |
| 487 | testing.expect((try c.to(u128)) == op1 + op2); | |
| 487 | try testing.expect((try c.to(u128)) == op1 + op2); | |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | test "big.int add zero-zero" { |
| ... | ... | @@ -497,7 +497,7 @@ test "big.int add zero-zero" { |
| 497 | 497 | defer c.deinit(); |
| 498 | 498 | try c.add(a.toConst(), b.toConst()); |
| 499 | 499 | |
| 500 | testing.expect((try c.to(u32)) == 0); | |
| 500 | try testing.expect((try c.to(u32)) == 0); | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | test "big.int add alias multi-limb nonzero-zero" { |
| ... | ... | @@ -509,7 +509,7 @@ test "big.int add alias multi-limb nonzero-zero" { |
| 509 | 509 | |
| 510 | 510 | try a.add(a.toConst(), b.toConst()); |
| 511 | 511 | |
| 512 | testing.expect((try a.to(u128)) == op1); | |
| 512 | try testing.expect((try a.to(u128)) == op1); | |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | test "big.int add sign" { |
| ... | ... | @@ -526,16 +526,16 @@ test "big.int add sign" { |
| 526 | 526 | defer neg_two.deinit(); |
| 527 | 527 | |
| 528 | 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); | |
| 530 | 530 | |
| 531 | 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); | |
| 533 | 533 | |
| 534 | 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); | |
| 536 | 536 | |
| 537 | 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 | } |
| 540 | 540 | |
| 541 | 541 | test "big.int sub single-single" { |
| ... | ... | @@ -548,7 +548,7 @@ test "big.int sub single-single" { |
| 548 | 548 | defer c.deinit(); |
| 549 | 549 | try c.sub(a.toConst(), b.toConst()); |
| 550 | 550 | |
| 551 | testing.expect((try c.to(u32)) == 45); | |
| 551 | try testing.expect((try c.to(u32)) == 45); | |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | test "big.int sub multi-single" { |
| ... | ... | @@ -561,7 +561,7 @@ test "big.int sub multi-single" { |
| 561 | 561 | defer c.deinit(); |
| 562 | 562 | try c.sub(a.toConst(), b.toConst()); |
| 563 | 563 | |
| 564 | testing.expect((try c.to(Limb)) == maxInt(Limb)); | |
| 564 | try testing.expect((try c.to(Limb)) == maxInt(Limb)); | |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | test "big.int sub multi-multi" { |
| ... | ... | @@ -577,7 +577,7 @@ test "big.int sub multi-multi" { |
| 577 | 577 | defer c.deinit(); |
| 578 | 578 | try c.sub(a.toConst(), b.toConst()); |
| 579 | 579 | |
| 580 | testing.expect((try c.to(u128)) == op1 - op2); | |
| 580 | try testing.expect((try c.to(u128)) == op1 - op2); | |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | test "big.int sub equal" { |
| ... | ... | @@ -590,7 +590,7 @@ test "big.int sub equal" { |
| 590 | 590 | defer c.deinit(); |
| 591 | 591 | try c.sub(a.toConst(), b.toConst()); |
| 592 | 592 | |
| 593 | testing.expect((try c.to(u32)) == 0); | |
| 593 | try testing.expect((try c.to(u32)) == 0); | |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | test "big.int sub sign" { |
| ... | ... | @@ -607,19 +607,19 @@ test "big.int sub sign" { |
| 607 | 607 | defer neg_two.deinit(); |
| 608 | 608 | |
| 609 | 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); | |
| 611 | 611 | |
| 612 | 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); | |
| 614 | 614 | |
| 615 | 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); | |
| 617 | 617 | |
| 618 | 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); | |
| 620 | 620 | |
| 621 | 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 | } |
| 624 | 624 | |
| 625 | 625 | test "big.int mul single-single" { |
| ... | ... | @@ -632,7 +632,7 @@ test "big.int mul single-single" { |
| 632 | 632 | defer c.deinit(); |
| 633 | 633 | try c.mul(a.toConst(), b.toConst()); |
| 634 | 634 | |
| 635 | testing.expect((try c.to(u64)) == 250); | |
| 635 | try testing.expect((try c.to(u64)) == 250); | |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | test "big.int mul multi-single" { |
| ... | ... | @@ -645,7 +645,7 @@ test "big.int mul multi-single" { |
| 645 | 645 | defer c.deinit(); |
| 646 | 646 | try c.mul(a.toConst(), b.toConst()); |
| 647 | 647 | |
| 648 | testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 648 | try testing.expect((try c.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | test "big.int mul multi-multi" { |
| ... | ... | @@ -660,7 +660,7 @@ test "big.int mul multi-multi" { |
| 660 | 660 | defer c.deinit(); |
| 661 | 661 | try c.mul(a.toConst(), b.toConst()); |
| 662 | 662 | |
| 663 | testing.expect((try c.to(u256)) == op1 * op2); | |
| 663 | try testing.expect((try c.to(u256)) == op1 * op2); | |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | test "big.int mul alias r with a" { |
| ... | ... | @@ -671,7 +671,7 @@ test "big.int mul alias r with a" { |
| 671 | 671 | |
| 672 | 672 | try a.mul(a.toConst(), b.toConst()); |
| 673 | 673 | |
| 674 | testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 674 | try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | test "big.int mul alias r with b" { |
| ... | ... | @@ -682,7 +682,7 @@ test "big.int mul alias r with b" { |
| 682 | 682 | |
| 683 | 683 | try a.mul(b.toConst(), a.toConst()); |
| 684 | 684 | |
| 685 | testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 685 | try testing.expect((try a.to(DoubleLimb)) == 2 * maxInt(Limb)); | |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | test "big.int mul alias r with a and b" { |
| ... | ... | @@ -691,7 +691,7 @@ test "big.int mul alias r with a and b" { |
| 691 | 691 | |
| 692 | 692 | try a.mul(a.toConst(), a.toConst()); |
| 693 | 693 | |
| 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 | } |
| 696 | 696 | |
| 697 | 697 | test "big.int mul a*0" { |
| ... | ... | @@ -704,7 +704,7 @@ test "big.int mul a*0" { |
| 704 | 704 | defer c.deinit(); |
| 705 | 705 | try c.mul(a.toConst(), b.toConst()); |
| 706 | 706 | |
| 707 | testing.expect((try c.to(u32)) == 0); | |
| 707 | try testing.expect((try c.to(u32)) == 0); | |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | test "big.int mul 0*0" { |
| ... | ... | @@ -717,7 +717,7 @@ test "big.int mul 0*0" { |
| 717 | 717 | defer c.deinit(); |
| 718 | 718 | try c.mul(a.toConst(), b.toConst()); |
| 719 | 719 | |
| 720 | testing.expect((try c.to(u32)) == 0); | |
| 720 | try testing.expect((try c.to(u32)) == 0); | |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | test "big.int mul large" { |
| ... | ... | @@ -738,7 +738,7 @@ test "big.int mul large" { |
| 738 | 738 | try b.mul(a.toConst(), a.toConst()); |
| 739 | 739 | try c.sqr(a.toConst()); |
| 740 | 740 | |
| 741 | testing.expect(b.eq(c)); | |
| 741 | try testing.expect(b.eq(c)); | |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | test "big.int div single-single no rem" { |
| ... | ... | @@ -753,8 +753,8 @@ test "big.int div single-single no rem" { |
| 753 | 753 | defer r.deinit(); |
| 754 | 754 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 755 | 755 | |
| 756 | testing.expect((try q.to(u32)) == 10); | |
| 757 | testing.expect((try r.to(u32)) == 0); | |
| 756 | try testing.expect((try q.to(u32)) == 10); | |
| 757 | try testing.expect((try r.to(u32)) == 0); | |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | test "big.int div single-single with rem" { |
| ... | ... | @@ -769,8 +769,8 @@ test "big.int div single-single with rem" { |
| 769 | 769 | defer r.deinit(); |
| 770 | 770 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 771 | 771 | |
| 772 | testing.expect((try q.to(u32)) == 9); | |
| 773 | testing.expect((try r.to(u32)) == 4); | |
| 772 | try testing.expect((try q.to(u32)) == 9); | |
| 773 | try testing.expect((try r.to(u32)) == 4); | |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | test "big.int div multi-single no rem" { |
| ... | ... | @@ -788,8 +788,8 @@ test "big.int div multi-single no rem" { |
| 788 | 788 | defer r.deinit(); |
| 789 | 789 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 790 | 790 | |
| 791 | testing.expect((try q.to(u64)) == op1 / op2); | |
| 792 | testing.expect((try r.to(u64)) == 0); | |
| 791 | try testing.expect((try q.to(u64)) == op1 / op2); | |
| 792 | try testing.expect((try r.to(u64)) == 0); | |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | test "big.int div multi-single with rem" { |
| ... | ... | @@ -807,8 +807,8 @@ test "big.int div multi-single with rem" { |
| 807 | 807 | defer r.deinit(); |
| 808 | 808 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 809 | 809 | |
| 810 | testing.expect((try q.to(u64)) == op1 / op2); | |
| 811 | testing.expect((try r.to(u64)) == 3); | |
| 810 | try testing.expect((try q.to(u64)) == op1 / op2); | |
| 811 | try testing.expect((try r.to(u64)) == 3); | |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | test "big.int div multi>2-single" { |
| ... | ... | @@ -826,8 +826,8 @@ test "big.int div multi>2-single" { |
| 826 | 826 | defer r.deinit(); |
| 827 | 827 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 828 | 828 | |
| 829 | testing.expect((try q.to(u128)) == op1 / op2); | |
| 830 | testing.expect((try r.to(u32)) == 0x3e4e); | |
| 829 | try testing.expect((try q.to(u128)) == op1 / op2); | |
| 830 | try testing.expect((try r.to(u32)) == 0x3e4e); | |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | test "big.int div single-single q < r" { |
| ... | ... | @@ -842,8 +842,8 @@ test "big.int div single-single q < r" { |
| 842 | 842 | defer r.deinit(); |
| 843 | 843 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 844 | 844 | |
| 845 | testing.expect((try q.to(u64)) == 0); | |
| 846 | testing.expect((try r.to(u64)) == 0x0078f432); | |
| 845 | try testing.expect((try q.to(u64)) == 0); | |
| 846 | try testing.expect((try r.to(u64)) == 0x0078f432); | |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | test "big.int div single-single q == r" { |
| ... | ... | @@ -858,8 +858,8 @@ test "big.int div single-single q == r" { |
| 858 | 858 | defer r.deinit(); |
| 859 | 859 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 860 | 860 | |
| 861 | testing.expect((try q.to(u64)) == 1); | |
| 862 | testing.expect((try r.to(u64)) == 0); | |
| 861 | try testing.expect((try q.to(u64)) == 1); | |
| 862 | try testing.expect((try r.to(u64)) == 0); | |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | test "big.int div q=0 alias" { |
| ... | ... | @@ -870,8 +870,8 @@ test "big.int div q=0 alias" { |
| 870 | 870 | |
| 871 | 871 | try Managed.divTrunc(&a, &b, a.toConst(), b.toConst()); |
| 872 | 872 | |
| 873 | testing.expect((try a.to(u64)) == 0); | |
| 874 | testing.expect((try b.to(u64)) == 3); | |
| 873 | try testing.expect((try a.to(u64)) == 0); | |
| 874 | try testing.expect((try b.to(u64)) == 3); | |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | test "big.int div multi-multi q < r" { |
| ... | ... | @@ -888,8 +888,8 @@ test "big.int div multi-multi q < r" { |
| 888 | 888 | defer r.deinit(); |
| 889 | 889 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 890 | 890 | |
| 891 | testing.expect((try q.to(u128)) == 0); | |
| 892 | testing.expect((try r.to(u128)) == op1); | |
| 891 | try testing.expect((try q.to(u128)) == 0); | |
| 892 | try testing.expect((try r.to(u128)) == op1); | |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | test "big.int div trunc single-single +/+" { |
| ... | ... | @@ -912,8 +912,8 @@ test "big.int div trunc single-single +/+" { |
| 912 | 912 | const eq = @divTrunc(u, v); |
| 913 | 913 | const er = @mod(u, v); |
| 914 | 914 | |
| 915 | testing.expect((try q.to(i32)) == eq); | |
| 916 | testing.expect((try r.to(i32)) == er); | |
| 915 | try testing.expect((try q.to(i32)) == eq); | |
| 916 | try testing.expect((try r.to(i32)) == er); | |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | test "big.int div trunc single-single -/+" { |
| ... | ... | @@ -936,8 +936,8 @@ test "big.int div trunc single-single -/+" { |
| 936 | 936 | const eq = -1; |
| 937 | 937 | const er = -2; |
| 938 | 938 | |
| 939 | testing.expect((try q.to(i32)) == eq); | |
| 940 | testing.expect((try r.to(i32)) == er); | |
| 939 | try testing.expect((try q.to(i32)) == eq); | |
| 940 | try testing.expect((try r.to(i32)) == er); | |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | test "big.int div trunc single-single +/-" { |
| ... | ... | @@ -960,8 +960,8 @@ test "big.int div trunc single-single +/-" { |
| 960 | 960 | const eq = -1; |
| 961 | 961 | const er = 2; |
| 962 | 962 | |
| 963 | testing.expect((try q.to(i32)) == eq); | |
| 964 | testing.expect((try r.to(i32)) == er); | |
| 963 | try testing.expect((try q.to(i32)) == eq); | |
| 964 | try testing.expect((try r.to(i32)) == er); | |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | test "big.int div trunc single-single -/-" { |
| ... | ... | @@ -984,8 +984,8 @@ test "big.int div trunc single-single -/-" { |
| 984 | 984 | const eq = 1; |
| 985 | 985 | const er = -2; |
| 986 | 986 | |
| 987 | testing.expect((try q.to(i32)) == eq); | |
| 988 | testing.expect((try r.to(i32)) == er); | |
| 987 | try testing.expect((try q.to(i32)) == eq); | |
| 988 | try testing.expect((try r.to(i32)) == er); | |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | test "big.int div floor single-single +/+" { |
| ... | ... | @@ -1008,8 +1008,8 @@ test "big.int div floor single-single +/+" { |
| 1008 | 1008 | const eq = 1; |
| 1009 | 1009 | const er = 2; |
| 1010 | 1010 | |
| 1011 | testing.expect((try q.to(i32)) == eq); | |
| 1012 | testing.expect((try r.to(i32)) == er); | |
| 1011 | try testing.expect((try q.to(i32)) == eq); | |
| 1012 | try testing.expect((try r.to(i32)) == er); | |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | test "big.int div floor single-single -/+" { |
| ... | ... | @@ -1032,8 +1032,8 @@ test "big.int div floor single-single -/+" { |
| 1032 | 1032 | const eq = -2; |
| 1033 | 1033 | const er = 1; |
| 1034 | 1034 | |
| 1035 | testing.expect((try q.to(i32)) == eq); | |
| 1036 | testing.expect((try r.to(i32)) == er); | |
| 1035 | try testing.expect((try q.to(i32)) == eq); | |
| 1036 | try testing.expect((try r.to(i32)) == er); | |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | test "big.int div floor single-single +/-" { |
| ... | ... | @@ -1056,8 +1056,8 @@ test "big.int div floor single-single +/-" { |
| 1056 | 1056 | const eq = -2; |
| 1057 | 1057 | const er = -1; |
| 1058 | 1058 | |
| 1059 | testing.expect((try q.to(i32)) == eq); | |
| 1060 | testing.expect((try r.to(i32)) == er); | |
| 1059 | try testing.expect((try q.to(i32)) == eq); | |
| 1060 | try testing.expect((try r.to(i32)) == er); | |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | 1063 | test "big.int div floor single-single -/-" { |
| ... | ... | @@ -1080,8 +1080,8 @@ test "big.int div floor single-single -/-" { |
| 1080 | 1080 | const eq = 1; |
| 1081 | 1081 | const er = -2; |
| 1082 | 1082 | |
| 1083 | testing.expect((try q.to(i32)) == eq); | |
| 1084 | testing.expect((try r.to(i32)) == er); | |
| 1083 | try testing.expect((try q.to(i32)) == eq); | |
| 1084 | try testing.expect((try r.to(i32)) == er); | |
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | test "big.int div multi-multi with rem" { |
| ... | ... | @@ -1096,8 +1096,8 @@ test "big.int div multi-multi with rem" { |
| 1096 | 1096 | defer r.deinit(); |
| 1097 | 1097 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1098 | 1098 | |
| 1099 | testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1100 | testing.expect((try r.to(u128)) == 0x28de0acacd806823638); | |
| 1099 | try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1100 | try testing.expect((try r.to(u128)) == 0x28de0acacd806823638); | |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | test "big.int div multi-multi no rem" { |
| ... | ... | @@ -1112,8 +1112,8 @@ test "big.int div multi-multi no rem" { |
| 1112 | 1112 | defer r.deinit(); |
| 1113 | 1113 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1114 | 1114 | |
| 1115 | testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1116 | testing.expect((try r.to(u128)) == 0); | |
| 1115 | try testing.expect((try q.to(u128)) == 0xe38f38e39161aaabd03f0f1b); | |
| 1116 | try testing.expect((try r.to(u128)) == 0); | |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | test "big.int div multi-multi (2 branch)" { |
| ... | ... | @@ -1128,8 +1128,8 @@ test "big.int div multi-multi (2 branch)" { |
| 1128 | 1128 | defer r.deinit(); |
| 1129 | 1129 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1130 | 1130 | |
| 1131 | testing.expect((try q.to(u128)) == 0x10000000000000000); | |
| 1132 | testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111); | |
| 1131 | try testing.expect((try q.to(u128)) == 0x10000000000000000); | |
| 1132 | try testing.expect((try r.to(u128)) == 0x44444443444444431111111111111111); | |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | 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 | 1144 | defer r.deinit(); |
| 1145 | 1145 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1146 | 1146 | |
| 1147 | testing.expect((try q.to(u128)) == 0xfffffffffffffffffff); | |
| 1148 | testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282); | |
| 1147 | try testing.expect((try q.to(u128)) == 0xfffffffffffffffffff); | |
| 1148 | try testing.expect((try r.to(u256)) == 0x1111111111111111111110b12222222222222222282); | |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | test "big.int div multi-single zero-limb trailing" { |
| ... | ... | @@ -1162,8 +1162,8 @@ test "big.int div multi-single zero-limb trailing" { |
| 1162 | 1162 | |
| 1163 | 1163 | var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000); |
| 1164 | 1164 | defer expected.deinit(); |
| 1165 | testing.expect(q.eq(expected)); | |
| 1166 | testing.expect(r.eqZero()); | |
| 1165 | try testing.expect(q.eq(expected)); | |
| 1166 | try testing.expect(r.eqZero()); | |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | 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 | 1178 | defer r.deinit(); |
| 1179 | 1179 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1180 | 1180 | |
| 1181 | testing.expect((try q.to(u128)) == 0x10000000000000000); | |
| 1181 | try testing.expect((try q.to(u128)) == 0x10000000000000000); | |
| 1182 | 1182 | |
| 1183 | 1183 | const rs = try r.toString(testing.allocator, 16, false); |
| 1184 | 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 | } |
| 1187 | 1187 | |
| 1188 | 1188 | test "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 | 1197 | defer r.deinit(); |
| 1198 | 1198 | try Managed.divTrunc(&q, &r, a.toConst(), b.toConst()); |
| 1199 | 1199 | |
| 1200 | testing.expect((try q.to(u128)) == 0x1); | |
| 1200 | try testing.expect((try q.to(u128)) == 0x1); | |
| 1201 | 1201 | |
| 1202 | 1202 | const rs = try r.toString(testing.allocator, 16, false); |
| 1203 | 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 | } |
| 1206 | 1206 | |
| 1207 | 1207 | test "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 | 1218 | |
| 1219 | 1219 | const qs = try q.toString(testing.allocator, 16, false); |
| 1220 | 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")); | |
| 1222 | 1222 | |
| 1223 | 1223 | const rs = try r.toString(testing.allocator, 16, false); |
| 1224 | 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 | } |
| 1227 | 1227 | |
| 1228 | 1228 | test "big.int div multi-multi fuzz case #1" { |
| ... | ... | @@ -1242,11 +1242,11 @@ test "big.int div multi-multi fuzz case #1" { |
| 1242 | 1242 | |
| 1243 | 1243 | const qs = try q.toString(testing.allocator, 16, false); |
| 1244 | 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")); | |
| 1246 | 1246 | |
| 1247 | 1247 | const rs = try r.toString(testing.allocator, 16, false); |
| 1248 | 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 | } |
| 1251 | 1251 | |
| 1252 | 1252 | test "big.int div multi-multi fuzz case #2" { |
| ... | ... | @@ -1266,11 +1266,11 @@ test "big.int div multi-multi fuzz case #2" { |
| 1266 | 1266 | |
| 1267 | 1267 | const qs = try q.toString(testing.allocator, 16, false); |
| 1268 | 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")); | |
| 1270 | 1270 | |
| 1271 | 1271 | const rs = try r.toString(testing.allocator, 16, false); |
| 1272 | 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 | } |
| 1275 | 1275 | |
| 1276 | 1276 | test "big.int shift-right single" { |
| ... | ... | @@ -1278,7 +1278,7 @@ test "big.int shift-right single" { |
| 1278 | 1278 | defer a.deinit(); |
| 1279 | 1279 | try a.shiftRight(a, 16); |
| 1280 | 1280 | |
| 1281 | testing.expect((try a.to(u32)) == 0xffff); | |
| 1281 | try testing.expect((try a.to(u32)) == 0xffff); | |
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | test "big.int shift-right multi" { |
| ... | ... | @@ -1286,13 +1286,13 @@ test "big.int shift-right multi" { |
| 1286 | 1286 | defer a.deinit(); |
| 1287 | 1287 | try a.shiftRight(a, 67); |
| 1288 | 1288 | |
| 1289 | testing.expect((try a.to(u64)) == 0x1fffe0001dddc222); | |
| 1289 | try testing.expect((try a.to(u64)) == 0x1fffe0001dddc222); | |
| 1290 | 1290 | |
| 1291 | 1291 | try a.set(0xffff0000eeee1111dddd2222cccc3333); |
| 1292 | 1292 | try a.shiftRight(a, 63); |
| 1293 | 1293 | try a.shiftRight(a, 63); |
| 1294 | 1294 | try a.shiftRight(a, 2); |
| 1295 | testing.expect(a.eqZero()); | |
| 1295 | try testing.expect(a.eqZero()); | |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | test "big.int shift-left single" { |
| ... | ... | @@ -1300,7 +1300,7 @@ test "big.int shift-left single" { |
| 1300 | 1300 | defer a.deinit(); |
| 1301 | 1301 | try a.shiftLeft(a, 16); |
| 1302 | 1302 | |
| 1303 | testing.expect((try a.to(u64)) == 0xffff0000); | |
| 1303 | try testing.expect((try a.to(u64)) == 0xffff0000); | |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | test "big.int shift-left multi" { |
| ... | ... | @@ -1308,7 +1308,7 @@ test "big.int shift-left multi" { |
| 1308 | 1308 | defer a.deinit(); |
| 1309 | 1309 | try a.shiftLeft(a, 67); |
| 1310 | 1310 | |
| 1311 | testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000); | |
| 1311 | try testing.expect((try a.to(u128)) == 0xffff0000eeee11100000000000000000); | |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | test "big.int shift-right negative" { |
| ... | ... | @@ -1318,12 +1318,12 @@ test "big.int shift-right negative" { |
| 1318 | 1318 | var arg = try Managed.initSet(testing.allocator, -20); |
| 1319 | 1319 | defer arg.deinit(); |
| 1320 | 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); | |
| 1322 | 1322 | |
| 1323 | 1323 | var arg2 = try Managed.initSet(testing.allocator, -5); |
| 1324 | 1324 | defer arg2.deinit(); |
| 1325 | 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 | } |
| 1328 | 1328 | |
| 1329 | 1329 | test "big.int shift-left negative" { |
| ... | ... | @@ -1333,7 +1333,7 @@ test "big.int shift-left negative" { |
| 1333 | 1333 | var arg = try Managed.initSet(testing.allocator, -10); |
| 1334 | 1334 | defer arg.deinit(); |
| 1335 | 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 | } |
| 1338 | 1338 | |
| 1339 | 1339 | test "big.int bitwise and simple" { |
| ... | ... | @@ -1344,7 +1344,7 @@ test "big.int bitwise and simple" { |
| 1344 | 1344 | |
| 1345 | 1345 | try a.bitAnd(a, b); |
| 1346 | 1346 | |
| 1347 | testing.expect((try a.to(u64)) == 0xeeeeeeee00000000); | |
| 1347 | try testing.expect((try a.to(u64)) == 0xeeeeeeee00000000); | |
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | 1350 | test "big.int bitwise and multi-limb" { |
| ... | ... | @@ -1355,7 +1355,7 @@ test "big.int bitwise and multi-limb" { |
| 1355 | 1355 | |
| 1356 | 1356 | try a.bitAnd(a, b); |
| 1357 | 1357 | |
| 1358 | testing.expect((try a.to(u128)) == 0); | |
| 1358 | try testing.expect((try a.to(u128)) == 0); | |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | test "big.int bitwise xor simple" { |
| ... | ... | @@ -1366,7 +1366,7 @@ test "big.int bitwise xor simple" { |
| 1366 | 1366 | |
| 1367 | 1367 | try a.bitXor(a, b); |
| 1368 | 1368 | |
| 1369 | testing.expect((try a.to(u64)) == 0x1111111133333333); | |
| 1369 | try testing.expect((try a.to(u64)) == 0x1111111133333333); | |
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | test "big.int bitwise xor multi-limb" { |
| ... | ... | @@ -1377,7 +1377,7 @@ test "big.int bitwise xor multi-limb" { |
| 1377 | 1377 | |
| 1378 | 1378 | try a.bitXor(a, b); |
| 1379 | 1379 | |
| 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 | } |
| 1382 | 1382 | |
| 1383 | 1383 | test "big.int bitwise or simple" { |
| ... | ... | @@ -1388,7 +1388,7 @@ test "big.int bitwise or simple" { |
| 1388 | 1388 | |
| 1389 | 1389 | try a.bitOr(a, b); |
| 1390 | 1390 | |
| 1391 | testing.expect((try a.to(u64)) == 0xffffffff33333333); | |
| 1391 | try testing.expect((try a.to(u64)) == 0xffffffff33333333); | |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | test "big.int bitwise or multi-limb" { |
| ... | ... | @@ -1400,7 +1400,7 @@ test "big.int bitwise or multi-limb" { |
| 1400 | 1400 | try a.bitOr(a, b); |
| 1401 | 1401 | |
| 1402 | 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 | } |
| 1405 | 1405 | |
| 1406 | 1406 | test "big.int var args" { |
| ... | ... | @@ -1410,15 +1410,15 @@ test "big.int var args" { |
| 1410 | 1410 | var b = try Managed.initSet(testing.allocator, 6); |
| 1411 | 1411 | defer b.deinit(); |
| 1412 | 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); | |
| 1414 | 1414 | |
| 1415 | 1415 | var c = try Managed.initSet(testing.allocator, 11); |
| 1416 | 1416 | defer c.deinit(); |
| 1417 | testing.expect(a.order(c) == .eq); | |
| 1417 | try testing.expect(a.order(c) == .eq); | |
| 1418 | 1418 | |
| 1419 | 1419 | var d = try Managed.initSet(testing.allocator, 14); |
| 1420 | 1420 | defer d.deinit(); |
| 1421 | testing.expect(a.order(d) != .gt); | |
| 1421 | try testing.expect(a.order(d) != .gt); | |
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | test "big.int gcd non-one small" { |
| ... | ... | @@ -1431,7 +1431,7 @@ test "big.int gcd non-one small" { |
| 1431 | 1431 | |
| 1432 | 1432 | try r.gcd(a, b); |
| 1433 | 1433 | |
| 1434 | testing.expect((try r.to(u32)) == 1); | |
| 1434 | try testing.expect((try r.to(u32)) == 1); | |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | test "big.int gcd non-one small" { |
| ... | ... | @@ -1444,7 +1444,7 @@ test "big.int gcd non-one small" { |
| 1444 | 1444 | |
| 1445 | 1445 | try r.gcd(a, b); |
| 1446 | 1446 | |
| 1447 | testing.expect((try r.to(u32)) == 38); | |
| 1447 | try testing.expect((try r.to(u32)) == 38); | |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | test "big.int gcd non-one large" { |
| ... | ... | @@ -1457,7 +1457,7 @@ test "big.int gcd non-one large" { |
| 1457 | 1457 | |
| 1458 | 1458 | try r.gcd(a, b); |
| 1459 | 1459 | |
| 1460 | testing.expect((try r.to(u32)) == 4369); | |
| 1460 | try testing.expect((try r.to(u32)) == 4369); | |
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | test "big.int gcd large multi-limb result" { |
| ... | ... | @@ -1471,7 +1471,7 @@ test "big.int gcd large multi-limb result" { |
| 1471 | 1471 | try r.gcd(a, b); |
| 1472 | 1472 | |
| 1473 | 1473 | const answer = (try r.to(u256)); |
| 1474 | testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1); | |
| 1474 | try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1); | |
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | test "big.int gcd one large" { |
| ... | ... | @@ -1484,7 +1484,7 @@ test "big.int gcd one large" { |
| 1484 | 1484 | |
| 1485 | 1485 | try r.gcd(a, b); |
| 1486 | 1486 | |
| 1487 | testing.expect((try r.to(u64)) == 1); | |
| 1487 | try testing.expect((try r.to(u64)) == 1); | |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | test "big.int mutable to managed" { |
| ... | ... | @@ -1495,7 +1495,7 @@ test "big.int mutable to managed" { |
| 1495 | 1495 | var a = Mutable.init(limbs_buf, 0xdeadbeef); |
| 1496 | 1496 | var a_managed = a.toManaged(allocator); |
| 1497 | 1497 | |
| 1498 | testing.expect(a.toConst().eq(a_managed.toConst())); | |
| 1498 | try testing.expect(a.toConst().eq(a_managed.toConst())); | |
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | test "big.int const to managed" { |
| ... | ... | @@ -1505,7 +1505,7 @@ test "big.int const to managed" { |
| 1505 | 1505 | var b = try a.toConst().toManaged(testing.allocator); |
| 1506 | 1506 | defer b.deinit(); |
| 1507 | 1507 | |
| 1508 | testing.expect(a.toConst().eq(b.toConst())); | |
| 1508 | try testing.expect(a.toConst().eq(b.toConst())); | |
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | test "big.int pow" { |
| ... | ... | @@ -1514,10 +1514,10 @@ test "big.int pow" { |
| 1514 | 1514 | defer a.deinit(); |
| 1515 | 1515 | |
| 1516 | 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)); | |
| 1518 | 1518 | |
| 1519 | 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 | 1523 | var a = try Managed.initSet(testing.allocator, 10); |
| ... | ... | @@ -1531,11 +1531,11 @@ test "big.int pow" { |
| 1531 | 1531 | // y and a are aliased |
| 1532 | 1532 | try a.pow(a.toConst(), 123); |
| 1533 | 1533 | |
| 1534 | testing.expect(a.eq(y)); | |
| 1534 | try testing.expect(a.eq(y)); | |
| 1535 | 1535 | |
| 1536 | 1536 | const ys = try y.toString(testing.allocator, 16, false); |
| 1537 | 1537 | defer testing.allocator.free(ys); |
| 1538 | testing.expectEqualSlices( | |
| 1538 | try testing.expectEqualSlices( | |
| 1539 | 1539 | u8, |
| 1540 | 1540 | "183425a5f872f126e00a5ad62c839075cd6846c6fb0230887c7ad7a9dc530fcb" ++ |
| 1541 | 1541 | "4933f60e8000000000000000000000000000000", |
| ... | ... | @@ -1548,17 +1548,17 @@ test "big.int pow" { |
| 1548 | 1548 | defer a.deinit(); |
| 1549 | 1549 | |
| 1550 | 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)); | |
| 1552 | 1552 | |
| 1553 | 1553 | try a.set(1); |
| 1554 | 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 | 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 | 1558 | try a.set(-1); |
| 1559 | 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 | 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 | 473 | }; |
| 474 | 474 | |
| 475 | 475 | fn extractLowBits(a: Int, comptime T: type) T { |
| 476 | testing.expect(@typeInfo(T) == .Int); | |
| 476 | debug.assert(@typeInfo(T) == .Int); | |
| 477 | 477 | |
| 478 | 478 | const t_bits = @typeInfo(T).Int.bits; |
| 479 | 479 | const limb_bits = @typeInfo(Limb).Int.bits; |
| ... | ... | @@ -498,19 +498,19 @@ test "big.rational extractLowBits" { |
| 498 | 498 | defer a.deinit(); |
| 499 | 499 | |
| 500 | 500 | const a1 = extractLowBits(a, u8); |
| 501 | testing.expect(a1 == 0x21); | |
| 501 | try testing.expect(a1 == 0x21); | |
| 502 | 502 | |
| 503 | 503 | const a2 = extractLowBits(a, u16); |
| 504 | testing.expect(a2 == 0x4321); | |
| 504 | try testing.expect(a2 == 0x4321); | |
| 505 | 505 | |
| 506 | 506 | const a3 = extractLowBits(a, u32); |
| 507 | testing.expect(a3 == 0x87654321); | |
| 507 | try testing.expect(a3 == 0x87654321); | |
| 508 | 508 | |
| 509 | 509 | const a4 = extractLowBits(a, u64); |
| 510 | testing.expect(a4 == 0x1234567887654321); | |
| 510 | try testing.expect(a4 == 0x1234567887654321); | |
| 511 | 511 | |
| 512 | 512 | const a5 = extractLowBits(a, u128); |
| 513 | testing.expect(a5 == 0x11112222333344441234567887654321); | |
| 513 | try testing.expect(a5 == 0x11112222333344441234567887654321); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | test "big.rational set" { |
| ... | ... | @@ -518,28 +518,28 @@ test "big.rational set" { |
| 518 | 518 | defer a.deinit(); |
| 519 | 519 | |
| 520 | 520 | try a.setInt(5); |
| 521 | testing.expect((try a.p.to(u32)) == 5); | |
| 522 | testing.expect((try a.q.to(u32)) == 1); | |
| 521 | try testing.expect((try a.p.to(u32)) == 5); | |
| 522 | try testing.expect((try a.q.to(u32)) == 1); | |
| 523 | 523 | |
| 524 | 524 | try a.setRatio(7, 3); |
| 525 | testing.expect((try a.p.to(u32)) == 7); | |
| 526 | testing.expect((try a.q.to(u32)) == 3); | |
| 525 | try testing.expect((try a.p.to(u32)) == 7); | |
| 526 | try testing.expect((try a.q.to(u32)) == 3); | |
| 527 | 527 | |
| 528 | 528 | try a.setRatio(9, 3); |
| 529 | testing.expect((try a.p.to(i32)) == 3); | |
| 530 | testing.expect((try a.q.to(i32)) == 1); | |
| 529 | try testing.expect((try a.p.to(i32)) == 3); | |
| 530 | try testing.expect((try a.q.to(i32)) == 1); | |
| 531 | 531 | |
| 532 | 532 | try a.setRatio(-9, 3); |
| 533 | testing.expect((try a.p.to(i32)) == -3); | |
| 534 | testing.expect((try a.q.to(i32)) == 1); | |
| 533 | try testing.expect((try a.p.to(i32)) == -3); | |
| 534 | try testing.expect((try a.q.to(i32)) == 1); | |
| 535 | 535 | |
| 536 | 536 | try a.setRatio(9, -3); |
| 537 | testing.expect((try a.p.to(i32)) == -3); | |
| 538 | testing.expect((try a.q.to(i32)) == 1); | |
| 537 | try testing.expect((try a.p.to(i32)) == -3); | |
| 538 | try testing.expect((try a.q.to(i32)) == 1); | |
| 539 | 539 | |
| 540 | 540 | try a.setRatio(-9, -3); |
| 541 | testing.expect((try a.p.to(i32)) == 3); | |
| 542 | testing.expect((try a.q.to(i32)) == 1); | |
| 541 | try testing.expect((try a.p.to(i32)) == 3); | |
| 542 | try testing.expect((try a.q.to(i32)) == 1); | |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | test "big.rational setFloat" { |
| ... | ... | @@ -547,24 +547,24 @@ test "big.rational setFloat" { |
| 547 | 547 | defer a.deinit(); |
| 548 | 548 | |
| 549 | 549 | try a.setFloat(f64, 2.5); |
| 550 | testing.expect((try a.p.to(i32)) == 5); | |
| 551 | testing.expect((try a.q.to(i32)) == 2); | |
| 550 | try testing.expect((try a.p.to(i32)) == 5); | |
| 551 | try testing.expect((try a.q.to(i32)) == 2); | |
| 552 | 552 | |
| 553 | 553 | try a.setFloat(f32, -2.5); |
| 554 | testing.expect((try a.p.to(i32)) == -5); | |
| 555 | testing.expect((try a.q.to(i32)) == 2); | |
| 554 | try testing.expect((try a.p.to(i32)) == -5); | |
| 555 | try testing.expect((try a.q.to(i32)) == 2); | |
| 556 | 556 | |
| 557 | 557 | try a.setFloat(f32, 3.141593); |
| 558 | 558 | |
| 559 | 559 | // = 3.14159297943115234375 |
| 560 | testing.expect((try a.p.to(u32)) == 3294199); | |
| 561 | testing.expect((try a.q.to(u32)) == 1048576); | |
| 560 | try testing.expect((try a.p.to(u32)) == 3294199); | |
| 561 | try testing.expect((try a.q.to(u32)) == 1048576); | |
| 562 | 562 | |
| 563 | 563 | try a.setFloat(f64, 72.141593120712409172417410926841290461290467124); |
| 564 | 564 | |
| 565 | 565 | // = 72.1415931207124145885245525278151035308837890625 |
| 566 | testing.expect((try a.p.to(u128)) == 5076513310880537); | |
| 567 | testing.expect((try a.q.to(u128)) == 70368744177664); | |
| 566 | try testing.expect((try a.p.to(u128)) == 5076513310880537); | |
| 567 | try testing.expect((try a.q.to(u128)) == 70368744177664); | |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | test "big.rational setFloatString" { |
| ... | ... | @@ -574,8 +574,8 @@ test "big.rational setFloatString" { |
| 574 | 574 | try a.setFloatString("72.14159312071241458852455252781510353"); |
| 575 | 575 | |
| 576 | 576 | // = 72.1415931207124145885245525278151035308837890625 |
| 577 | testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353); | |
| 578 | testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000); | |
| 577 | try testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353); | |
| 578 | try testing.expect((try a.q.to(u128)) == 100000000000000000000000000000000000); | |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | test "big.rational toFloat" { |
| ... | ... | @@ -584,11 +584,11 @@ test "big.rational toFloat" { |
| 584 | 584 | |
| 585 | 585 | // = 3.14159297943115234375 |
| 586 | 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); | |
| 588 | 588 | |
| 589 | 589 | // = 72.1415931207124145885245525278151035308837890625 |
| 590 | 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 | } |
| 593 | 593 | |
| 594 | 594 | test "big.rational set/to Float round-trip" { |
| ... | ... | @@ -599,7 +599,7 @@ test "big.rational set/to Float round-trip" { |
| 599 | 599 | while (i < 512) : (i += 1) { |
| 600 | 600 | const r = prng.random.float(f64); |
| 601 | 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 | } |
| 605 | 605 | |
| ... | ... | @@ -611,8 +611,8 @@ test "big.rational copy" { |
| 611 | 611 | defer b.deinit(); |
| 612 | 612 | |
| 613 | 613 | try a.copyInt(b); |
| 614 | testing.expect((try a.p.to(u32)) == 5); | |
| 615 | testing.expect((try a.q.to(u32)) == 1); | |
| 614 | try testing.expect((try a.p.to(u32)) == 5); | |
| 615 | try testing.expect((try a.q.to(u32)) == 1); | |
| 616 | 616 | |
| 617 | 617 | var c = try Int.initSet(testing.allocator, 7); |
| 618 | 618 | defer c.deinit(); |
| ... | ... | @@ -620,8 +620,8 @@ test "big.rational copy" { |
| 620 | 620 | defer d.deinit(); |
| 621 | 621 | |
| 622 | 622 | try a.copyRatio(c, d); |
| 623 | testing.expect((try a.p.to(u32)) == 7); | |
| 624 | testing.expect((try a.q.to(u32)) == 3); | |
| 623 | try testing.expect((try a.p.to(u32)) == 7); | |
| 624 | try testing.expect((try a.q.to(u32)) == 3); | |
| 625 | 625 | |
| 626 | 626 | var e = try Int.initSet(testing.allocator, 9); |
| 627 | 627 | defer e.deinit(); |
| ... | ... | @@ -629,8 +629,8 @@ test "big.rational copy" { |
| 629 | 629 | defer f.deinit(); |
| 630 | 630 | |
| 631 | 631 | try a.copyRatio(e, f); |
| 632 | testing.expect((try a.p.to(u32)) == 3); | |
| 633 | testing.expect((try a.q.to(u32)) == 1); | |
| 632 | try testing.expect((try a.p.to(u32)) == 3); | |
| 633 | try testing.expect((try a.q.to(u32)) == 1); | |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | test "big.rational negate" { |
| ... | ... | @@ -638,16 +638,16 @@ test "big.rational negate" { |
| 638 | 638 | defer a.deinit(); |
| 639 | 639 | |
| 640 | 640 | try a.setInt(-50); |
| 641 | testing.expect((try a.p.to(i32)) == -50); | |
| 642 | testing.expect((try a.q.to(i32)) == 1); | |
| 641 | try testing.expect((try a.p.to(i32)) == -50); | |
| 642 | try testing.expect((try a.q.to(i32)) == 1); | |
| 643 | 643 | |
| 644 | 644 | a.negate(); |
| 645 | testing.expect((try a.p.to(i32)) == 50); | |
| 646 | testing.expect((try a.q.to(i32)) == 1); | |
| 645 | try testing.expect((try a.p.to(i32)) == 50); | |
| 646 | try testing.expect((try a.q.to(i32)) == 1); | |
| 647 | 647 | |
| 648 | 648 | a.negate(); |
| 649 | testing.expect((try a.p.to(i32)) == -50); | |
| 650 | testing.expect((try a.q.to(i32)) == 1); | |
| 649 | try testing.expect((try a.p.to(i32)) == -50); | |
| 650 | try testing.expect((try a.q.to(i32)) == 1); | |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | test "big.rational abs" { |
| ... | ... | @@ -655,16 +655,16 @@ test "big.rational abs" { |
| 655 | 655 | defer a.deinit(); |
| 656 | 656 | |
| 657 | 657 | try a.setInt(-50); |
| 658 | testing.expect((try a.p.to(i32)) == -50); | |
| 659 | testing.expect((try a.q.to(i32)) == 1); | |
| 658 | try testing.expect((try a.p.to(i32)) == -50); | |
| 659 | try testing.expect((try a.q.to(i32)) == 1); | |
| 660 | 660 | |
| 661 | 661 | a.abs(); |
| 662 | testing.expect((try a.p.to(i32)) == 50); | |
| 663 | testing.expect((try a.q.to(i32)) == 1); | |
| 662 | try testing.expect((try a.p.to(i32)) == 50); | |
| 663 | try testing.expect((try a.q.to(i32)) == 1); | |
| 664 | 664 | |
| 665 | 665 | a.abs(); |
| 666 | testing.expect((try a.p.to(i32)) == 50); | |
| 667 | testing.expect((try a.q.to(i32)) == 1); | |
| 666 | try testing.expect((try a.p.to(i32)) == 50); | |
| 667 | try testing.expect((try a.q.to(i32)) == 1); | |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | test "big.rational swap" { |
| ... | ... | @@ -676,19 +676,19 @@ test "big.rational swap" { |
| 676 | 676 | try a.setRatio(50, 23); |
| 677 | 677 | try b.setRatio(17, 3); |
| 678 | 678 | |
| 679 | testing.expect((try a.p.to(u32)) == 50); | |
| 680 | testing.expect((try a.q.to(u32)) == 23); | |
| 679 | try testing.expect((try a.p.to(u32)) == 50); | |
| 680 | try testing.expect((try a.q.to(u32)) == 23); | |
| 681 | 681 | |
| 682 | testing.expect((try b.p.to(u32)) == 17); | |
| 683 | testing.expect((try b.q.to(u32)) == 3); | |
| 682 | try testing.expect((try b.p.to(u32)) == 17); | |
| 683 | try testing.expect((try b.q.to(u32)) == 3); | |
| 684 | 684 | |
| 685 | 685 | a.swap(&b); |
| 686 | 686 | |
| 687 | testing.expect((try a.p.to(u32)) == 17); | |
| 688 | testing.expect((try a.q.to(u32)) == 3); | |
| 687 | try testing.expect((try a.p.to(u32)) == 17); | |
| 688 | try testing.expect((try a.q.to(u32)) == 3); | |
| 689 | 689 | |
| 690 | testing.expect((try b.p.to(u32)) == 50); | |
| 691 | testing.expect((try b.q.to(u32)) == 23); | |
| 690 | try testing.expect((try b.p.to(u32)) == 50); | |
| 691 | try testing.expect((try b.q.to(u32)) == 23); | |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | test "big.rational order" { |
| ... | ... | @@ -699,11 +699,11 @@ test "big.rational order" { |
| 699 | 699 | |
| 700 | 700 | try a.setRatio(500, 231); |
| 701 | 701 | try b.setRatio(18903, 8584); |
| 702 | testing.expect((try a.order(b)) == .lt); | |
| 702 | try testing.expect((try a.order(b)) == .lt); | |
| 703 | 703 | |
| 704 | 704 | try a.setRatio(890, 10); |
| 705 | 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 | } |
| 708 | 708 | |
| 709 | 709 | test "big.rational add single-limb" { |
| ... | ... | @@ -714,11 +714,11 @@ test "big.rational add single-limb" { |
| 714 | 714 | |
| 715 | 715 | try a.setRatio(500, 231); |
| 716 | 716 | try b.setRatio(18903, 8584); |
| 717 | testing.expect((try a.order(b)) == .lt); | |
| 717 | try testing.expect((try a.order(b)) == .lt); | |
| 718 | 718 | |
| 719 | 719 | try a.setRatio(890, 10); |
| 720 | 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 | } |
| 723 | 723 | |
| 724 | 724 | test "big.rational add" { |
| ... | ... | @@ -734,7 +734,7 @@ test "big.rational add" { |
| 734 | 734 | try a.add(a, b); |
| 735 | 735 | |
| 736 | 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 | } |
| 739 | 739 | |
| 740 | 740 | test "big.rational sub" { |
| ... | ... | @@ -750,7 +750,7 @@ test "big.rational sub" { |
| 750 | 750 | try a.sub(a, b); |
| 751 | 751 | |
| 752 | 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 | } |
| 755 | 755 | |
| 756 | 756 | test "big.rational mul" { |
| ... | ... | @@ -766,7 +766,7 @@ test "big.rational mul" { |
| 766 | 766 | try a.mul(a, b); |
| 767 | 767 | |
| 768 | 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 | } |
| 771 | 771 | |
| 772 | 772 | test "big.rational div" { |
| ... | ... | @@ -782,7 +782,7 @@ test "big.rational div" { |
| 782 | 782 | try a.div(a, b); |
| 783 | 783 | |
| 784 | 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 | } |
| 787 | 787 | |
| 788 | 788 | test "big.rational div" { |
| ... | ... | @@ -795,11 +795,11 @@ test "big.rational div" { |
| 795 | 795 | a.invert(); |
| 796 | 796 | |
| 797 | 797 | try r.setRatio(23341, 78923); |
| 798 | testing.expect((try a.order(r)) == .eq); | |
| 798 | try testing.expect((try a.order(r)) == .eq); | |
| 799 | 799 | |
| 800 | 800 | try a.setRatio(-78923, 23341); |
| 801 | 801 | a.invert(); |
| 802 | 802 | |
| 803 | 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 | 125 | } |
| 126 | 126 | |
| 127 | 127 | test "math.cbrt" { |
| 128 | expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0)); | |
| 129 | expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0)); | |
| 128 | try expect(cbrt(@as(f32, 0.0)) == cbrt32(0.0)); | |
| 129 | try expect(cbrt(@as(f64, 0.0)) == cbrt64(0.0)); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "math.cbrt32" { |
| 133 | 133 | const epsilon = 0.000001; |
| 134 | 134 | |
| 135 | expect(cbrt32(0.0) == 0.0); | |
| 136 | expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon)); | |
| 137 | expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon)); | |
| 138 | expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon)); | |
| 139 | expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon)); | |
| 140 | expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon)); | |
| 135 | try expect(cbrt32(0.0) == 0.0); | |
| 136 | try expect(math.approxEqAbs(f32, cbrt32(0.2), 0.584804, epsilon)); | |
| 137 | try expect(math.approxEqAbs(f32, cbrt32(0.8923), 0.962728, epsilon)); | |
| 138 | try expect(math.approxEqAbs(f32, cbrt32(1.5), 1.144714, epsilon)); | |
| 139 | try expect(math.approxEqAbs(f32, cbrt32(37.45), 3.345676, epsilon)); | |
| 140 | try expect(math.approxEqAbs(f32, cbrt32(123123.234375), 49.748501, epsilon)); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "math.cbrt64" { |
| 144 | 144 | const epsilon = 0.000001; |
| 145 | 145 | |
| 146 | expect(cbrt64(0.0) == 0.0); | |
| 147 | expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon)); | |
| 148 | expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon)); | |
| 149 | expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon)); | |
| 150 | expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon)); | |
| 151 | expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon)); | |
| 146 | try expect(cbrt64(0.0) == 0.0); | |
| 147 | try expect(math.approxEqAbs(f64, cbrt64(0.2), 0.584804, epsilon)); | |
| 148 | try expect(math.approxEqAbs(f64, cbrt64(0.8923), 0.962728, epsilon)); | |
| 149 | try expect(math.approxEqAbs(f64, cbrt64(1.5), 1.144714, epsilon)); | |
| 150 | try expect(math.approxEqAbs(f64, cbrt64(37.45), 3.345676, epsilon)); | |
| 151 | try expect(math.approxEqAbs(f64, cbrt64(123123.234375), 49.748501, epsilon)); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.cbrt.special" { |
| 155 | expect(cbrt32(0.0) == 0.0); | |
| 156 | expect(cbrt32(-0.0) == -0.0); | |
| 157 | expect(math.isPositiveInf(cbrt32(math.inf(f32)))); | |
| 158 | expect(math.isNegativeInf(cbrt32(-math.inf(f32)))); | |
| 159 | expect(math.isNan(cbrt32(math.nan(f32)))); | |
| 155 | try expect(cbrt32(0.0) == 0.0); | |
| 156 | try expect(cbrt32(-0.0) == -0.0); | |
| 157 | try expect(math.isPositiveInf(cbrt32(math.inf(f32)))); | |
| 158 | try expect(math.isNegativeInf(cbrt32(-math.inf(f32)))); | |
| 159 | try expect(math.isNan(cbrt32(math.nan(f32)))); | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | test "math.cbrt64.special" { |
| 163 | expect(cbrt64(0.0) == 0.0); | |
| 164 | expect(cbrt64(-0.0) == -0.0); | |
| 165 | expect(math.isPositiveInf(cbrt64(math.inf(f64)))); | |
| 166 | expect(math.isNegativeInf(cbrt64(-math.inf(f64)))); | |
| 167 | expect(math.isNan(cbrt64(math.nan(f64)))); | |
| 163 | try expect(cbrt64(0.0) == 0.0); | |
| 164 | try expect(cbrt64(-0.0) == -0.0); | |
| 165 | try expect(math.isPositiveInf(cbrt64(math.inf(f64)))); | |
| 166 | try expect(math.isNegativeInf(cbrt64(-math.inf(f64)))); | |
| 167 | try expect(math.isNan(cbrt64(math.nan(f64)))); | |
| 168 | 168 | } |
lib/std/math/ceil.zig+27-27| ... | ... | @@ -120,49 +120,49 @@ fn ceil128(x: f128) f128 { |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "math.ceil" { |
| 123 | expect(ceil(@as(f32, 0.0)) == ceil32(0.0)); | |
| 124 | expect(ceil(@as(f64, 0.0)) == ceil64(0.0)); | |
| 125 | expect(ceil(@as(f128, 0.0)) == ceil128(0.0)); | |
| 123 | try expect(ceil(@as(f32, 0.0)) == ceil32(0.0)); | |
| 124 | try expect(ceil(@as(f64, 0.0)) == ceil64(0.0)); | |
| 125 | try expect(ceil(@as(f128, 0.0)) == ceil128(0.0)); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | test "math.ceil32" { |
| 129 | expect(ceil32(1.3) == 2.0); | |
| 130 | expect(ceil32(-1.3) == -1.0); | |
| 131 | expect(ceil32(0.2) == 1.0); | |
| 129 | try expect(ceil32(1.3) == 2.0); | |
| 130 | try expect(ceil32(-1.3) == -1.0); | |
| 131 | try expect(ceil32(0.2) == 1.0); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | test "math.ceil64" { |
| 135 | expect(ceil64(1.3) == 2.0); | |
| 136 | expect(ceil64(-1.3) == -1.0); | |
| 137 | expect(ceil64(0.2) == 1.0); | |
| 135 | try expect(ceil64(1.3) == 2.0); | |
| 136 | try expect(ceil64(-1.3) == -1.0); | |
| 137 | try expect(ceil64(0.2) == 1.0); | |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | test "math.ceil128" { |
| 141 | expect(ceil128(1.3) == 2.0); | |
| 142 | expect(ceil128(-1.3) == -1.0); | |
| 143 | expect(ceil128(0.2) == 1.0); | |
| 141 | try expect(ceil128(1.3) == 2.0); | |
| 142 | try expect(ceil128(-1.3) == -1.0); | |
| 143 | try expect(ceil128(0.2) == 1.0); | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | test "math.ceil32.special" { |
| 147 | expect(ceil32(0.0) == 0.0); | |
| 148 | expect(ceil32(-0.0) == -0.0); | |
| 149 | expect(math.isPositiveInf(ceil32(math.inf(f32)))); | |
| 150 | expect(math.isNegativeInf(ceil32(-math.inf(f32)))); | |
| 151 | expect(math.isNan(ceil32(math.nan(f32)))); | |
| 147 | try expect(ceil32(0.0) == 0.0); | |
| 148 | try expect(ceil32(-0.0) == -0.0); | |
| 149 | try expect(math.isPositiveInf(ceil32(math.inf(f32)))); | |
| 150 | try expect(math.isNegativeInf(ceil32(-math.inf(f32)))); | |
| 151 | try expect(math.isNan(ceil32(math.nan(f32)))); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | test "math.ceil64.special" { |
| 155 | expect(ceil64(0.0) == 0.0); | |
| 156 | expect(ceil64(-0.0) == -0.0); | |
| 157 | expect(math.isPositiveInf(ceil64(math.inf(f64)))); | |
| 158 | expect(math.isNegativeInf(ceil64(-math.inf(f64)))); | |
| 159 | expect(math.isNan(ceil64(math.nan(f64)))); | |
| 155 | try expect(ceil64(0.0) == 0.0); | |
| 156 | try expect(ceil64(-0.0) == -0.0); | |
| 157 | try expect(math.isPositiveInf(ceil64(math.inf(f64)))); | |
| 158 | try expect(math.isNegativeInf(ceil64(-math.inf(f64)))); | |
| 159 | try expect(math.isNan(ceil64(math.nan(f64)))); | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | test "math.ceil128.special" { |
| 163 | expect(ceil128(0.0) == 0.0); | |
| 164 | expect(ceil128(-0.0) == -0.0); | |
| 165 | expect(math.isPositiveInf(ceil128(math.inf(f128)))); | |
| 166 | expect(math.isNegativeInf(ceil128(-math.inf(f128)))); | |
| 167 | expect(math.isNan(ceil128(math.nan(f128)))); | |
| 163 | try expect(ceil128(0.0) == 0.0); | |
| 164 | try expect(ceil128(-0.0) == -0.0); | |
| 165 | try expect(math.isPositiveInf(ceil128(math.inf(f128)))); | |
| 166 | try expect(math.isNegativeInf(ceil128(-math.inf(f128)))); | |
| 167 | try expect(math.isNan(ceil128(math.nan(f128)))); | |
| 168 | 168 | } |
lib/std/math/complex.zig+7-7| ... | ... | @@ -114,7 +114,7 @@ test "complex.add" { |
| 114 | 114 | const b = Complex(f32).new(2, 7); |
| 115 | 115 | const c = a.add(b); |
| 116 | 116 | |
| 117 | testing.expect(c.re == 7 and c.im == 10); | |
| 117 | try testing.expect(c.re == 7 and c.im == 10); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "complex.sub" { |
| ... | ... | @@ -122,7 +122,7 @@ test "complex.sub" { |
| 122 | 122 | const b = Complex(f32).new(2, 7); |
| 123 | 123 | const c = a.sub(b); |
| 124 | 124 | |
| 125 | testing.expect(c.re == 3 and c.im == -4); | |
| 125 | try testing.expect(c.re == 3 and c.im == -4); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | test "complex.mul" { |
| ... | ... | @@ -130,7 +130,7 @@ test "complex.mul" { |
| 130 | 130 | const b = Complex(f32).new(2, 7); |
| 131 | 131 | const c = a.mul(b); |
| 132 | 132 | |
| 133 | testing.expect(c.re == -11 and c.im == 41); | |
| 133 | try testing.expect(c.re == -11 and c.im == 41); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "complex.div" { |
| ... | ... | @@ -138,7 +138,7 @@ test "complex.div" { |
| 138 | 138 | const b = Complex(f32).new(2, 7); |
| 139 | 139 | const c = a.div(b); |
| 140 | 140 | |
| 141 | testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and | |
| 141 | try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 31) / 53, epsilon) and | |
| 142 | 142 | math.approxEqAbs(f32, c.im, @as(f32, -29) / 53, epsilon)); |
| 143 | 143 | } |
| 144 | 144 | |
| ... | ... | @@ -146,14 +146,14 @@ test "complex.conjugate" { |
| 146 | 146 | const a = Complex(f32).new(5, 3); |
| 147 | 147 | const c = a.conjugate(); |
| 148 | 148 | |
| 149 | testing.expect(c.re == 5 and c.im == -3); | |
| 149 | try testing.expect(c.re == 5 and c.im == -3); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | test "complex.reciprocal" { |
| 153 | 153 | const a = Complex(f32).new(5, 3); |
| 154 | 154 | const c = a.reciprocal(); |
| 155 | 155 | |
| 156 | testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and | |
| 156 | try testing.expect(math.approxEqAbs(f32, c.re, @as(f32, 5) / 34, epsilon) and | |
| 157 | 157 | math.approxEqAbs(f32, c.im, @as(f32, -3) / 34, epsilon)); |
| 158 | 158 | } |
| 159 | 159 | |
| ... | ... | @@ -161,7 +161,7 @@ test "complex.magnitude" { |
| 161 | 161 | const a = Complex(f32).new(5, 3); |
| 162 | 162 | const c = a.magnitude(); |
| 163 | 163 | |
| 164 | testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); | |
| 164 | try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | test "complex.cmath" { |
lib/std/math/complex/abs.zig+1-1| ... | ... | @@ -20,5 +20,5 @@ const epsilon = 0.0001; |
| 20 | 20 | test "complex.cabs" { |
| 21 | 21 | const a = Complex(f32).new(5, 3); |
| 22 | 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 | 22 | const a = Complex(f32).new(5, 3); |
| 23 | 23 | const c = acos(a); |
| 24 | 24 | |
| 25 | testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon)); | |
| 26 | testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon)); | |
| 25 | try testing.expect(math.approxEqAbs(f32, c.re, 0.546975, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.im, -2.452914, epsilon)); | |
| 27 | 27 | } |
lib/std/math/complex/acosh.zig+2-2| ... | ... | @@ -22,6 +22,6 @@ test "complex.cacosh" { |
| 22 | 22 | const a = Complex(f32).new(5, 3); |
| 23 | 23 | const c = acosh(a); |
| 24 | 24 | |
| 25 | testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon)); | |
| 26 | testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon)); | |
| 25 | try testing.expect(math.approxEqAbs(f32, c.re, 2.452914, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.im, 0.546975, epsilon)); | |
| 27 | 27 | } |
lib/std/math/complex/arg.zig+1-1| ... | ... | @@ -20,5 +20,5 @@ const epsilon = 0.0001; |
| 20 | 20 | test "complex.carg" { |
| 21 | 21 | const a = Complex(f32).new(5, 3); |
| 22 | 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 | 28 | const a = Complex(f32).new(5, 3); |
| 29 | 29 | const c = asin(a); |
| 30 | 30 | |
| 31 | testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon)); | |
| 32 | testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon)); | |
| 31 | try testing.expect(math.approxEqAbs(f32, c.re, 1.023822, epsilon)); | |
| 32 | try testing.expect(math.approxEqAbs(f32, c.im, 2.452914, epsilon)); | |
| 33 | 33 | } |
lib/std/math/complex/asinh.zig+2-2| ... | ... | @@ -23,6 +23,6 @@ test "complex.casinh" { |
| 23 | 23 | const a = Complex(f32).new(5, 3); |
| 24 | 24 | const c = asinh(a); |
| 25 | 25 | |
| 26 | testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon)); | |
| 27 | testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.re, 2.459831, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.im, 0.533999, epsilon)); | |
| 28 | 28 | } |
lib/std/math/complex/atan.zig+4-4| ... | ... | @@ -130,14 +130,14 @@ test "complex.catan32" { |
| 130 | 130 | const a = Complex(f32).new(5, 3); |
| 131 | 131 | const c = atan(a); |
| 132 | 132 | |
| 133 | testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon)); | |
| 134 | testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon)); | |
| 133 | try testing.expect(math.approxEqAbs(f32, c.re, 1.423679, epsilon)); | |
| 134 | try testing.expect(math.approxEqAbs(f32, c.im, 0.086569, epsilon)); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | test "complex.catan64" { |
| 138 | 138 | const a = Complex(f64).new(5, 3); |
| 139 | 139 | const c = atan(a); |
| 140 | 140 | |
| 141 | testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon)); | |
| 142 | testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon)); | |
| 141 | try testing.expect(math.approxEqAbs(f64, c.re, 1.423679, epsilon)); | |
| 142 | try testing.expect(math.approxEqAbs(f64, c.im, 0.086569, epsilon)); | |
| 143 | 143 | } |
lib/std/math/complex/atanh.zig+2-2| ... | ... | @@ -23,6 +23,6 @@ test "complex.catanh" { |
| 23 | 23 | const a = Complex(f32).new(5, 3); |
| 24 | 24 | const c = atanh(a); |
| 25 | 25 | |
| 26 | testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon)); | |
| 27 | testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.re, 0.146947, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.im, 1.480870, epsilon)); | |
| 28 | 28 | } |
lib/std/math/complex/conj.zig+1-1| ... | ... | @@ -19,5 +19,5 @@ test "complex.conj" { |
| 19 | 19 | const a = Complex(f32).new(5, 3); |
| 20 | 20 | const c = a.conjugate(); |
| 21 | 21 | |
| 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 | 22 | const a = Complex(f32).new(5, 3); |
| 23 | 23 | const c = cos(a); |
| 24 | 24 | |
| 25 | testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon)); | |
| 26 | testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon)); | |
| 25 | try testing.expect(math.approxEqAbs(f32, c.re, 2.855815, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.im, 9.606383, epsilon)); | |
| 27 | 27 | } |
lib/std/math/complex/cosh.zig+4-4| ... | ... | @@ -165,14 +165,14 @@ test "complex.ccosh32" { |
| 165 | 165 | const a = Complex(f32).new(5, 3); |
| 166 | 166 | const c = cosh(a); |
| 167 | 167 | |
| 168 | testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon)); | |
| 169 | testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon)); | |
| 168 | try testing.expect(math.approxEqAbs(f32, c.re, -73.467300, epsilon)); | |
| 169 | try testing.expect(math.approxEqAbs(f32, c.im, 10.471557, epsilon)); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "complex.ccosh64" { |
| 173 | 173 | const a = Complex(f64).new(5, 3); |
| 174 | 174 | const c = cosh(a); |
| 175 | 175 | |
| 176 | testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon)); | |
| 177 | testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon)); | |
| 176 | try testing.expect(math.approxEqAbs(f64, c.re, -73.467300, epsilon)); | |
| 177 | try testing.expect(math.approxEqAbs(f64, c.im, 10.471557, epsilon)); | |
| 178 | 178 | } |
lib/std/math/complex/exp.zig+4-4| ... | ... | @@ -131,14 +131,14 @@ test "complex.cexp32" { |
| 131 | 131 | const a = Complex(f32).new(5, 3); |
| 132 | 132 | const c = exp(a); |
| 133 | 133 | |
| 134 | testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon)); | |
| 135 | testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon)); | |
| 134 | try testing.expect(math.approxEqAbs(f32, c.re, -146.927917, epsilon)); | |
| 135 | try testing.expect(math.approxEqAbs(f32, c.im, 20.944065, epsilon)); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "complex.cexp64" { |
| 139 | 139 | const a = Complex(f64).new(5, 3); |
| 140 | 140 | const c = exp(a); |
| 141 | 141 | |
| 142 | testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon)); | |
| 143 | testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon)); | |
| 142 | try testing.expect(math.approxEqAbs(f64, c.re, -146.927917, epsilon)); | |
| 143 | try testing.expect(math.approxEqAbs(f64, c.im, 20.944065, epsilon)); | |
| 144 | 144 | } |
lib/std/math/complex/log.zig+2-2| ... | ... | @@ -24,6 +24,6 @@ test "complex.clog" { |
| 24 | 24 | const a = Complex(f32).new(5, 3); |
| 25 | 25 | const c = log(a); |
| 26 | 26 | |
| 27 | testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon)); | |
| 28 | testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.re, 1.763180, epsilon)); | |
| 28 | try testing.expect(math.approxEqAbs(f32, c.im, 0.540419, epsilon)); | |
| 29 | 29 | } |
lib/std/math/complex/pow.zig+2-2| ... | ... | @@ -23,6 +23,6 @@ test "complex.cpow" { |
| 23 | 23 | const b = Complex(f32).new(2.3, -1.3); |
| 24 | 24 | const c = pow(Complex(f32), a, b); |
| 25 | 25 | |
| 26 | testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon)); | |
| 27 | testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.re, 58.049110, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.im, -101.003433, epsilon)); | |
| 28 | 28 | } |
lib/std/math/complex/proj.zig+1-1| ... | ... | @@ -26,5 +26,5 @@ test "complex.cproj" { |
| 26 | 26 | const a = Complex(f32).new(5, 3); |
| 27 | 27 | const c = proj(a); |
| 28 | 28 | |
| 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 | 23 | const a = Complex(f32).new(5, 3); |
| 24 | 24 | const c = sin(a); |
| 25 | 25 | |
| 26 | testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon)); | |
| 27 | testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.re, -9.654126, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.im, 2.841692, epsilon)); | |
| 28 | 28 | } |
lib/std/math/complex/sinh.zig+4-4| ... | ... | @@ -164,14 +164,14 @@ test "complex.csinh32" { |
| 164 | 164 | const a = Complex(f32).new(5, 3); |
| 165 | 165 | const c = sinh(a); |
| 166 | 166 | |
| 167 | testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon)); | |
| 168 | testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon)); | |
| 167 | try testing.expect(math.approxEqAbs(f32, c.re, -73.460617, epsilon)); | |
| 168 | try testing.expect(math.approxEqAbs(f32, c.im, 10.472508, epsilon)); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "complex.csinh64" { |
| 172 | 172 | const a = Complex(f64).new(5, 3); |
| 173 | 173 | const c = sinh(a); |
| 174 | 174 | |
| 175 | testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon)); | |
| 176 | testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon)); | |
| 175 | try testing.expect(math.approxEqAbs(f64, c.re, -73.460617, epsilon)); | |
| 176 | try testing.expect(math.approxEqAbs(f64, c.im, 10.472508, epsilon)); | |
| 177 | 177 | } |
lib/std/math/complex/sqrt.zig+4-4| ... | ... | @@ -138,14 +138,14 @@ test "complex.csqrt32" { |
| 138 | 138 | const a = Complex(f32).new(5, 3); |
| 139 | 139 | const c = sqrt(a); |
| 140 | 140 | |
| 141 | testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon)); | |
| 142 | testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon)); | |
| 141 | try testing.expect(math.approxEqAbs(f32, c.re, 2.327117, epsilon)); | |
| 142 | try testing.expect(math.approxEqAbs(f32, c.im, 0.644574, epsilon)); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "complex.csqrt64" { |
| 146 | 146 | const a = Complex(f64).new(5, 3); |
| 147 | 147 | const c = sqrt(a); |
| 148 | 148 | |
| 149 | testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon)); | |
| 150 | testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon)); | |
| 149 | try testing.expect(math.approxEqAbs(f64, c.re, 2.3271175190399496, epsilon)); | |
| 150 | try testing.expect(math.approxEqAbs(f64, c.im, 0.6445742373246469, epsilon)); | |
| 151 | 151 | } |
lib/std/math/complex/tan.zig+2-2| ... | ... | @@ -23,6 +23,6 @@ test "complex.ctan" { |
| 23 | 23 | const a = Complex(f32).new(5, 3); |
| 24 | 24 | const c = tan(a); |
| 25 | 25 | |
| 26 | testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon)); | |
| 27 | testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon)); | |
| 26 | try testing.expect(math.approxEqAbs(f32, c.re, -0.002708233, epsilon)); | |
| 27 | try testing.expect(math.approxEqAbs(f32, c.im, 1.004165, epsilon)); | |
| 28 | 28 | } |
lib/std/math/complex/tanh.zig+4-4| ... | ... | @@ -113,14 +113,14 @@ test "complex.ctanh32" { |
| 113 | 113 | const a = Complex(f32).new(5, 3); |
| 114 | 114 | const c = tanh(a); |
| 115 | 115 | |
| 116 | testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon)); | |
| 117 | testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon)); | |
| 116 | try testing.expect(math.approxEqAbs(f32, c.re, 0.999913, epsilon)); | |
| 117 | try testing.expect(math.approxEqAbs(f32, c.im, -0.000025, epsilon)); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "complex.ctanh64" { |
| 121 | 121 | const a = Complex(f64).new(5, 3); |
| 122 | 122 | const c = tanh(a); |
| 123 | 123 | |
| 124 | testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon)); | |
| 125 | testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon)); | |
| 124 | try testing.expect(math.approxEqAbs(f64, c.re, 0.999913, epsilon)); | |
| 125 | try testing.expect(math.approxEqAbs(f64, c.im, -0.000025, epsilon)); | |
| 126 | 126 | } |
lib/std/math/copysign.zig+20-20| ... | ... | @@ -62,36 +62,36 @@ fn copysign128(x: f128, y: f128) f128 { |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | test "math.copysign" { |
| 65 | expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0)); | |
| 66 | expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0)); | |
| 67 | expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0)); | |
| 68 | expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0)); | |
| 65 | try expect(copysign(f16, 1.0, 1.0) == copysign16(1.0, 1.0)); | |
| 66 | try expect(copysign(f32, 1.0, 1.0) == copysign32(1.0, 1.0)); | |
| 67 | try expect(copysign(f64, 1.0, 1.0) == copysign64(1.0, 1.0)); | |
| 68 | try expect(copysign(f128, 1.0, 1.0) == copysign128(1.0, 1.0)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "math.copysign16" { |
| 72 | expect(copysign16(5.0, 1.0) == 5.0); | |
| 73 | expect(copysign16(5.0, -1.0) == -5.0); | |
| 74 | expect(copysign16(-5.0, -1.0) == -5.0); | |
| 75 | expect(copysign16(-5.0, 1.0) == 5.0); | |
| 72 | try expect(copysign16(5.0, 1.0) == 5.0); | |
| 73 | try expect(copysign16(5.0, -1.0) == -5.0); | |
| 74 | try expect(copysign16(-5.0, -1.0) == -5.0); | |
| 75 | try expect(copysign16(-5.0, 1.0) == 5.0); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "math.copysign32" { |
| 79 | expect(copysign32(5.0, 1.0) == 5.0); | |
| 80 | expect(copysign32(5.0, -1.0) == -5.0); | |
| 81 | expect(copysign32(-5.0, -1.0) == -5.0); | |
| 82 | expect(copysign32(-5.0, 1.0) == 5.0); | |
| 79 | try expect(copysign32(5.0, 1.0) == 5.0); | |
| 80 | try expect(copysign32(5.0, -1.0) == -5.0); | |
| 81 | try expect(copysign32(-5.0, -1.0) == -5.0); | |
| 82 | try expect(copysign32(-5.0, 1.0) == 5.0); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "math.copysign64" { |
| 86 | expect(copysign64(5.0, 1.0) == 5.0); | |
| 87 | expect(copysign64(5.0, -1.0) == -5.0); | |
| 88 | expect(copysign64(-5.0, -1.0) == -5.0); | |
| 89 | expect(copysign64(-5.0, 1.0) == 5.0); | |
| 86 | try expect(copysign64(5.0, 1.0) == 5.0); | |
| 87 | try expect(copysign64(5.0, -1.0) == -5.0); | |
| 88 | try expect(copysign64(-5.0, -1.0) == -5.0); | |
| 89 | try expect(copysign64(-5.0, 1.0) == 5.0); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | test "math.copysign128" { |
| 93 | expect(copysign128(5.0, 1.0) == 5.0); | |
| 94 | expect(copysign128(5.0, -1.0) == -5.0); | |
| 95 | expect(copysign128(-5.0, -1.0) == -5.0); | |
| 96 | expect(copysign128(-5.0, 1.0) == 5.0); | |
| 93 | try expect(copysign128(5.0, 1.0) == 5.0); | |
| 94 | try expect(copysign128(5.0, -1.0) == -5.0); | |
| 95 | try expect(copysign128(-5.0, -1.0) == -5.0); | |
| 96 | try expect(copysign128(-5.0, 1.0) == 5.0); | |
| 97 | 97 | } |
lib/std/math/cos.zig+22-22| ... | ... | @@ -88,42 +88,42 @@ fn cos_(comptime T: type, x_: T) T { |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "math.cos" { |
| 91 | expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0)); | |
| 92 | expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0)); | |
| 91 | try expect(cos(@as(f32, 0.0)) == cos_(f32, 0.0)); | |
| 92 | try expect(cos(@as(f64, 0.0)) == cos_(f64, 0.0)); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "math.cos32" { |
| 96 | 96 | const epsilon = 0.000001; |
| 97 | 97 | |
| 98 | expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon)); | |
| 99 | expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon)); | |
| 100 | expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon)); | |
| 101 | expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon)); | |
| 102 | expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon)); | |
| 103 | expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon)); | |
| 104 | expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon)); | |
| 98 | try expect(math.approxEqAbs(f32, cos_(f32, 0.0), 1.0, epsilon)); | |
| 99 | try expect(math.approxEqAbs(f32, cos_(f32, 0.2), 0.980067, epsilon)); | |
| 100 | try expect(math.approxEqAbs(f32, cos_(f32, 0.8923), 0.627623, epsilon)); | |
| 101 | try expect(math.approxEqAbs(f32, cos_(f32, 1.5), 0.070737, epsilon)); | |
| 102 | try expect(math.approxEqAbs(f32, cos_(f32, -1.5), 0.070737, epsilon)); | |
| 103 | try expect(math.approxEqAbs(f32, cos_(f32, 37.45), 0.969132, epsilon)); | |
| 104 | try expect(math.approxEqAbs(f32, cos_(f32, 89.123), 0.400798, epsilon)); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | test "math.cos64" { |
| 108 | 108 | const epsilon = 0.000001; |
| 109 | 109 | |
| 110 | expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon)); | |
| 111 | expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon)); | |
| 112 | expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon)); | |
| 113 | expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon)); | |
| 114 | expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon)); | |
| 115 | expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon)); | |
| 116 | expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon)); | |
| 110 | try expect(math.approxEqAbs(f64, cos_(f64, 0.0), 1.0, epsilon)); | |
| 111 | try expect(math.approxEqAbs(f64, cos_(f64, 0.2), 0.980067, epsilon)); | |
| 112 | try expect(math.approxEqAbs(f64, cos_(f64, 0.8923), 0.627623, epsilon)); | |
| 113 | try expect(math.approxEqAbs(f64, cos_(f64, 1.5), 0.070737, epsilon)); | |
| 114 | try expect(math.approxEqAbs(f64, cos_(f64, -1.5), 0.070737, epsilon)); | |
| 115 | try expect(math.approxEqAbs(f64, cos_(f64, 37.45), 0.969132, epsilon)); | |
| 116 | try expect(math.approxEqAbs(f64, cos_(f64, 89.123), 0.40080, epsilon)); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "math.cos32.special" { |
| 120 | expect(math.isNan(cos_(f32, math.inf(f32)))); | |
| 121 | expect(math.isNan(cos_(f32, -math.inf(f32)))); | |
| 122 | expect(math.isNan(cos_(f32, math.nan(f32)))); | |
| 120 | try expect(math.isNan(cos_(f32, math.inf(f32)))); | |
| 121 | try expect(math.isNan(cos_(f32, -math.inf(f32)))); | |
| 122 | try expect(math.isNan(cos_(f32, math.nan(f32)))); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "math.cos64.special" { |
| 126 | expect(math.isNan(cos_(f64, math.inf(f64)))); | |
| 127 | expect(math.isNan(cos_(f64, -math.inf(f64)))); | |
| 128 | expect(math.isNan(cos_(f64, math.nan(f64)))); | |
| 126 | try expect(math.isNan(cos_(f64, math.inf(f64)))); | |
| 127 | try expect(math.isNan(cos_(f64, -math.inf(f64)))); | |
| 128 | try expect(math.isNan(cos_(f64, math.nan(f64)))); | |
| 129 | 129 | } |
lib/std/math/cosh.zig+28-28| ... | ... | @@ -93,48 +93,48 @@ fn cosh64(x: f64) f64 { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "math.cosh" { |
| 96 | expect(cosh(@as(f32, 1.5)) == cosh32(1.5)); | |
| 97 | expect(cosh(@as(f64, 1.5)) == cosh64(1.5)); | |
| 96 | try expect(cosh(@as(f32, 1.5)) == cosh32(1.5)); | |
| 97 | try expect(cosh(@as(f64, 1.5)) == cosh64(1.5)); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "math.cosh32" { |
| 101 | 101 | const epsilon = 0.000001; |
| 102 | 102 | |
| 103 | expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon)); | |
| 104 | expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon)); | |
| 105 | expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon)); | |
| 106 | expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon)); | |
| 107 | expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon)); | |
| 108 | expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon)); | |
| 109 | expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon)); | |
| 110 | expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon)); | |
| 103 | try expect(math.approxEqAbs(f32, cosh32(0.0), 1.0, epsilon)); | |
| 104 | try expect(math.approxEqAbs(f32, cosh32(0.2), 1.020067, epsilon)); | |
| 105 | try expect(math.approxEqAbs(f32, cosh32(0.8923), 1.425225, epsilon)); | |
| 106 | try expect(math.approxEqAbs(f32, cosh32(1.5), 2.352410, epsilon)); | |
| 107 | try expect(math.approxEqAbs(f32, cosh32(-0.0), 1.0, epsilon)); | |
| 108 | try expect(math.approxEqAbs(f32, cosh32(-0.2), 1.020067, epsilon)); | |
| 109 | try expect(math.approxEqAbs(f32, cosh32(-0.8923), 1.425225, epsilon)); | |
| 110 | try expect(math.approxEqAbs(f32, cosh32(-1.5), 2.352410, epsilon)); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "math.cosh64" { |
| 114 | 114 | const epsilon = 0.000001; |
| 115 | 115 | |
| 116 | expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon)); | |
| 117 | expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon)); | |
| 118 | expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon)); | |
| 119 | expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon)); | |
| 120 | expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon)); | |
| 121 | expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon)); | |
| 122 | expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon)); | |
| 123 | expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon)); | |
| 116 | try expect(math.approxEqAbs(f64, cosh64(0.0), 1.0, epsilon)); | |
| 117 | try expect(math.approxEqAbs(f64, cosh64(0.2), 1.020067, epsilon)); | |
| 118 | try expect(math.approxEqAbs(f64, cosh64(0.8923), 1.425225, epsilon)); | |
| 119 | try expect(math.approxEqAbs(f64, cosh64(1.5), 2.352410, epsilon)); | |
| 120 | try expect(math.approxEqAbs(f64, cosh64(-0.0), 1.0, epsilon)); | |
| 121 | try expect(math.approxEqAbs(f64, cosh64(-0.2), 1.020067, epsilon)); | |
| 122 | try expect(math.approxEqAbs(f64, cosh64(-0.8923), 1.425225, epsilon)); | |
| 123 | try expect(math.approxEqAbs(f64, cosh64(-1.5), 2.352410, epsilon)); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | test "math.cosh32.special" { |
| 127 | expect(cosh32(0.0) == 1.0); | |
| 128 | expect(cosh32(-0.0) == 1.0); | |
| 129 | expect(math.isPositiveInf(cosh32(math.inf(f32)))); | |
| 130 | expect(math.isPositiveInf(cosh32(-math.inf(f32)))); | |
| 131 | expect(math.isNan(cosh32(math.nan(f32)))); | |
| 127 | try expect(cosh32(0.0) == 1.0); | |
| 128 | try expect(cosh32(-0.0) == 1.0); | |
| 129 | try expect(math.isPositiveInf(cosh32(math.inf(f32)))); | |
| 130 | try expect(math.isPositiveInf(cosh32(-math.inf(f32)))); | |
| 131 | try expect(math.isNan(cosh32(math.nan(f32)))); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | test "math.cosh64.special" { |
| 135 | expect(cosh64(0.0) == 1.0); | |
| 136 | expect(cosh64(-0.0) == 1.0); | |
| 137 | expect(math.isPositiveInf(cosh64(math.inf(f64)))); | |
| 138 | expect(math.isPositiveInf(cosh64(-math.inf(f64)))); | |
| 139 | expect(math.isNan(cosh64(math.nan(f64)))); | |
| 135 | try expect(cosh64(0.0) == 1.0); | |
| 136 | try expect(cosh64(-0.0) == 1.0); | |
| 137 | try expect(math.isPositiveInf(cosh64(math.inf(f64)))); | |
| 138 | try expect(math.isPositiveInf(cosh64(-math.inf(f64)))); | |
| 139 | try expect(math.isNan(cosh64(math.nan(f64)))); | |
| 140 | 140 | } |
lib/std/math/exp.zig+16-16| ... | ... | @@ -187,36 +187,36 @@ fn exp64(x_: f64) f64 { |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "math.exp" { |
| 190 | expect(exp(@as(f32, 0.0)) == exp32(0.0)); | |
| 191 | expect(exp(@as(f64, 0.0)) == exp64(0.0)); | |
| 190 | try expect(exp(@as(f32, 0.0)) == exp32(0.0)); | |
| 191 | try expect(exp(@as(f64, 0.0)) == exp64(0.0)); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | test "math.exp32" { |
| 195 | 195 | const epsilon = 0.000001; |
| 196 | 196 | |
| 197 | expect(exp32(0.0) == 1.0); | |
| 198 | expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon)); | |
| 199 | expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon)); | |
| 200 | expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon)); | |
| 201 | expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon)); | |
| 197 | try expect(exp32(0.0) == 1.0); | |
| 198 | try expect(math.approxEqAbs(f32, exp32(0.0), 1.0, epsilon)); | |
| 199 | try expect(math.approxEqAbs(f32, exp32(0.2), 1.221403, epsilon)); | |
| 200 | try expect(math.approxEqAbs(f32, exp32(0.8923), 2.440737, epsilon)); | |
| 201 | try expect(math.approxEqAbs(f32, exp32(1.5), 4.481689, epsilon)); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "math.exp64" { |
| 205 | 205 | const epsilon = 0.000001; |
| 206 | 206 | |
| 207 | expect(exp64(0.0) == 1.0); | |
| 208 | expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon)); | |
| 209 | expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon)); | |
| 210 | expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon)); | |
| 211 | expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon)); | |
| 207 | try expect(exp64(0.0) == 1.0); | |
| 208 | try expect(math.approxEqAbs(f64, exp64(0.0), 1.0, epsilon)); | |
| 209 | try expect(math.approxEqAbs(f64, exp64(0.2), 1.221403, epsilon)); | |
| 210 | try expect(math.approxEqAbs(f64, exp64(0.8923), 2.440737, epsilon)); | |
| 211 | try expect(math.approxEqAbs(f64, exp64(1.5), 4.481689, epsilon)); | |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | test "math.exp32.special" { |
| 215 | expect(math.isPositiveInf(exp32(math.inf(f32)))); | |
| 216 | expect(math.isNan(exp32(math.nan(f32)))); | |
| 215 | try expect(math.isPositiveInf(exp32(math.inf(f32)))); | |
| 216 | try expect(math.isNan(exp32(math.nan(f32)))); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "math.exp64.special" { |
| 220 | expect(math.isPositiveInf(exp64(math.inf(f64)))); | |
| 221 | expect(math.isNan(exp64(math.nan(f64)))); | |
| 220 | try expect(math.isPositiveInf(exp64(math.inf(f64)))); | |
| 221 | try expect(math.isNan(exp64(math.nan(f64)))); | |
| 222 | 222 | } |
lib/std/math/exp2.zig+15-15| ... | ... | @@ -426,35 +426,35 @@ fn exp2_64(x: f64) f64 { |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | test "math.exp2" { |
| 429 | expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923)); | |
| 430 | expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923)); | |
| 429 | try expect(exp2(@as(f32, 0.8923)) == exp2_32(0.8923)); | |
| 430 | try expect(exp2(@as(f64, 0.8923)) == exp2_64(0.8923)); | |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | test "math.exp2_32" { |
| 434 | 434 | const epsilon = 0.000001; |
| 435 | 435 | |
| 436 | expect(exp2_32(0.0) == 1.0); | |
| 437 | expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon)); | |
| 438 | expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon)); | |
| 439 | expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon)); | |
| 440 | expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon)); | |
| 436 | try expect(exp2_32(0.0) == 1.0); | |
| 437 | try expect(math.approxEqAbs(f32, exp2_32(0.2), 1.148698, epsilon)); | |
| 438 | try expect(math.approxEqAbs(f32, exp2_32(0.8923), 1.856133, epsilon)); | |
| 439 | try expect(math.approxEqAbs(f32, exp2_32(1.5), 2.828427, epsilon)); | |
| 440 | try expect(math.approxEqAbs(f32, exp2_32(37.45), 187747237888, epsilon)); | |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | test "math.exp2_64" { |
| 444 | 444 | const epsilon = 0.000001; |
| 445 | 445 | |
| 446 | expect(exp2_64(0.0) == 1.0); | |
| 447 | expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon)); | |
| 448 | expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon)); | |
| 449 | expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon)); | |
| 446 | try expect(exp2_64(0.0) == 1.0); | |
| 447 | try expect(math.approxEqAbs(f64, exp2_64(0.2), 1.148698, epsilon)); | |
| 448 | try expect(math.approxEqAbs(f64, exp2_64(0.8923), 1.856133, epsilon)); | |
| 449 | try expect(math.approxEqAbs(f64, exp2_64(1.5), 2.828427, epsilon)); | |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | test "math.exp2_32.special" { |
| 453 | expect(math.isPositiveInf(exp2_32(math.inf(f32)))); | |
| 454 | expect(math.isNan(exp2_32(math.nan(f32)))); | |
| 453 | try expect(math.isPositiveInf(exp2_32(math.inf(f32)))); | |
| 454 | try expect(math.isNan(exp2_32(math.nan(f32)))); | |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | test "math.exp2_64.special" { |
| 458 | expect(math.isPositiveInf(exp2_64(math.inf(f64)))); | |
| 459 | expect(math.isNan(exp2_64(math.nan(f64)))); | |
| 458 | try expect(math.isPositiveInf(exp2_64(math.inf(f64)))); | |
| 459 | try expect(math.isNan(exp2_64(math.nan(f64)))); | |
| 460 | 460 | } |
lib/std/math/expm1.zig+18-18| ... | ... | @@ -292,42 +292,42 @@ fn expm1_64(x_: f64) f64 { |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | test "math.exp1m" { |
| 295 | expect(expm1(@as(f32, 0.0)) == expm1_32(0.0)); | |
| 296 | expect(expm1(@as(f64, 0.0)) == expm1_64(0.0)); | |
| 295 | try expect(expm1(@as(f32, 0.0)) == expm1_32(0.0)); | |
| 296 | try expect(expm1(@as(f64, 0.0)) == expm1_64(0.0)); | |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | test "math.expm1_32" { |
| 300 | 300 | const epsilon = 0.000001; |
| 301 | 301 | |
| 302 | expect(expm1_32(0.0) == 0.0); | |
| 303 | expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon)); | |
| 304 | expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon)); | |
| 305 | expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon)); | |
| 306 | expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon)); | |
| 302 | try expect(expm1_32(0.0) == 0.0); | |
| 303 | try expect(math.approxEqAbs(f32, expm1_32(0.0), 0.0, epsilon)); | |
| 304 | try expect(math.approxEqAbs(f32, expm1_32(0.2), 0.221403, epsilon)); | |
| 305 | try expect(math.approxEqAbs(f32, expm1_32(0.8923), 1.440737, epsilon)); | |
| 306 | try expect(math.approxEqAbs(f32, expm1_32(1.5), 3.481689, epsilon)); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | test "math.expm1_64" { |
| 310 | 310 | const epsilon = 0.000001; |
| 311 | 311 | |
| 312 | expect(expm1_64(0.0) == 0.0); | |
| 313 | expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon)); | |
| 314 | expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon)); | |
| 315 | expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon)); | |
| 316 | expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon)); | |
| 312 | try expect(expm1_64(0.0) == 0.0); | |
| 313 | try expect(math.approxEqAbs(f64, expm1_64(0.0), 0.0, epsilon)); | |
| 314 | try expect(math.approxEqAbs(f64, expm1_64(0.2), 0.221403, epsilon)); | |
| 315 | try expect(math.approxEqAbs(f64, expm1_64(0.8923), 1.440737, epsilon)); | |
| 316 | try expect(math.approxEqAbs(f64, expm1_64(1.5), 3.481689, epsilon)); | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | test "math.expm1_32.special" { |
| 320 | 320 | const epsilon = 0.000001; |
| 321 | 321 | |
| 322 | expect(math.isPositiveInf(expm1_32(math.inf(f32)))); | |
| 323 | expect(expm1_32(-math.inf(f32)) == -1.0); | |
| 324 | expect(math.isNan(expm1_32(math.nan(f32)))); | |
| 322 | try expect(math.isPositiveInf(expm1_32(math.inf(f32)))); | |
| 323 | try expect(expm1_32(-math.inf(f32)) == -1.0); | |
| 324 | try expect(math.isNan(expm1_32(math.nan(f32)))); | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | test "math.expm1_64.special" { |
| 328 | 328 | const epsilon = 0.000001; |
| 329 | 329 | |
| 330 | expect(math.isPositiveInf(expm1_64(math.inf(f64)))); | |
| 331 | expect(expm1_64(-math.inf(f64)) == -1.0); | |
| 332 | expect(math.isNan(expm1_64(math.nan(f64)))); | |
| 330 | try expect(math.isPositiveInf(expm1_64(math.inf(f64)))); | |
| 331 | try expect(expm1_64(-math.inf(f64)) == -1.0); | |
| 332 | try expect(math.isNan(expm1_64(math.nan(f64)))); | |
| 333 | 333 | } |
lib/std/math/fabs.zig+24-24| ... | ... | @@ -55,52 +55,52 @@ fn fabs128(x: f128) f128 { |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "math.fabs" { |
| 58 | expect(fabs(@as(f16, 1.0)) == fabs16(1.0)); | |
| 59 | expect(fabs(@as(f32, 1.0)) == fabs32(1.0)); | |
| 60 | expect(fabs(@as(f64, 1.0)) == fabs64(1.0)); | |
| 61 | expect(fabs(@as(f128, 1.0)) == fabs128(1.0)); | |
| 58 | try expect(fabs(@as(f16, 1.0)) == fabs16(1.0)); | |
| 59 | try expect(fabs(@as(f32, 1.0)) == fabs32(1.0)); | |
| 60 | try expect(fabs(@as(f64, 1.0)) == fabs64(1.0)); | |
| 61 | try expect(fabs(@as(f128, 1.0)) == fabs128(1.0)); | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | test "math.fabs16" { |
| 65 | expect(fabs16(1.0) == 1.0); | |
| 66 | expect(fabs16(-1.0) == 1.0); | |
| 65 | try expect(fabs16(1.0) == 1.0); | |
| 66 | try expect(fabs16(-1.0) == 1.0); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | test "math.fabs32" { |
| 70 | expect(fabs32(1.0) == 1.0); | |
| 71 | expect(fabs32(-1.0) == 1.0); | |
| 70 | try expect(fabs32(1.0) == 1.0); | |
| 71 | try expect(fabs32(-1.0) == 1.0); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | test "math.fabs64" { |
| 75 | expect(fabs64(1.0) == 1.0); | |
| 76 | expect(fabs64(-1.0) == 1.0); | |
| 75 | try expect(fabs64(1.0) == 1.0); | |
| 76 | try expect(fabs64(-1.0) == 1.0); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | test "math.fabs128" { |
| 80 | expect(fabs128(1.0) == 1.0); | |
| 81 | expect(fabs128(-1.0) == 1.0); | |
| 80 | try expect(fabs128(1.0) == 1.0); | |
| 81 | try expect(fabs128(-1.0) == 1.0); | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | test "math.fabs16.special" { |
| 85 | expect(math.isPositiveInf(fabs(math.inf(f16)))); | |
| 86 | expect(math.isPositiveInf(fabs(-math.inf(f16)))); | |
| 87 | expect(math.isNan(fabs(math.nan(f16)))); | |
| 85 | try expect(math.isPositiveInf(fabs(math.inf(f16)))); | |
| 86 | try expect(math.isPositiveInf(fabs(-math.inf(f16)))); | |
| 87 | try expect(math.isNan(fabs(math.nan(f16)))); | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | test "math.fabs32.special" { |
| 91 | expect(math.isPositiveInf(fabs(math.inf(f32)))); | |
| 92 | expect(math.isPositiveInf(fabs(-math.inf(f32)))); | |
| 93 | expect(math.isNan(fabs(math.nan(f32)))); | |
| 91 | try expect(math.isPositiveInf(fabs(math.inf(f32)))); | |
| 92 | try expect(math.isPositiveInf(fabs(-math.inf(f32)))); | |
| 93 | try expect(math.isNan(fabs(math.nan(f32)))); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.fabs64.special" { |
| 97 | expect(math.isPositiveInf(fabs(math.inf(f64)))); | |
| 98 | expect(math.isPositiveInf(fabs(-math.inf(f64)))); | |
| 99 | expect(math.isNan(fabs(math.nan(f64)))); | |
| 97 | try expect(math.isPositiveInf(fabs(math.inf(f64)))); | |
| 98 | try expect(math.isPositiveInf(fabs(-math.inf(f64)))); | |
| 99 | try expect(math.isNan(fabs(math.nan(f64)))); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "math.fabs128.special" { |
| 103 | expect(math.isPositiveInf(fabs(math.inf(f128)))); | |
| 104 | expect(math.isPositiveInf(fabs(-math.inf(f128)))); | |
| 105 | expect(math.isNan(fabs(math.nan(f128)))); | |
| 103 | try expect(math.isPositiveInf(fabs(math.inf(f128)))); | |
| 104 | try expect(math.isPositiveInf(fabs(-math.inf(f128)))); | |
| 105 | try expect(math.isNan(fabs(math.nan(f128)))); | |
| 106 | 106 | } |
lib/std/math/floor.zig+36-36| ... | ... | @@ -156,64 +156,64 @@ fn floor128(x: f128) f128 { |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | test "math.floor" { |
| 159 | expect(floor(@as(f16, 1.3)) == floor16(1.3)); | |
| 160 | expect(floor(@as(f32, 1.3)) == floor32(1.3)); | |
| 161 | expect(floor(@as(f64, 1.3)) == floor64(1.3)); | |
| 162 | expect(floor(@as(f128, 1.3)) == floor128(1.3)); | |
| 159 | try expect(floor(@as(f16, 1.3)) == floor16(1.3)); | |
| 160 | try expect(floor(@as(f32, 1.3)) == floor32(1.3)); | |
| 161 | try expect(floor(@as(f64, 1.3)) == floor64(1.3)); | |
| 162 | try expect(floor(@as(f128, 1.3)) == floor128(1.3)); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | test "math.floor16" { |
| 166 | expect(floor16(1.3) == 1.0); | |
| 167 | expect(floor16(-1.3) == -2.0); | |
| 168 | expect(floor16(0.2) == 0.0); | |
| 166 | try expect(floor16(1.3) == 1.0); | |
| 167 | try expect(floor16(-1.3) == -2.0); | |
| 168 | try expect(floor16(0.2) == 0.0); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "math.floor32" { |
| 172 | expect(floor32(1.3) == 1.0); | |
| 173 | expect(floor32(-1.3) == -2.0); | |
| 174 | expect(floor32(0.2) == 0.0); | |
| 172 | try expect(floor32(1.3) == 1.0); | |
| 173 | try expect(floor32(-1.3) == -2.0); | |
| 174 | try expect(floor32(0.2) == 0.0); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | test "math.floor64" { |
| 178 | expect(floor64(1.3) == 1.0); | |
| 179 | expect(floor64(-1.3) == -2.0); | |
| 180 | expect(floor64(0.2) == 0.0); | |
| 178 | try expect(floor64(1.3) == 1.0); | |
| 179 | try expect(floor64(-1.3) == -2.0); | |
| 180 | try expect(floor64(0.2) == 0.0); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | test "math.floor128" { |
| 184 | expect(floor128(1.3) == 1.0); | |
| 185 | expect(floor128(-1.3) == -2.0); | |
| 186 | expect(floor128(0.2) == 0.0); | |
| 184 | try expect(floor128(1.3) == 1.0); | |
| 185 | try expect(floor128(-1.3) == -2.0); | |
| 186 | try expect(floor128(0.2) == 0.0); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "math.floor16.special" { |
| 190 | expect(floor16(0.0) == 0.0); | |
| 191 | expect(floor16(-0.0) == -0.0); | |
| 192 | expect(math.isPositiveInf(floor16(math.inf(f16)))); | |
| 193 | expect(math.isNegativeInf(floor16(-math.inf(f16)))); | |
| 194 | expect(math.isNan(floor16(math.nan(f16)))); | |
| 190 | try expect(floor16(0.0) == 0.0); | |
| 191 | try expect(floor16(-0.0) == -0.0); | |
| 192 | try expect(math.isPositiveInf(floor16(math.inf(f16)))); | |
| 193 | try expect(math.isNegativeInf(floor16(-math.inf(f16)))); | |
| 194 | try expect(math.isNan(floor16(math.nan(f16)))); | |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | test "math.floor32.special" { |
| 198 | expect(floor32(0.0) == 0.0); | |
| 199 | expect(floor32(-0.0) == -0.0); | |
| 200 | expect(math.isPositiveInf(floor32(math.inf(f32)))); | |
| 201 | expect(math.isNegativeInf(floor32(-math.inf(f32)))); | |
| 202 | expect(math.isNan(floor32(math.nan(f32)))); | |
| 198 | try expect(floor32(0.0) == 0.0); | |
| 199 | try expect(floor32(-0.0) == -0.0); | |
| 200 | try expect(math.isPositiveInf(floor32(math.inf(f32)))); | |
| 201 | try expect(math.isNegativeInf(floor32(-math.inf(f32)))); | |
| 202 | try expect(math.isNan(floor32(math.nan(f32)))); | |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | test "math.floor64.special" { |
| 206 | expect(floor64(0.0) == 0.0); | |
| 207 | expect(floor64(-0.0) == -0.0); | |
| 208 | expect(math.isPositiveInf(floor64(math.inf(f64)))); | |
| 209 | expect(math.isNegativeInf(floor64(-math.inf(f64)))); | |
| 210 | expect(math.isNan(floor64(math.nan(f64)))); | |
| 206 | try expect(floor64(0.0) == 0.0); | |
| 207 | try expect(floor64(-0.0) == -0.0); | |
| 208 | try expect(math.isPositiveInf(floor64(math.inf(f64)))); | |
| 209 | try expect(math.isNegativeInf(floor64(-math.inf(f64)))); | |
| 210 | try expect(math.isNan(floor64(math.nan(f64)))); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | test "math.floor128.special" { |
| 214 | expect(floor128(0.0) == 0.0); | |
| 215 | expect(floor128(-0.0) == -0.0); | |
| 216 | expect(math.isPositiveInf(floor128(math.inf(f128)))); | |
| 217 | expect(math.isNegativeInf(floor128(-math.inf(f128)))); | |
| 218 | expect(math.isNan(floor128(math.nan(f128)))); | |
| 214 | try expect(floor128(0.0) == 0.0); | |
| 215 | try expect(floor128(-0.0) == -0.0); | |
| 216 | try expect(math.isPositiveInf(floor128(math.inf(f128)))); | |
| 217 | try expect(math.isNegativeInf(floor128(-math.inf(f128)))); | |
| 218 | try expect(math.isNan(floor128(math.nan(f128)))); | |
| 219 | 219 | } |
lib/std/math/fma.zig+16-16| ... | ... | @@ -148,30 +148,30 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 { |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "math.fma" { |
| 151 | expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0)); | |
| 152 | expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0)); | |
| 151 | try expect(fma(f32, 0.0, 1.0, 1.0) == fma32(0.0, 1.0, 1.0)); | |
| 152 | try expect(fma(f64, 0.0, 1.0, 1.0) == fma64(0.0, 1.0, 1.0)); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | test "math.fma32" { |
| 156 | 156 | const epsilon = 0.000001; |
| 157 | 157 | |
| 158 | expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 159 | expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 160 | expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 161 | expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 162 | expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon)); | |
| 163 | expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon)); | |
| 164 | expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 158 | try expect(math.approxEqAbs(f32, fma32(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 159 | try expect(math.approxEqAbs(f32, fma32(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 160 | try expect(math.approxEqAbs(f32, fma32(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 161 | try expect(math.approxEqAbs(f32, fma32(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 162 | try expect(math.approxEqAbs(f32, fma32(37.45, 5.0, 9.124), 196.374004, epsilon)); | |
| 163 | try expect(math.approxEqAbs(f32, fma32(89.123, 5.0, 9.124), 454.739005, epsilon)); | |
| 164 | try expect(math.approxEqAbs(f32, fma32(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | test "math.fma64" { |
| 168 | 168 | const epsilon = 0.000001; |
| 169 | 169 | |
| 170 | expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 171 | expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 172 | expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 173 | expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 174 | expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon)); | |
| 175 | expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon)); | |
| 176 | expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 170 | try expect(math.approxEqAbs(f64, fma64(0.0, 5.0, 9.124), 9.124, epsilon)); | |
| 171 | try expect(math.approxEqAbs(f64, fma64(0.2, 5.0, 9.124), 10.124, epsilon)); | |
| 172 | try expect(math.approxEqAbs(f64, fma64(0.8923, 5.0, 9.124), 13.5855, epsilon)); | |
| 173 | try expect(math.approxEqAbs(f64, fma64(1.5, 5.0, 9.124), 16.624, epsilon)); | |
| 174 | try expect(math.approxEqAbs(f64, fma64(37.45, 5.0, 9.124), 196.374, epsilon)); | |
| 175 | try expect(math.approxEqAbs(f64, fma64(89.123, 5.0, 9.124), 454.739, epsilon)); | |
| 176 | try expect(math.approxEqAbs(f64, fma64(123123.234375, 5.0, 9.124), 615625.295875, epsilon)); | |
| 177 | 177 | } |
lib/std/math/frexp.zig+16-16| ... | ... | @@ -115,11 +115,11 @@ fn frexp64(x: f64) frexp64_result { |
| 115 | 115 | test "math.frexp" { |
| 116 | 116 | const a = frexp(@as(f32, 1.3)); |
| 117 | 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); | |
| 119 | 119 | |
| 120 | 120 | const c = frexp(@as(f64, 1.3)); |
| 121 | 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 | } |
| 124 | 124 | |
| 125 | 125 | test "math.frexp32" { |
| ... | ... | @@ -127,10 +127,10 @@ test "math.frexp32" { |
| 127 | 127 | var r: frexp32_result = undefined; |
| 128 | 128 | |
| 129 | 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); | |
| 131 | 131 | |
| 132 | 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 | } |
| 135 | 135 | |
| 136 | 136 | test "math.frexp64" { |
| ... | ... | @@ -138,46 +138,46 @@ test "math.frexp64" { |
| 138 | 138 | var r: frexp64_result = undefined; |
| 139 | 139 | |
| 140 | 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); | |
| 142 | 142 | |
| 143 | 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 | } |
| 146 | 146 | |
| 147 | 147 | test "math.frexp32.special" { |
| 148 | 148 | var r: frexp32_result = undefined; |
| 149 | 149 | |
| 150 | 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); | |
| 152 | 152 | |
| 153 | 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); | |
| 155 | 155 | |
| 156 | 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); | |
| 158 | 158 | |
| 159 | 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); | |
| 161 | 161 | |
| 162 | 162 | r = frexp32(math.nan(f32)); |
| 163 | expect(math.isNan(r.significand)); | |
| 163 | try expect(math.isNan(r.significand)); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | test "math.frexp64.special" { |
| 167 | 167 | var r: frexp64_result = undefined; |
| 168 | 168 | |
| 169 | 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); | |
| 171 | 171 | |
| 172 | 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); | |
| 174 | 174 | |
| 175 | 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); | |
| 177 | 177 | |
| 178 | 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); | |
| 180 | 180 | |
| 181 | 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 | 126 | } |
| 127 | 127 | |
| 128 | 128 | test "math.hypot" { |
| 129 | expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2)); | |
| 130 | expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2)); | |
| 129 | try expect(hypot(f32, 0.0, -1.2) == hypot32(0.0, -1.2)); | |
| 130 | try expect(hypot(f64, 0.0, -1.2) == hypot64(0.0, -1.2)); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "math.hypot32" { |
| 134 | 134 | const epsilon = 0.000001; |
| 135 | 135 | |
| 136 | expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon)); | |
| 137 | expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon)); | |
| 138 | expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon)); | |
| 139 | expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon)); | |
| 140 | expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon)); | |
| 141 | expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon)); | |
| 142 | expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon)); | |
| 136 | try expect(math.approxEqAbs(f32, hypot32(0.0, -1.2), 1.2, epsilon)); | |
| 137 | try expect(math.approxEqAbs(f32, hypot32(0.2, -0.34), 0.394462, epsilon)); | |
| 138 | try expect(math.approxEqAbs(f32, hypot32(0.8923, 2.636890), 2.783772, epsilon)); | |
| 139 | try expect(math.approxEqAbs(f32, hypot32(1.5, 5.25), 5.460083, epsilon)); | |
| 140 | try expect(math.approxEqAbs(f32, hypot32(37.45, 159.835), 164.163742, epsilon)); | |
| 141 | try expect(math.approxEqAbs(f32, hypot32(89.123, 382.028905), 392.286865, epsilon)); | |
| 142 | try expect(math.approxEqAbs(f32, hypot32(123123.234375, 529428.707813), 543556.875, epsilon)); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "math.hypot64" { |
| 146 | 146 | const epsilon = 0.000001; |
| 147 | 147 | |
| 148 | expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon)); | |
| 149 | expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon)); | |
| 150 | expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon)); | |
| 151 | expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon)); | |
| 152 | expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon)); | |
| 153 | expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon)); | |
| 154 | expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon)); | |
| 148 | try expect(math.approxEqAbs(f64, hypot64(0.0, -1.2), 1.2, epsilon)); | |
| 149 | try expect(math.approxEqAbs(f64, hypot64(0.2, -0.34), 0.394462, epsilon)); | |
| 150 | try expect(math.approxEqAbs(f64, hypot64(0.8923, 2.636890), 2.783772, epsilon)); | |
| 151 | try expect(math.approxEqAbs(f64, hypot64(1.5, 5.25), 5.460082, epsilon)); | |
| 152 | try expect(math.approxEqAbs(f64, hypot64(37.45, 159.835), 164.163728, epsilon)); | |
| 153 | try expect(math.approxEqAbs(f64, hypot64(89.123, 382.028905), 392.286876, epsilon)); | |
| 154 | try expect(math.approxEqAbs(f64, hypot64(123123.234375, 529428.707813), 543556.885247, epsilon)); | |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | test "math.hypot32.special" { |
| 158 | expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0))); | |
| 159 | expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0))); | |
| 160 | expect(math.isPositiveInf(hypot32(0.0, math.inf(f32)))); | |
| 161 | expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32)))); | |
| 162 | expect(math.isNan(hypot32(math.nan(f32), 0.0))); | |
| 163 | expect(math.isNan(hypot32(0.0, math.nan(f32)))); | |
| 158 | try expect(math.isPositiveInf(hypot32(math.inf(f32), 0.0))); | |
| 159 | try expect(math.isPositiveInf(hypot32(-math.inf(f32), 0.0))); | |
| 160 | try expect(math.isPositiveInf(hypot32(0.0, math.inf(f32)))); | |
| 161 | try expect(math.isPositiveInf(hypot32(0.0, -math.inf(f32)))); | |
| 162 | try expect(math.isNan(hypot32(math.nan(f32), 0.0))); | |
| 163 | try expect(math.isNan(hypot32(0.0, math.nan(f32)))); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | test "math.hypot64.special" { |
| 167 | expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0))); | |
| 168 | expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0))); | |
| 169 | expect(math.isPositiveInf(hypot64(0.0, math.inf(f64)))); | |
| 170 | expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64)))); | |
| 171 | expect(math.isNan(hypot64(math.nan(f64), 0.0))); | |
| 172 | expect(math.isNan(hypot64(0.0, math.nan(f64)))); | |
| 167 | try expect(math.isPositiveInf(hypot64(math.inf(f64), 0.0))); | |
| 168 | try expect(math.isPositiveInf(hypot64(-math.inf(f64), 0.0))); | |
| 169 | try expect(math.isPositiveInf(hypot64(0.0, math.inf(f64)))); | |
| 170 | try expect(math.isPositiveInf(hypot64(0.0, -math.inf(f64)))); | |
| 171 | try expect(math.isNan(hypot64(math.nan(f64), 0.0))); | |
| 172 | try expect(math.isNan(hypot64(0.0, math.nan(f64)))); | |
| 173 | 173 | } |
lib/std/math/ilogb.zig+22-22| ... | ... | @@ -106,38 +106,38 @@ fn ilogb64(x: f64) i32 { |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | test "math.ilogb" { |
| 109 | expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2)); | |
| 110 | expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2)); | |
| 109 | try expect(ilogb(@as(f32, 0.2)) == ilogb32(0.2)); | |
| 110 | try expect(ilogb(@as(f64, 0.2)) == ilogb64(0.2)); | |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "math.ilogb32" { |
| 114 | expect(ilogb32(0.0) == fp_ilogb0); | |
| 115 | expect(ilogb32(0.5) == -1); | |
| 116 | expect(ilogb32(0.8923) == -1); | |
| 117 | expect(ilogb32(10.0) == 3); | |
| 118 | expect(ilogb32(-123984) == 16); | |
| 119 | expect(ilogb32(2398.23) == 11); | |
| 114 | try expect(ilogb32(0.0) == fp_ilogb0); | |
| 115 | try expect(ilogb32(0.5) == -1); | |
| 116 | try expect(ilogb32(0.8923) == -1); | |
| 117 | try expect(ilogb32(10.0) == 3); | |
| 118 | try expect(ilogb32(-123984) == 16); | |
| 119 | try expect(ilogb32(2398.23) == 11); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | test "math.ilogb64" { |
| 123 | expect(ilogb64(0.0) == fp_ilogb0); | |
| 124 | expect(ilogb64(0.5) == -1); | |
| 125 | expect(ilogb64(0.8923) == -1); | |
| 126 | expect(ilogb64(10.0) == 3); | |
| 127 | expect(ilogb64(-123984) == 16); | |
| 128 | expect(ilogb64(2398.23) == 11); | |
| 123 | try expect(ilogb64(0.0) == fp_ilogb0); | |
| 124 | try expect(ilogb64(0.5) == -1); | |
| 125 | try expect(ilogb64(0.8923) == -1); | |
| 126 | try expect(ilogb64(10.0) == 3); | |
| 127 | try expect(ilogb64(-123984) == 16); | |
| 128 | try expect(ilogb64(2398.23) == 11); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.ilogb32.special" { |
| 132 | expect(ilogb32(math.inf(f32)) == maxInt(i32)); | |
| 133 | expect(ilogb32(-math.inf(f32)) == maxInt(i32)); | |
| 134 | expect(ilogb32(0.0) == minInt(i32)); | |
| 135 | expect(ilogb32(math.nan(f32)) == maxInt(i32)); | |
| 132 | try expect(ilogb32(math.inf(f32)) == maxInt(i32)); | |
| 133 | try expect(ilogb32(-math.inf(f32)) == maxInt(i32)); | |
| 134 | try expect(ilogb32(0.0) == minInt(i32)); | |
| 135 | try expect(ilogb32(math.nan(f32)) == maxInt(i32)); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "math.ilogb64.special" { |
| 139 | expect(ilogb64(math.inf(f64)) == maxInt(i32)); | |
| 140 | expect(ilogb64(-math.inf(f64)) == maxInt(i32)); | |
| 141 | expect(ilogb64(0.0) == minInt(i32)); | |
| 142 | expect(ilogb64(math.nan(f64)) == maxInt(i32)); | |
| 139 | try expect(ilogb64(math.inf(f64)) == maxInt(i32)); | |
| 140 | try expect(ilogb64(-math.inf(f64)) == maxInt(i32)); | |
| 141 | try expect(ilogb64(0.0) == minInt(i32)); | |
| 142 | try expect(ilogb64(math.nan(f64)) == maxInt(i32)); | |
| 143 | 143 | } |
lib/std/math/isfinite.zig+24-24| ... | ... | @@ -35,30 +35,30 @@ pub fn isFinite(x: anytype) bool { |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test "math.isFinite" { |
| 38 | expect(isFinite(@as(f16, 0.0))); | |
| 39 | expect(isFinite(@as(f16, -0.0))); | |
| 40 | expect(isFinite(@as(f32, 0.0))); | |
| 41 | expect(isFinite(@as(f32, -0.0))); | |
| 42 | expect(isFinite(@as(f64, 0.0))); | |
| 43 | expect(isFinite(@as(f64, -0.0))); | |
| 44 | expect(isFinite(@as(f128, 0.0))); | |
| 45 | expect(isFinite(@as(f128, -0.0))); | |
| 38 | try expect(isFinite(@as(f16, 0.0))); | |
| 39 | try expect(isFinite(@as(f16, -0.0))); | |
| 40 | try expect(isFinite(@as(f32, 0.0))); | |
| 41 | try expect(isFinite(@as(f32, -0.0))); | |
| 42 | try expect(isFinite(@as(f64, 0.0))); | |
| 43 | try expect(isFinite(@as(f64, -0.0))); | |
| 44 | try expect(isFinite(@as(f128, 0.0))); | |
| 45 | try expect(isFinite(@as(f128, -0.0))); | |
| 46 | 46 | |
| 47 | expect(!isFinite(math.inf(f16))); | |
| 48 | expect(!isFinite(-math.inf(f16))); | |
| 49 | expect(!isFinite(math.inf(f32))); | |
| 50 | expect(!isFinite(-math.inf(f32))); | |
| 51 | expect(!isFinite(math.inf(f64))); | |
| 52 | expect(!isFinite(-math.inf(f64))); | |
| 53 | expect(!isFinite(math.inf(f128))); | |
| 54 | expect(!isFinite(-math.inf(f128))); | |
| 47 | try expect(!isFinite(math.inf(f16))); | |
| 48 | try expect(!isFinite(-math.inf(f16))); | |
| 49 | try expect(!isFinite(math.inf(f32))); | |
| 50 | try expect(!isFinite(-math.inf(f32))); | |
| 51 | try expect(!isFinite(math.inf(f64))); | |
| 52 | try expect(!isFinite(-math.inf(f64))); | |
| 53 | try expect(!isFinite(math.inf(f128))); | |
| 54 | try expect(!isFinite(-math.inf(f128))); | |
| 55 | 55 | |
| 56 | expect(!isFinite(math.nan(f16))); | |
| 57 | expect(!isFinite(-math.nan(f16))); | |
| 58 | expect(!isFinite(math.nan(f32))); | |
| 59 | expect(!isFinite(-math.nan(f32))); | |
| 60 | expect(!isFinite(math.nan(f64))); | |
| 61 | expect(!isFinite(-math.nan(f64))); | |
| 62 | expect(!isFinite(math.nan(f128))); | |
| 63 | expect(!isFinite(-math.nan(f128))); | |
| 56 | try expect(!isFinite(math.nan(f16))); | |
| 57 | try expect(!isFinite(-math.nan(f16))); | |
| 58 | try expect(!isFinite(math.nan(f32))); | |
| 59 | try expect(!isFinite(-math.nan(f32))); | |
| 60 | try expect(!isFinite(math.nan(f64))); | |
| 61 | try expect(!isFinite(-math.nan(f64))); | |
| 62 | try expect(!isFinite(math.nan(f128))); | |
| 63 | try expect(!isFinite(-math.nan(f128))); | |
| 64 | 64 | } |
lib/std/math/isinf.zig+48-48| ... | ... | @@ -79,58 +79,58 @@ pub fn isNegativeInf(x: anytype) bool { |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | test "math.isInf" { |
| 82 | expect(!isInf(@as(f16, 0.0))); | |
| 83 | expect(!isInf(@as(f16, -0.0))); | |
| 84 | expect(!isInf(@as(f32, 0.0))); | |
| 85 | expect(!isInf(@as(f32, -0.0))); | |
| 86 | expect(!isInf(@as(f64, 0.0))); | |
| 87 | expect(!isInf(@as(f64, -0.0))); | |
| 88 | expect(!isInf(@as(f128, 0.0))); | |
| 89 | expect(!isInf(@as(f128, -0.0))); | |
| 90 | expect(isInf(math.inf(f16))); | |
| 91 | expect(isInf(-math.inf(f16))); | |
| 92 | expect(isInf(math.inf(f32))); | |
| 93 | expect(isInf(-math.inf(f32))); | |
| 94 | expect(isInf(math.inf(f64))); | |
| 95 | expect(isInf(-math.inf(f64))); | |
| 96 | expect(isInf(math.inf(f128))); | |
| 97 | expect(isInf(-math.inf(f128))); | |
| 82 | try expect(!isInf(@as(f16, 0.0))); | |
| 83 | try expect(!isInf(@as(f16, -0.0))); | |
| 84 | try expect(!isInf(@as(f32, 0.0))); | |
| 85 | try expect(!isInf(@as(f32, -0.0))); | |
| 86 | try expect(!isInf(@as(f64, 0.0))); | |
| 87 | try expect(!isInf(@as(f64, -0.0))); | |
| 88 | try expect(!isInf(@as(f128, 0.0))); | |
| 89 | try expect(!isInf(@as(f128, -0.0))); | |
| 90 | try expect(isInf(math.inf(f16))); | |
| 91 | try expect(isInf(-math.inf(f16))); | |
| 92 | try expect(isInf(math.inf(f32))); | |
| 93 | try expect(isInf(-math.inf(f32))); | |
| 94 | try expect(isInf(math.inf(f64))); | |
| 95 | try expect(isInf(-math.inf(f64))); | |
| 96 | try expect(isInf(math.inf(f128))); | |
| 97 | try expect(isInf(-math.inf(f128))); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "math.isPositiveInf" { |
| 101 | expect(!isPositiveInf(@as(f16, 0.0))); | |
| 102 | expect(!isPositiveInf(@as(f16, -0.0))); | |
| 103 | expect(!isPositiveInf(@as(f32, 0.0))); | |
| 104 | expect(!isPositiveInf(@as(f32, -0.0))); | |
| 105 | expect(!isPositiveInf(@as(f64, 0.0))); | |
| 106 | expect(!isPositiveInf(@as(f64, -0.0))); | |
| 107 | expect(!isPositiveInf(@as(f128, 0.0))); | |
| 108 | expect(!isPositiveInf(@as(f128, -0.0))); | |
| 109 | expect(isPositiveInf(math.inf(f16))); | |
| 110 | expect(!isPositiveInf(-math.inf(f16))); | |
| 111 | expect(isPositiveInf(math.inf(f32))); | |
| 112 | expect(!isPositiveInf(-math.inf(f32))); | |
| 113 | expect(isPositiveInf(math.inf(f64))); | |
| 114 | expect(!isPositiveInf(-math.inf(f64))); | |
| 115 | expect(isPositiveInf(math.inf(f128))); | |
| 116 | expect(!isPositiveInf(-math.inf(f128))); | |
| 101 | try expect(!isPositiveInf(@as(f16, 0.0))); | |
| 102 | try expect(!isPositiveInf(@as(f16, -0.0))); | |
| 103 | try expect(!isPositiveInf(@as(f32, 0.0))); | |
| 104 | try expect(!isPositiveInf(@as(f32, -0.0))); | |
| 105 | try expect(!isPositiveInf(@as(f64, 0.0))); | |
| 106 | try expect(!isPositiveInf(@as(f64, -0.0))); | |
| 107 | try expect(!isPositiveInf(@as(f128, 0.0))); | |
| 108 | try expect(!isPositiveInf(@as(f128, -0.0))); | |
| 109 | try expect(isPositiveInf(math.inf(f16))); | |
| 110 | try expect(!isPositiveInf(-math.inf(f16))); | |
| 111 | try expect(isPositiveInf(math.inf(f32))); | |
| 112 | try expect(!isPositiveInf(-math.inf(f32))); | |
| 113 | try expect(isPositiveInf(math.inf(f64))); | |
| 114 | try expect(!isPositiveInf(-math.inf(f64))); | |
| 115 | try expect(isPositiveInf(math.inf(f128))); | |
| 116 | try expect(!isPositiveInf(-math.inf(f128))); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "math.isNegativeInf" { |
| 120 | expect(!isNegativeInf(@as(f16, 0.0))); | |
| 121 | expect(!isNegativeInf(@as(f16, -0.0))); | |
| 122 | expect(!isNegativeInf(@as(f32, 0.0))); | |
| 123 | expect(!isNegativeInf(@as(f32, -0.0))); | |
| 124 | expect(!isNegativeInf(@as(f64, 0.0))); | |
| 125 | expect(!isNegativeInf(@as(f64, -0.0))); | |
| 126 | expect(!isNegativeInf(@as(f128, 0.0))); | |
| 127 | expect(!isNegativeInf(@as(f128, -0.0))); | |
| 128 | expect(!isNegativeInf(math.inf(f16))); | |
| 129 | expect(isNegativeInf(-math.inf(f16))); | |
| 130 | expect(!isNegativeInf(math.inf(f32))); | |
| 131 | expect(isNegativeInf(-math.inf(f32))); | |
| 132 | expect(!isNegativeInf(math.inf(f64))); | |
| 133 | expect(isNegativeInf(-math.inf(f64))); | |
| 134 | expect(!isNegativeInf(math.inf(f128))); | |
| 135 | expect(isNegativeInf(-math.inf(f128))); | |
| 120 | try expect(!isNegativeInf(@as(f16, 0.0))); | |
| 121 | try expect(!isNegativeInf(@as(f16, -0.0))); | |
| 122 | try expect(!isNegativeInf(@as(f32, 0.0))); | |
| 123 | try expect(!isNegativeInf(@as(f32, -0.0))); | |
| 124 | try expect(!isNegativeInf(@as(f64, 0.0))); | |
| 125 | try expect(!isNegativeInf(@as(f64, -0.0))); | |
| 126 | try expect(!isNegativeInf(@as(f128, 0.0))); | |
| 127 | try expect(!isNegativeInf(@as(f128, -0.0))); | |
| 128 | try expect(!isNegativeInf(math.inf(f16))); | |
| 129 | try expect(isNegativeInf(-math.inf(f16))); | |
| 130 | try expect(!isNegativeInf(math.inf(f32))); | |
| 131 | try expect(isNegativeInf(-math.inf(f32))); | |
| 132 | try expect(!isNegativeInf(math.inf(f64))); | |
| 133 | try expect(isNegativeInf(-math.inf(f64))); | |
| 134 | try expect(!isNegativeInf(math.inf(f128))); | |
| 135 | try expect(isNegativeInf(-math.inf(f128))); | |
| 136 | 136 | } |
lib/std/math/isnan.zig+8-8| ... | ... | @@ -21,12 +21,12 @@ pub fn isSignalNan(x: anytype) bool { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "math.isNan" { |
| 24 | expect(isNan(math.nan(f16))); | |
| 25 | expect(isNan(math.nan(f32))); | |
| 26 | expect(isNan(math.nan(f64))); | |
| 27 | expect(isNan(math.nan(f128))); | |
| 28 | expect(!isNan(@as(f16, 1.0))); | |
| 29 | expect(!isNan(@as(f32, 1.0))); | |
| 30 | expect(!isNan(@as(f64, 1.0))); | |
| 31 | expect(!isNan(@as(f128, 1.0))); | |
| 24 | try expect(isNan(math.nan(f16))); | |
| 25 | try expect(isNan(math.nan(f32))); | |
| 26 | try expect(isNan(math.nan(f64))); | |
| 27 | try expect(isNan(math.nan(f128))); | |
| 28 | try expect(!isNan(@as(f16, 1.0))); | |
| 29 | try expect(!isNan(@as(f32, 1.0))); | |
| 30 | try expect(!isNan(@as(f64, 1.0))); | |
| 31 | try expect(!isNan(@as(f128, 1.0))); | |
| 32 | 32 | } |
lib/std/math/isnormal.zig+9-9| ... | ... | @@ -31,13 +31,13 @@ pub fn isNormal(x: anytype) bool { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | test "math.isNormal" { |
| 34 | expect(!isNormal(math.nan(f16))); | |
| 35 | expect(!isNormal(math.nan(f32))); | |
| 36 | expect(!isNormal(math.nan(f64))); | |
| 37 | expect(!isNormal(@as(f16, 0))); | |
| 38 | expect(!isNormal(@as(f32, 0))); | |
| 39 | expect(!isNormal(@as(f64, 0))); | |
| 40 | expect(isNormal(@as(f16, 1.0))); | |
| 41 | expect(isNormal(@as(f32, 1.0))); | |
| 42 | expect(isNormal(@as(f64, 1.0))); | |
| 34 | try expect(!isNormal(math.nan(f16))); | |
| 35 | try expect(!isNormal(math.nan(f32))); | |
| 36 | try expect(!isNormal(math.nan(f64))); | |
| 37 | try expect(!isNormal(@as(f16, 0))); | |
| 38 | try expect(!isNormal(@as(f32, 0))); | |
| 39 | try expect(!isNormal(@as(f64, 0))); | |
| 40 | try expect(isNormal(@as(f16, 1.0))); | |
| 41 | try expect(isNormal(@as(f32, 1.0))); | |
| 42 | try expect(isNormal(@as(f64, 1.0))); | |
| 43 | 43 | } |
lib/std/math/ln.zig+22-22| ... | ... | @@ -153,42 +153,42 @@ pub fn ln_64(x_: f64) f64 { |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | test "math.ln" { |
| 156 | expect(ln(@as(f32, 0.2)) == ln_32(0.2)); | |
| 157 | expect(ln(@as(f64, 0.2)) == ln_64(0.2)); | |
| 156 | try expect(ln(@as(f32, 0.2)) == ln_32(0.2)); | |
| 157 | try expect(ln(@as(f64, 0.2)) == ln_64(0.2)); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | test "math.ln32" { |
| 161 | 161 | const epsilon = 0.000001; |
| 162 | 162 | |
| 163 | expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon)); | |
| 164 | expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon)); | |
| 165 | expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon)); | |
| 166 | expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon)); | |
| 167 | expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon)); | |
| 168 | expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon)); | |
| 163 | try expect(math.approxEqAbs(f32, ln_32(0.2), -1.609438, epsilon)); | |
| 164 | try expect(math.approxEqAbs(f32, ln_32(0.8923), -0.113953, epsilon)); | |
| 165 | try expect(math.approxEqAbs(f32, ln_32(1.5), 0.405465, epsilon)); | |
| 166 | try expect(math.approxEqAbs(f32, ln_32(37.45), 3.623007, epsilon)); | |
| 167 | try expect(math.approxEqAbs(f32, ln_32(89.123), 4.490017, epsilon)); | |
| 168 | try expect(math.approxEqAbs(f32, ln_32(123123.234375), 11.720941, epsilon)); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "math.ln64" { |
| 172 | 172 | const epsilon = 0.000001; |
| 173 | 173 | |
| 174 | expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon)); | |
| 175 | expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon)); | |
| 176 | expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon)); | |
| 177 | expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon)); | |
| 178 | expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon)); | |
| 179 | expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon)); | |
| 174 | try expect(math.approxEqAbs(f64, ln_64(0.2), -1.609438, epsilon)); | |
| 175 | try expect(math.approxEqAbs(f64, ln_64(0.8923), -0.113953, epsilon)); | |
| 176 | try expect(math.approxEqAbs(f64, ln_64(1.5), 0.405465, epsilon)); | |
| 177 | try expect(math.approxEqAbs(f64, ln_64(37.45), 3.623007, epsilon)); | |
| 178 | try expect(math.approxEqAbs(f64, ln_64(89.123), 4.490017, epsilon)); | |
| 179 | try expect(math.approxEqAbs(f64, ln_64(123123.234375), 11.720941, epsilon)); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | test "math.ln32.special" { |
| 183 | expect(math.isPositiveInf(ln_32(math.inf(f32)))); | |
| 184 | expect(math.isNegativeInf(ln_32(0.0))); | |
| 185 | expect(math.isNan(ln_32(-1.0))); | |
| 186 | expect(math.isNan(ln_32(math.nan(f32)))); | |
| 183 | try expect(math.isPositiveInf(ln_32(math.inf(f32)))); | |
| 184 | try expect(math.isNegativeInf(ln_32(0.0))); | |
| 185 | try expect(math.isNan(ln_32(-1.0))); | |
| 186 | try expect(math.isNan(ln_32(math.nan(f32)))); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "math.ln64.special" { |
| 190 | expect(math.isPositiveInf(ln_64(math.inf(f64)))); | |
| 191 | expect(math.isNegativeInf(ln_64(0.0))); | |
| 192 | expect(math.isNan(ln_64(-1.0))); | |
| 193 | expect(math.isNan(ln_64(math.nan(f64)))); | |
| 190 | try expect(math.isPositiveInf(ln_64(math.inf(f64)))); | |
| 191 | try expect(math.isNegativeInf(ln_64(0.0))); | |
| 192 | try expect(math.isNan(ln_64(-1.0))); | |
| 193 | try expect(math.isNan(ln_64(math.nan(f64)))); | |
| 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 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "math.log integer" { |
| 56 | expect(log(u8, 2, 0x1) == 0); | |
| 57 | expect(log(u8, 2, 0x2) == 1); | |
| 58 | expect(log(u16, 2, 0x72) == 6); | |
| 59 | expect(log(u32, 2, 0xFFFFFF) == 23); | |
| 60 | expect(log(u64, 2, 0x7FF0123456789ABC) == 62); | |
| 56 | try expect(log(u8, 2, 0x1) == 0); | |
| 57 | try expect(log(u8, 2, 0x2) == 1); | |
| 58 | try expect(log(u16, 2, 0x72) == 6); | |
| 59 | try expect(log(u32, 2, 0xFFFFFF) == 23); | |
| 60 | try expect(log(u64, 2, 0x7FF0123456789ABC) == 62); | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | test "math.log float" { |
| 64 | 64 | const epsilon = 0.000001; |
| 65 | 65 | |
| 66 | expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon)); | |
| 67 | expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon)); | |
| 68 | expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon)); | |
| 66 | try expect(math.approxEqAbs(f32, log(f32, 6, 0.23947), -0.797723, epsilon)); | |
| 67 | try expect(math.approxEqAbs(f32, log(f32, 89, 0.23947), -0.318432, epsilon)); | |
| 68 | try expect(math.approxEqAbs(f64, log(f64, 123897, 12389216414), 1.981724596, epsilon)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "math.log float_special" { |
| 72 | expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974))); | |
| 73 | expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974))); | |
| 72 | try expect(log(f32, 2, 0.2301974) == math.log2(@as(f32, 0.2301974))); | |
| 73 | try expect(log(f32, 10, 0.2301974) == math.log10(@as(f32, 0.2301974))); | |
| 74 | 74 | |
| 75 | expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993))); | |
| 76 | expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993))); | |
| 75 | try expect(log(f64, 2, 213.23019799993) == math.log2(@as(f64, 213.23019799993))); | |
| 76 | try expect(log(f64, 10, 213.23019799993) == math.log10(@as(f64, 213.23019799993))); | |
| 77 | 77 | } |
lib/std/math/log10.zig+22-22| ... | ... | @@ -181,42 +181,42 @@ pub fn log10_64(x_: f64) f64 { |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | test "math.log10" { |
| 184 | testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2)); | |
| 185 | testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2)); | |
| 184 | try testing.expect(log10(@as(f32, 0.2)) == log10_32(0.2)); | |
| 185 | try testing.expect(log10(@as(f64, 0.2)) == log10_64(0.2)); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | test "math.log10_32" { |
| 189 | 189 | const epsilon = 0.000001; |
| 190 | 190 | |
| 191 | testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon)); | |
| 192 | testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon)); | |
| 193 | testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon)); | |
| 194 | testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon)); | |
| 195 | testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon)); | |
| 196 | testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon)); | |
| 191 | try testing.expect(math.approxEqAbs(f32, log10_32(0.2), -0.698970, epsilon)); | |
| 192 | try testing.expect(math.approxEqAbs(f32, log10_32(0.8923), -0.049489, epsilon)); | |
| 193 | try testing.expect(math.approxEqAbs(f32, log10_32(1.5), 0.176091, epsilon)); | |
| 194 | try testing.expect(math.approxEqAbs(f32, log10_32(37.45), 1.573452, epsilon)); | |
| 195 | try testing.expect(math.approxEqAbs(f32, log10_32(89.123), 1.94999, epsilon)); | |
| 196 | try testing.expect(math.approxEqAbs(f32, log10_32(123123.234375), 5.09034, epsilon)); | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | test "math.log10_64" { |
| 200 | 200 | const epsilon = 0.000001; |
| 201 | 201 | |
| 202 | testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon)); | |
| 203 | testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon)); | |
| 204 | testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon)); | |
| 205 | testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon)); | |
| 206 | testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon)); | |
| 207 | testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon)); | |
| 202 | try testing.expect(math.approxEqAbs(f64, log10_64(0.2), -0.698970, epsilon)); | |
| 203 | try testing.expect(math.approxEqAbs(f64, log10_64(0.8923), -0.049489, epsilon)); | |
| 204 | try testing.expect(math.approxEqAbs(f64, log10_64(1.5), 0.176091, epsilon)); | |
| 205 | try testing.expect(math.approxEqAbs(f64, log10_64(37.45), 1.573452, epsilon)); | |
| 206 | try testing.expect(math.approxEqAbs(f64, log10_64(89.123), 1.94999, epsilon)); | |
| 207 | try testing.expect(math.approxEqAbs(f64, log10_64(123123.234375), 5.09034, epsilon)); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | test "math.log10_32.special" { |
| 211 | testing.expect(math.isPositiveInf(log10_32(math.inf(f32)))); | |
| 212 | testing.expect(math.isNegativeInf(log10_32(0.0))); | |
| 213 | testing.expect(math.isNan(log10_32(-1.0))); | |
| 214 | testing.expect(math.isNan(log10_32(math.nan(f32)))); | |
| 211 | try testing.expect(math.isPositiveInf(log10_32(math.inf(f32)))); | |
| 212 | try testing.expect(math.isNegativeInf(log10_32(0.0))); | |
| 213 | try testing.expect(math.isNan(log10_32(-1.0))); | |
| 214 | try testing.expect(math.isNan(log10_32(math.nan(f32)))); | |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | test "math.log10_64.special" { |
| 218 | testing.expect(math.isPositiveInf(log10_64(math.inf(f64)))); | |
| 219 | testing.expect(math.isNegativeInf(log10_64(0.0))); | |
| 220 | testing.expect(math.isNan(log10_64(-1.0))); | |
| 221 | testing.expect(math.isNan(log10_64(math.nan(f64)))); | |
| 218 | try testing.expect(math.isPositiveInf(log10_64(math.inf(f64)))); | |
| 219 | try testing.expect(math.isNegativeInf(log10_64(0.0))); | |
| 220 | try testing.expect(math.isNan(log10_64(-1.0))); | |
| 221 | try testing.expect(math.isNan(log10_64(math.nan(f64)))); | |
| 222 | 222 | } |
lib/std/math/log1p.zig+28-28| ... | ... | @@ -188,48 +188,48 @@ fn log1p_64(x: f64) f64 { |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "math.log1p" { |
| 191 | expect(log1p(@as(f32, 0.0)) == log1p_32(0.0)); | |
| 192 | expect(log1p(@as(f64, 0.0)) == log1p_64(0.0)); | |
| 191 | try expect(log1p(@as(f32, 0.0)) == log1p_32(0.0)); | |
| 192 | try expect(log1p(@as(f64, 0.0)) == log1p_64(0.0)); | |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | test "math.log1p_32" { |
| 196 | 196 | const epsilon = 0.000001; |
| 197 | 197 | |
| 198 | expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon)); | |
| 199 | expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon)); | |
| 200 | expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon)); | |
| 201 | expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon)); | |
| 202 | expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon)); | |
| 203 | expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon)); | |
| 204 | expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon)); | |
| 198 | try expect(math.approxEqAbs(f32, log1p_32(0.0), 0.0, epsilon)); | |
| 199 | try expect(math.approxEqAbs(f32, log1p_32(0.2), 0.182322, epsilon)); | |
| 200 | try expect(math.approxEqAbs(f32, log1p_32(0.8923), 0.637793, epsilon)); | |
| 201 | try expect(math.approxEqAbs(f32, log1p_32(1.5), 0.916291, epsilon)); | |
| 202 | try expect(math.approxEqAbs(f32, log1p_32(37.45), 3.649359, epsilon)); | |
| 203 | try expect(math.approxEqAbs(f32, log1p_32(89.123), 4.501175, epsilon)); | |
| 204 | try expect(math.approxEqAbs(f32, log1p_32(123123.234375), 11.720949, epsilon)); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | test "math.log1p_64" { |
| 208 | 208 | const epsilon = 0.000001; |
| 209 | 209 | |
| 210 | expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon)); | |
| 211 | expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon)); | |
| 212 | expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon)); | |
| 213 | expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon)); | |
| 214 | expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon)); | |
| 215 | expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon)); | |
| 216 | expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon)); | |
| 210 | try expect(math.approxEqAbs(f64, log1p_64(0.0), 0.0, epsilon)); | |
| 211 | try expect(math.approxEqAbs(f64, log1p_64(0.2), 0.182322, epsilon)); | |
| 212 | try expect(math.approxEqAbs(f64, log1p_64(0.8923), 0.637793, epsilon)); | |
| 213 | try expect(math.approxEqAbs(f64, log1p_64(1.5), 0.916291, epsilon)); | |
| 214 | try expect(math.approxEqAbs(f64, log1p_64(37.45), 3.649359, epsilon)); | |
| 215 | try expect(math.approxEqAbs(f64, log1p_64(89.123), 4.501175, epsilon)); | |
| 216 | try expect(math.approxEqAbs(f64, log1p_64(123123.234375), 11.720949, epsilon)); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "math.log1p_32.special" { |
| 220 | expect(math.isPositiveInf(log1p_32(math.inf(f32)))); | |
| 221 | expect(log1p_32(0.0) == 0.0); | |
| 222 | expect(log1p_32(-0.0) == -0.0); | |
| 223 | expect(math.isNegativeInf(log1p_32(-1.0))); | |
| 224 | expect(math.isNan(log1p_32(-2.0))); | |
| 225 | expect(math.isNan(log1p_32(math.nan(f32)))); | |
| 220 | try expect(math.isPositiveInf(log1p_32(math.inf(f32)))); | |
| 221 | try expect(log1p_32(0.0) == 0.0); | |
| 222 | try expect(log1p_32(-0.0) == -0.0); | |
| 223 | try expect(math.isNegativeInf(log1p_32(-1.0))); | |
| 224 | try expect(math.isNan(log1p_32(-2.0))); | |
| 225 | try expect(math.isNan(log1p_32(math.nan(f32)))); | |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | test "math.log1p_64.special" { |
| 229 | expect(math.isPositiveInf(log1p_64(math.inf(f64)))); | |
| 230 | expect(log1p_64(0.0) == 0.0); | |
| 231 | expect(log1p_64(-0.0) == -0.0); | |
| 232 | expect(math.isNegativeInf(log1p_64(-1.0))); | |
| 233 | expect(math.isNan(log1p_64(-2.0))); | |
| 234 | expect(math.isNan(log1p_64(math.nan(f64)))); | |
| 229 | try expect(math.isPositiveInf(log1p_64(math.inf(f64)))); | |
| 230 | try expect(log1p_64(0.0) == 0.0); | |
| 231 | try expect(log1p_64(-0.0) == -0.0); | |
| 232 | try expect(math.isNegativeInf(log1p_64(-1.0))); | |
| 233 | try expect(math.isNan(log1p_64(-2.0))); | |
| 234 | try expect(math.isNan(log1p_64(math.nan(f64)))); | |
| 235 | 235 | } |
lib/std/math/log2.zig+20-20| ... | ... | @@ -179,40 +179,40 @@ pub fn log2_64(x_: f64) f64 { |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | test "math.log2" { |
| 182 | expect(log2(@as(f32, 0.2)) == log2_32(0.2)); | |
| 183 | expect(log2(@as(f64, 0.2)) == log2_64(0.2)); | |
| 182 | try expect(log2(@as(f32, 0.2)) == log2_32(0.2)); | |
| 183 | try expect(log2(@as(f64, 0.2)) == log2_64(0.2)); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | test "math.log2_32" { |
| 187 | 187 | const epsilon = 0.000001; |
| 188 | 188 | |
| 189 | expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon)); | |
| 190 | expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon)); | |
| 191 | expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon)); | |
| 192 | expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon)); | |
| 193 | expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon)); | |
| 189 | try expect(math.approxEqAbs(f32, log2_32(0.2), -2.321928, epsilon)); | |
| 190 | try expect(math.approxEqAbs(f32, log2_32(0.8923), -0.164399, epsilon)); | |
| 191 | try expect(math.approxEqAbs(f32, log2_32(1.5), 0.584962, epsilon)); | |
| 192 | try expect(math.approxEqAbs(f32, log2_32(37.45), 5.226894, epsilon)); | |
| 193 | try expect(math.approxEqAbs(f32, log2_32(123123.234375), 16.909744, epsilon)); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | test "math.log2_64" { |
| 197 | 197 | const epsilon = 0.000001; |
| 198 | 198 | |
| 199 | expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon)); | |
| 200 | expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon)); | |
| 201 | expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon)); | |
| 202 | expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon)); | |
| 203 | expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon)); | |
| 199 | try expect(math.approxEqAbs(f64, log2_64(0.2), -2.321928, epsilon)); | |
| 200 | try expect(math.approxEqAbs(f64, log2_64(0.8923), -0.164399, epsilon)); | |
| 201 | try expect(math.approxEqAbs(f64, log2_64(1.5), 0.584962, epsilon)); | |
| 202 | try expect(math.approxEqAbs(f64, log2_64(37.45), 5.226894, epsilon)); | |
| 203 | try expect(math.approxEqAbs(f64, log2_64(123123.234375), 16.909744, epsilon)); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | test "math.log2_32.special" { |
| 207 | expect(math.isPositiveInf(log2_32(math.inf(f32)))); | |
| 208 | expect(math.isNegativeInf(log2_32(0.0))); | |
| 209 | expect(math.isNan(log2_32(-1.0))); | |
| 210 | expect(math.isNan(log2_32(math.nan(f32)))); | |
| 207 | try expect(math.isPositiveInf(log2_32(math.inf(f32)))); | |
| 208 | try expect(math.isNegativeInf(log2_32(0.0))); | |
| 209 | try expect(math.isNan(log2_32(-1.0))); | |
| 210 | try expect(math.isNan(log2_32(math.nan(f32)))); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | test "math.log2_64.special" { |
| 214 | expect(math.isPositiveInf(log2_64(math.inf(f64)))); | |
| 215 | expect(math.isNegativeInf(log2_64(0.0))); | |
| 216 | expect(math.isNan(log2_64(-1.0))); | |
| 217 | expect(math.isNan(log2_64(math.nan(f64)))); | |
| 214 | try expect(math.isPositiveInf(log2_64(math.inf(f64)))); | |
| 215 | try expect(math.isNegativeInf(log2_64(0.0))); | |
| 216 | try expect(math.isNan(log2_64(-1.0))); | |
| 217 | try expect(math.isNan(log2_64(math.nan(f64)))); | |
| 218 | 218 | } |
lib/std/math/modf.zig+28-28| ... | ... | @@ -131,11 +131,11 @@ test "math.modf" { |
| 131 | 131 | const a = modf(@as(f32, 1.0)); |
| 132 | 132 | const b = modf32(1.0); |
| 133 | 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); | |
| 135 | 135 | |
| 136 | 136 | const c = modf(@as(f64, 1.0)); |
| 137 | 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 | } |
| 140 | 140 | |
| 141 | 141 | test "math.modf32" { |
| ... | ... | @@ -143,24 +143,24 @@ test "math.modf32" { |
| 143 | 143 | var r: modf32_result = undefined; |
| 144 | 144 | |
| 145 | 145 | r = modf32(1.0); |
| 146 | expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon)); | |
| 147 | expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon)); | |
| 146 | try expect(math.approxEqAbs(f32, r.ipart, 1.0, epsilon)); | |
| 147 | try expect(math.approxEqAbs(f32, r.fpart, 0.0, epsilon)); | |
| 148 | 148 | |
| 149 | 149 | r = modf32(2.545); |
| 150 | expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon)); | |
| 151 | expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon)); | |
| 150 | try expect(math.approxEqAbs(f32, r.ipart, 2.0, epsilon)); | |
| 151 | try expect(math.approxEqAbs(f32, r.fpart, 0.545, epsilon)); | |
| 152 | 152 | |
| 153 | 153 | r = modf32(3.978123); |
| 154 | expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon)); | |
| 155 | expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon)); | |
| 154 | try expect(math.approxEqAbs(f32, r.ipart, 3.0, epsilon)); | |
| 155 | try expect(math.approxEqAbs(f32, r.fpart, 0.978123, epsilon)); | |
| 156 | 156 | |
| 157 | 157 | r = modf32(43874.3); |
| 158 | expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon)); | |
| 159 | expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon)); | |
| 158 | try expect(math.approxEqAbs(f32, r.ipart, 43874, epsilon)); | |
| 159 | try expect(math.approxEqAbs(f32, r.fpart, 0.300781, epsilon)); | |
| 160 | 160 | |
| 161 | 161 | r = modf32(1234.340780); |
| 162 | expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon)); | |
| 163 | expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon)); | |
| 162 | try expect(math.approxEqAbs(f32, r.ipart, 1234, epsilon)); | |
| 163 | try expect(math.approxEqAbs(f32, r.fpart, 0.340820, epsilon)); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | test "math.modf64" { |
| ... | ... | @@ -168,48 +168,48 @@ test "math.modf64" { |
| 168 | 168 | var r: modf64_result = undefined; |
| 169 | 169 | |
| 170 | 170 | r = modf64(1.0); |
| 171 | expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon)); | |
| 172 | expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon)); | |
| 171 | try expect(math.approxEqAbs(f64, r.ipart, 1.0, epsilon)); | |
| 172 | try expect(math.approxEqAbs(f64, r.fpart, 0.0, epsilon)); | |
| 173 | 173 | |
| 174 | 174 | r = modf64(2.545); |
| 175 | expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon)); | |
| 176 | expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon)); | |
| 175 | try expect(math.approxEqAbs(f64, r.ipart, 2.0, epsilon)); | |
| 176 | try expect(math.approxEqAbs(f64, r.fpart, 0.545, epsilon)); | |
| 177 | 177 | |
| 178 | 178 | r = modf64(3.978123); |
| 179 | expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon)); | |
| 180 | expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon)); | |
| 179 | try expect(math.approxEqAbs(f64, r.ipart, 3.0, epsilon)); | |
| 180 | try expect(math.approxEqAbs(f64, r.fpart, 0.978123, epsilon)); | |
| 181 | 181 | |
| 182 | 182 | r = modf64(43874.3); |
| 183 | expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon)); | |
| 184 | expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon)); | |
| 183 | try expect(math.approxEqAbs(f64, r.ipart, 43874, epsilon)); | |
| 184 | try expect(math.approxEqAbs(f64, r.fpart, 0.3, epsilon)); | |
| 185 | 185 | |
| 186 | 186 | r = modf64(1234.340780); |
| 187 | expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon)); | |
| 188 | expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon)); | |
| 187 | try expect(math.approxEqAbs(f64, r.ipart, 1234, epsilon)); | |
| 188 | try expect(math.approxEqAbs(f64, r.fpart, 0.340780, epsilon)); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | test "math.modf32.special" { |
| 192 | 192 | var r: modf32_result = undefined; |
| 193 | 193 | |
| 194 | 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)); | |
| 196 | 196 | |
| 197 | 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)); | |
| 199 | 199 | |
| 200 | 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 | } |
| 203 | 203 | |
| 204 | 204 | test "math.modf64.special" { |
| 205 | 205 | var r: modf64_result = undefined; |
| 206 | 206 | |
| 207 | 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)); | |
| 209 | 209 | |
| 210 | 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)); | |
| 212 | 212 | |
| 213 | 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| ... | ... | @@ -191,67 +191,67 @@ fn isOddInteger(x: f64) bool { |
| 191 | 191 | test "math.pow" { |
| 192 | 192 | const epsilon = 0.000001; |
| 193 | 193 | |
| 194 | expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon)); | |
| 195 | expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon)); | |
| 196 | expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon)); | |
| 197 | expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon)); | |
| 198 | expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon)); | |
| 199 | expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon)); | |
| 194 | try expect(math.approxEqAbs(f32, pow(f32, 0.0, 3.3), 0.0, epsilon)); | |
| 195 | try expect(math.approxEqAbs(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon)); | |
| 196 | try expect(math.approxEqAbs(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon)); | |
| 197 | try expect(math.approxEqAbs(f32, pow(f32, 1.5, 3.3), 3.811546, epsilon)); | |
| 198 | try expect(math.approxEqAbs(f32, pow(f32, 37.45, 3.3), 155736.703125, epsilon)); | |
| 199 | try expect(math.approxEqAbs(f32, pow(f32, 89.123, 3.3), 2722489.5, epsilon)); | |
| 200 | 200 | |
| 201 | expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon)); | |
| 202 | expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon)); | |
| 203 | expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon)); | |
| 204 | expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon)); | |
| 205 | expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon)); | |
| 206 | expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon)); | |
| 201 | try expect(math.approxEqAbs(f64, pow(f64, 0.0, 3.3), 0.0, epsilon)); | |
| 202 | try expect(math.approxEqAbs(f64, pow(f64, 0.8923, 3.3), 0.686572, epsilon)); | |
| 203 | try expect(math.approxEqAbs(f64, pow(f64, 0.2, 3.3), 0.004936, epsilon)); | |
| 204 | try expect(math.approxEqAbs(f64, pow(f64, 1.5, 3.3), 3.811546, epsilon)); | |
| 205 | try expect(math.approxEqAbs(f64, pow(f64, 37.45, 3.3), 155736.7160616, epsilon)); | |
| 206 | try expect(math.approxEqAbs(f64, pow(f64, 89.123, 3.3), 2722490.231436, epsilon)); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | test "math.pow.special" { |
| 210 | 210 | const epsilon = 0.000001; |
| 211 | 211 | |
| 212 | expect(pow(f32, 4, 0.0) == 1.0); | |
| 213 | expect(pow(f32, 7, -0.0) == 1.0); | |
| 214 | expect(pow(f32, 45, 1.0) == 45); | |
| 215 | expect(pow(f32, -45, 1.0) == -45); | |
| 216 | expect(math.isNan(pow(f32, math.nan(f32), 5.0))); | |
| 217 | expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5))); | |
| 218 | expect(math.isPositiveInf(pow(f32, -0, -0.5))); | |
| 219 | expect(pow(f32, -0, 0.5) == 0); | |
| 220 | expect(math.isNan(pow(f32, 5.0, math.nan(f32)))); | |
| 221 | expect(math.isPositiveInf(pow(f32, 0.0, -1.0))); | |
| 212 | try expect(pow(f32, 4, 0.0) == 1.0); | |
| 213 | try expect(pow(f32, 7, -0.0) == 1.0); | |
| 214 | try expect(pow(f32, 45, 1.0) == 45); | |
| 215 | try expect(pow(f32, -45, 1.0) == -45); | |
| 216 | try expect(math.isNan(pow(f32, math.nan(f32), 5.0))); | |
| 217 | try expect(math.isPositiveInf(pow(f32, -math.inf(f32), 0.5))); | |
| 218 | try expect(math.isPositiveInf(pow(f32, -0, -0.5))); | |
| 219 | try expect(pow(f32, -0, 0.5) == 0); | |
| 220 | try expect(math.isNan(pow(f32, 5.0, math.nan(f32)))); | |
| 221 | try expect(math.isPositiveInf(pow(f32, 0.0, -1.0))); | |
| 222 | 222 | //expect(math.isNegativeInf(pow(f32, -0.0, -3.0))); TODO is this required? |
| 223 | expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32)))); | |
| 224 | expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32)))); | |
| 225 | expect(pow(f32, 0.0, math.inf(f32)) == 0.0); | |
| 226 | expect(pow(f32, -0.0, math.inf(f32)) == 0.0); | |
| 227 | expect(math.isPositiveInf(pow(f32, 0.0, -2.0))); | |
| 228 | expect(math.isPositiveInf(pow(f32, -0.0, -2.0))); | |
| 229 | expect(pow(f32, 0.0, 1.0) == 0.0); | |
| 230 | expect(pow(f32, -0.0, 1.0) == -0.0); | |
| 231 | expect(pow(f32, 0.0, 2.0) == 0.0); | |
| 232 | expect(pow(f32, -0.0, 2.0) == 0.0); | |
| 233 | expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon)); | |
| 234 | expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon)); | |
| 235 | expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32)))); | |
| 236 | expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32)))); | |
| 237 | expect(pow(f32, 1.2, -math.inf(f32)) == 0.0); | |
| 238 | expect(pow(f32, -1.2, -math.inf(f32)) == 0.0); | |
| 239 | expect(pow(f32, 0.2, math.inf(f32)) == 0.0); | |
| 240 | expect(pow(f32, -0.2, math.inf(f32)) == 0.0); | |
| 241 | expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32)))); | |
| 242 | expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32)))); | |
| 243 | expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0))); | |
| 244 | expect(pow(f32, math.inf(f32), -1.0) == 0.0); | |
| 223 | try expect(math.isPositiveInf(pow(f32, 0.0, -math.inf(f32)))); | |
| 224 | try expect(math.isPositiveInf(pow(f32, -0.0, -math.inf(f32)))); | |
| 225 | try expect(pow(f32, 0.0, math.inf(f32)) == 0.0); | |
| 226 | try expect(pow(f32, -0.0, math.inf(f32)) == 0.0); | |
| 227 | try expect(math.isPositiveInf(pow(f32, 0.0, -2.0))); | |
| 228 | try expect(math.isPositiveInf(pow(f32, -0.0, -2.0))); | |
| 229 | try expect(pow(f32, 0.0, 1.0) == 0.0); | |
| 230 | try expect(pow(f32, -0.0, 1.0) == -0.0); | |
| 231 | try expect(pow(f32, 0.0, 2.0) == 0.0); | |
| 232 | try expect(pow(f32, -0.0, 2.0) == 0.0); | |
| 233 | try expect(math.approxEqAbs(f32, pow(f32, -1.0, math.inf(f32)), 1.0, epsilon)); | |
| 234 | try expect(math.approxEqAbs(f32, pow(f32, -1.0, -math.inf(f32)), 1.0, epsilon)); | |
| 235 | try expect(math.isPositiveInf(pow(f32, 1.2, math.inf(f32)))); | |
| 236 | try expect(math.isPositiveInf(pow(f32, -1.2, math.inf(f32)))); | |
| 237 | try expect(pow(f32, 1.2, -math.inf(f32)) == 0.0); | |
| 238 | try expect(pow(f32, -1.2, -math.inf(f32)) == 0.0); | |
| 239 | try expect(pow(f32, 0.2, math.inf(f32)) == 0.0); | |
| 240 | try expect(pow(f32, -0.2, math.inf(f32)) == 0.0); | |
| 241 | try expect(math.isPositiveInf(pow(f32, 0.2, -math.inf(f32)))); | |
| 242 | try expect(math.isPositiveInf(pow(f32, -0.2, -math.inf(f32)))); | |
| 243 | try expect(math.isPositiveInf(pow(f32, math.inf(f32), 1.0))); | |
| 244 | try expect(pow(f32, math.inf(f32), -1.0) == 0.0); | |
| 245 | 245 | //expect(pow(f32, -math.inf(f32), 5.0) == pow(f32, -0.0, -5.0)); TODO support negative 0? |
| 246 | expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2)); | |
| 247 | expect(math.isNan(pow(f32, -1.0, 1.2))); | |
| 248 | expect(math.isNan(pow(f32, -12.4, 78.5))); | |
| 246 | try expect(pow(f32, -math.inf(f32), -5.2) == pow(f32, -0.0, 5.2)); | |
| 247 | try expect(math.isNan(pow(f32, -1.0, 1.2))); | |
| 248 | try expect(math.isNan(pow(f32, -12.4, 78.5))); | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | test "math.pow.overflow" { |
| 252 | expect(math.isPositiveInf(pow(f64, 2, 1 << 32))); | |
| 253 | expect(pow(f64, 2, -(1 << 32)) == 0); | |
| 254 | expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1))); | |
| 255 | expect(pow(f64, 0.5, 1 << 45) == 0); | |
| 256 | expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45)))); | |
| 252 | try expect(math.isPositiveInf(pow(f64, 2, 1 << 32))); | |
| 253 | try expect(pow(f64, 2, -(1 << 32)) == 0); | |
| 254 | try expect(math.isNegativeInf(pow(f64, -2, (1 << 32) + 1))); | |
| 255 | try expect(pow(f64, 0.5, 1 << 45) == 0); | |
| 256 | try expect(math.isPositiveInf(pow(f64, 0.5, -(1 << 45)))); | |
| 257 | 257 | } |
lib/std/math/powi.zig+75-75| ... | ... | @@ -112,82 +112,82 @@ pub fn powi(comptime T: type, x: T, y: T) (error{ |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "math.powi" { |
| 115 | testing.expectError(error.Underflow, powi(i8, -66, 6)); | |
| 116 | testing.expectError(error.Underflow, powi(i16, -13, 13)); | |
| 117 | testing.expectError(error.Underflow, powi(i32, -32, 21)); | |
| 118 | testing.expectError(error.Underflow, powi(i64, -24, 61)); | |
| 119 | testing.expectError(error.Underflow, powi(i17, -15, 15)); | |
| 120 | testing.expectError(error.Underflow, powi(i42, -6, 40)); | |
| 121 | ||
| 122 | testing.expect((try powi(i8, -5, 3)) == -125); | |
| 123 | testing.expect((try powi(i16, -16, 3)) == -4096); | |
| 124 | testing.expect((try powi(i32, -91, 3)) == -753571); | |
| 125 | testing.expect((try powi(i64, -36, 6)) == 2176782336); | |
| 126 | testing.expect((try powi(i17, -2, 15)) == -32768); | |
| 127 | testing.expect((try powi(i42, -5, 7)) == -78125); | |
| 128 | ||
| 129 | testing.expect((try powi(u8, 6, 2)) == 36); | |
| 130 | testing.expect((try powi(u16, 5, 4)) == 625); | |
| 131 | testing.expect((try powi(u32, 12, 6)) == 2985984); | |
| 132 | testing.expect((try powi(u64, 34, 2)) == 1156); | |
| 133 | testing.expect((try powi(u17, 16, 3)) == 4096); | |
| 134 | testing.expect((try powi(u42, 34, 6)) == 1544804416); | |
| 135 | ||
| 136 | testing.expectError(error.Overflow, powi(i8, 120, 7)); | |
| 137 | testing.expectError(error.Overflow, powi(i16, 73, 15)); | |
| 138 | testing.expectError(error.Overflow, powi(i32, 23, 31)); | |
| 139 | testing.expectError(error.Overflow, powi(i64, 68, 61)); | |
| 140 | testing.expectError(error.Overflow, powi(i17, 15, 15)); | |
| 141 | testing.expectError(error.Overflow, powi(i42, 121312, 41)); | |
| 142 | ||
| 143 | testing.expectError(error.Overflow, powi(u8, 123, 7)); | |
| 144 | testing.expectError(error.Overflow, powi(u16, 2313, 15)); | |
| 145 | testing.expectError(error.Overflow, powi(u32, 8968, 31)); | |
| 146 | testing.expectError(error.Overflow, powi(u64, 2342, 63)); | |
| 147 | testing.expectError(error.Overflow, powi(u17, 2723, 16)); | |
| 148 | testing.expectError(error.Overflow, powi(u42, 8234, 41)); | |
| 115 | try testing.expectError(error.Underflow, powi(i8, -66, 6)); | |
| 116 | try testing.expectError(error.Underflow, powi(i16, -13, 13)); | |
| 117 | try testing.expectError(error.Underflow, powi(i32, -32, 21)); | |
| 118 | try testing.expectError(error.Underflow, powi(i64, -24, 61)); | |
| 119 | try testing.expectError(error.Underflow, powi(i17, -15, 15)); | |
| 120 | try testing.expectError(error.Underflow, powi(i42, -6, 40)); | |
| 121 | ||
| 122 | try testing.expect((try powi(i8, -5, 3)) == -125); | |
| 123 | try testing.expect((try powi(i16, -16, 3)) == -4096); | |
| 124 | try testing.expect((try powi(i32, -91, 3)) == -753571); | |
| 125 | try testing.expect((try powi(i64, -36, 6)) == 2176782336); | |
| 126 | try testing.expect((try powi(i17, -2, 15)) == -32768); | |
| 127 | try testing.expect((try powi(i42, -5, 7)) == -78125); | |
| 128 | ||
| 129 | try testing.expect((try powi(u8, 6, 2)) == 36); | |
| 130 | try testing.expect((try powi(u16, 5, 4)) == 625); | |
| 131 | try testing.expect((try powi(u32, 12, 6)) == 2985984); | |
| 132 | try testing.expect((try powi(u64, 34, 2)) == 1156); | |
| 133 | try testing.expect((try powi(u17, 16, 3)) == 4096); | |
| 134 | try testing.expect((try powi(u42, 34, 6)) == 1544804416); | |
| 135 | ||
| 136 | try testing.expectError(error.Overflow, powi(i8, 120, 7)); | |
| 137 | try testing.expectError(error.Overflow, powi(i16, 73, 15)); | |
| 138 | try testing.expectError(error.Overflow, powi(i32, 23, 31)); | |
| 139 | try testing.expectError(error.Overflow, powi(i64, 68, 61)); | |
| 140 | try testing.expectError(error.Overflow, powi(i17, 15, 15)); | |
| 141 | try testing.expectError(error.Overflow, powi(i42, 121312, 41)); | |
| 142 | ||
| 143 | try testing.expectError(error.Overflow, powi(u8, 123, 7)); | |
| 144 | try testing.expectError(error.Overflow, powi(u16, 2313, 15)); | |
| 145 | try testing.expectError(error.Overflow, powi(u32, 8968, 31)); | |
| 146 | try testing.expectError(error.Overflow, powi(u64, 2342, 63)); | |
| 147 | try testing.expectError(error.Overflow, powi(u17, 2723, 16)); | |
| 148 | try testing.expectError(error.Overflow, powi(u42, 8234, 41)); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "math.powi.special" { |
| 152 | testing.expectError(error.Underflow, powi(i8, -2, 8)); | |
| 153 | testing.expectError(error.Underflow, powi(i16, -2, 16)); | |
| 154 | testing.expectError(error.Underflow, powi(i32, -2, 32)); | |
| 155 | testing.expectError(error.Underflow, powi(i64, -2, 64)); | |
| 156 | testing.expectError(error.Underflow, powi(i17, -2, 17)); | |
| 157 | testing.expectError(error.Underflow, powi(i42, -2, 42)); | |
| 158 | ||
| 159 | testing.expect((try powi(i8, -1, 3)) == -1); | |
| 160 | testing.expect((try powi(i16, -1, 2)) == 1); | |
| 161 | testing.expect((try powi(i32, -1, 16)) == 1); | |
| 162 | testing.expect((try powi(i64, -1, 6)) == 1); | |
| 163 | testing.expect((try powi(i17, -1, 15)) == -1); | |
| 164 | testing.expect((try powi(i42, -1, 7)) == -1); | |
| 165 | ||
| 166 | testing.expect((try powi(u8, 1, 2)) == 1); | |
| 167 | testing.expect((try powi(u16, 1, 4)) == 1); | |
| 168 | testing.expect((try powi(u32, 1, 6)) == 1); | |
| 169 | testing.expect((try powi(u64, 1, 2)) == 1); | |
| 170 | testing.expect((try powi(u17, 1, 3)) == 1); | |
| 171 | testing.expect((try powi(u42, 1, 6)) == 1); | |
| 172 | ||
| 173 | testing.expectError(error.Overflow, powi(i8, 2, 7)); | |
| 174 | testing.expectError(error.Overflow, powi(i16, 2, 15)); | |
| 175 | testing.expectError(error.Overflow, powi(i32, 2, 31)); | |
| 176 | testing.expectError(error.Overflow, powi(i64, 2, 63)); | |
| 177 | testing.expectError(error.Overflow, powi(i17, 2, 16)); | |
| 178 | testing.expectError(error.Overflow, powi(i42, 2, 41)); | |
| 179 | ||
| 180 | testing.expectError(error.Overflow, powi(u8, 2, 8)); | |
| 181 | testing.expectError(error.Overflow, powi(u16, 2, 16)); | |
| 182 | testing.expectError(error.Overflow, powi(u32, 2, 32)); | |
| 183 | testing.expectError(error.Overflow, powi(u64, 2, 64)); | |
| 184 | testing.expectError(error.Overflow, powi(u17, 2, 17)); | |
| 185 | testing.expectError(error.Overflow, powi(u42, 2, 42)); | |
| 186 | ||
| 187 | testing.expect((try powi(u8, 6, 0)) == 1); | |
| 188 | testing.expect((try powi(u16, 5, 0)) == 1); | |
| 189 | testing.expect((try powi(u32, 12, 0)) == 1); | |
| 190 | testing.expect((try powi(u64, 34, 0)) == 1); | |
| 191 | testing.expect((try powi(u17, 16, 0)) == 1); | |
| 192 | testing.expect((try powi(u42, 34, 0)) == 1); | |
| 152 | try testing.expectError(error.Underflow, powi(i8, -2, 8)); | |
| 153 | try testing.expectError(error.Underflow, powi(i16, -2, 16)); | |
| 154 | try testing.expectError(error.Underflow, powi(i32, -2, 32)); | |
| 155 | try testing.expectError(error.Underflow, powi(i64, -2, 64)); | |
| 156 | try testing.expectError(error.Underflow, powi(i17, -2, 17)); | |
| 157 | try testing.expectError(error.Underflow, powi(i42, -2, 42)); | |
| 158 | ||
| 159 | try testing.expect((try powi(i8, -1, 3)) == -1); | |
| 160 | try testing.expect((try powi(i16, -1, 2)) == 1); | |
| 161 | try testing.expect((try powi(i32, -1, 16)) == 1); | |
| 162 | try testing.expect((try powi(i64, -1, 6)) == 1); | |
| 163 | try testing.expect((try powi(i17, -1, 15)) == -1); | |
| 164 | try testing.expect((try powi(i42, -1, 7)) == -1); | |
| 165 | ||
| 166 | try testing.expect((try powi(u8, 1, 2)) == 1); | |
| 167 | try testing.expect((try powi(u16, 1, 4)) == 1); | |
| 168 | try testing.expect((try powi(u32, 1, 6)) == 1); | |
| 169 | try testing.expect((try powi(u64, 1, 2)) == 1); | |
| 170 | try testing.expect((try powi(u17, 1, 3)) == 1); | |
| 171 | try testing.expect((try powi(u42, 1, 6)) == 1); | |
| 172 | ||
| 173 | try testing.expectError(error.Overflow, powi(i8, 2, 7)); | |
| 174 | try testing.expectError(error.Overflow, powi(i16, 2, 15)); | |
| 175 | try testing.expectError(error.Overflow, powi(i32, 2, 31)); | |
| 176 | try testing.expectError(error.Overflow, powi(i64, 2, 63)); | |
| 177 | try testing.expectError(error.Overflow, powi(i17, 2, 16)); | |
| 178 | try testing.expectError(error.Overflow, powi(i42, 2, 41)); | |
| 179 | ||
| 180 | try testing.expectError(error.Overflow, powi(u8, 2, 8)); | |
| 181 | try testing.expectError(error.Overflow, powi(u16, 2, 16)); | |
| 182 | try testing.expectError(error.Overflow, powi(u32, 2, 32)); | |
| 183 | try testing.expectError(error.Overflow, powi(u64, 2, 64)); | |
| 184 | try testing.expectError(error.Overflow, powi(u17, 2, 17)); | |
| 185 | try testing.expectError(error.Overflow, powi(u42, 2, 42)); | |
| 186 | ||
| 187 | try testing.expect((try powi(u8, 6, 0)) == 1); | |
| 188 | try testing.expect((try powi(u16, 5, 0)) == 1); | |
| 189 | try testing.expect((try powi(u32, 12, 0)) == 1); | |
| 190 | try testing.expect((try powi(u64, 34, 0)) == 1); | |
| 191 | try testing.expect((try powi(u17, 16, 0)) == 1); | |
| 192 | try testing.expect((try powi(u42, 34, 0)) == 1); | |
| 193 | 193 | } |
lib/std/math/round.zig+30-30| ... | ... | @@ -130,52 +130,52 @@ fn round128(x_: f128) f128 { |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "math.round" { |
| 133 | expect(round(@as(f32, 1.3)) == round32(1.3)); | |
| 134 | expect(round(@as(f64, 1.3)) == round64(1.3)); | |
| 135 | expect(round(@as(f128, 1.3)) == round128(1.3)); | |
| 133 | try expect(round(@as(f32, 1.3)) == round32(1.3)); | |
| 134 | try expect(round(@as(f64, 1.3)) == round64(1.3)); | |
| 135 | try expect(round(@as(f128, 1.3)) == round128(1.3)); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "math.round32" { |
| 139 | expect(round32(1.3) == 1.0); | |
| 140 | expect(round32(-1.3) == -1.0); | |
| 141 | expect(round32(0.2) == 0.0); | |
| 142 | expect(round32(1.8) == 2.0); | |
| 139 | try expect(round32(1.3) == 1.0); | |
| 140 | try expect(round32(-1.3) == -1.0); | |
| 141 | try expect(round32(0.2) == 0.0); | |
| 142 | try expect(round32(1.8) == 2.0); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "math.round64" { |
| 146 | expect(round64(1.3) == 1.0); | |
| 147 | expect(round64(-1.3) == -1.0); | |
| 148 | expect(round64(0.2) == 0.0); | |
| 149 | expect(round64(1.8) == 2.0); | |
| 146 | try expect(round64(1.3) == 1.0); | |
| 147 | try expect(round64(-1.3) == -1.0); | |
| 148 | try expect(round64(0.2) == 0.0); | |
| 149 | try expect(round64(1.8) == 2.0); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | test "math.round128" { |
| 153 | expect(round128(1.3) == 1.0); | |
| 154 | expect(round128(-1.3) == -1.0); | |
| 155 | expect(round128(0.2) == 0.0); | |
| 156 | expect(round128(1.8) == 2.0); | |
| 153 | try expect(round128(1.3) == 1.0); | |
| 154 | try expect(round128(-1.3) == -1.0); | |
| 155 | try expect(round128(0.2) == 0.0); | |
| 156 | try expect(round128(1.8) == 2.0); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "math.round32.special" { |
| 160 | expect(round32(0.0) == 0.0); | |
| 161 | expect(round32(-0.0) == -0.0); | |
| 162 | expect(math.isPositiveInf(round32(math.inf(f32)))); | |
| 163 | expect(math.isNegativeInf(round32(-math.inf(f32)))); | |
| 164 | expect(math.isNan(round32(math.nan(f32)))); | |
| 160 | try expect(round32(0.0) == 0.0); | |
| 161 | try expect(round32(-0.0) == -0.0); | |
| 162 | try expect(math.isPositiveInf(round32(math.inf(f32)))); | |
| 163 | try expect(math.isNegativeInf(round32(-math.inf(f32)))); | |
| 164 | try expect(math.isNan(round32(math.nan(f32)))); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | test "math.round64.special" { |
| 168 | expect(round64(0.0) == 0.0); | |
| 169 | expect(round64(-0.0) == -0.0); | |
| 170 | expect(math.isPositiveInf(round64(math.inf(f64)))); | |
| 171 | expect(math.isNegativeInf(round64(-math.inf(f64)))); | |
| 172 | expect(math.isNan(round64(math.nan(f64)))); | |
| 168 | try expect(round64(0.0) == 0.0); | |
| 169 | try expect(round64(-0.0) == -0.0); | |
| 170 | try expect(math.isPositiveInf(round64(math.inf(f64)))); | |
| 171 | try expect(math.isNegativeInf(round64(-math.inf(f64)))); | |
| 172 | try expect(math.isNan(round64(math.nan(f64)))); | |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | test "math.round128.special" { |
| 176 | expect(round128(0.0) == 0.0); | |
| 177 | expect(round128(-0.0) == -0.0); | |
| 178 | expect(math.isPositiveInf(round128(math.inf(f128)))); | |
| 179 | expect(math.isNegativeInf(round128(-math.inf(f128)))); | |
| 180 | expect(math.isNan(round128(math.nan(f128)))); | |
| 176 | try expect(round128(0.0) == 0.0); | |
| 177 | try expect(round128(-0.0) == -0.0); | |
| 178 | try expect(math.isPositiveInf(round128(math.inf(f128)))); | |
| 179 | try expect(math.isNegativeInf(round128(-math.inf(f128)))); | |
| 180 | try expect(math.isNan(round128(math.nan(f128)))); | |
| 181 | 181 | } |
lib/std/math/scalbn.zig+4-4| ... | ... | @@ -84,14 +84,14 @@ fn scalbn64(x: f64, n_: i32) f64 { |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "math.scalbn" { |
| 87 | expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4)); | |
| 88 | expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4)); | |
| 87 | try expect(scalbn(@as(f32, 1.5), 4) == scalbn32(1.5, 4)); | |
| 88 | try expect(scalbn(@as(f64, 1.5), 4) == scalbn64(1.5, 4)); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "math.scalbn32" { |
| 92 | expect(scalbn32(1.5, 4) == 24.0); | |
| 92 | try expect(scalbn32(1.5, 4) == 24.0); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "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 | 40 | } |
| 41 | 41 | |
| 42 | 42 | test "math.signbit" { |
| 43 | expect(signbit(@as(f16, 4.0)) == signbit16(4.0)); | |
| 44 | expect(signbit(@as(f32, 4.0)) == signbit32(4.0)); | |
| 45 | expect(signbit(@as(f64, 4.0)) == signbit64(4.0)); | |
| 46 | expect(signbit(@as(f128, 4.0)) == signbit128(4.0)); | |
| 43 | try expect(signbit(@as(f16, 4.0)) == signbit16(4.0)); | |
| 44 | try expect(signbit(@as(f32, 4.0)) == signbit32(4.0)); | |
| 45 | try expect(signbit(@as(f64, 4.0)) == signbit64(4.0)); | |
| 46 | try expect(signbit(@as(f128, 4.0)) == signbit128(4.0)); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "math.signbit16" { |
| 50 | expect(!signbit16(4.0)); | |
| 51 | expect(signbit16(-3.0)); | |
| 50 | try expect(!signbit16(4.0)); | |
| 51 | try expect(signbit16(-3.0)); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "math.signbit32" { |
| 55 | expect(!signbit32(4.0)); | |
| 56 | expect(signbit32(-3.0)); | |
| 55 | try expect(!signbit32(4.0)); | |
| 56 | try expect(signbit32(-3.0)); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | test "math.signbit64" { |
| 60 | expect(!signbit64(4.0)); | |
| 61 | expect(signbit64(-3.0)); | |
| 60 | try expect(!signbit64(4.0)); | |
| 61 | try expect(signbit64(-3.0)); | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | test "math.signbit128" { |
| 65 | expect(!signbit128(4.0)); | |
| 66 | expect(signbit128(-3.0)); | |
| 65 | try expect(!signbit128(4.0)); | |
| 66 | try expect(signbit128(-3.0)); | |
| 67 | 67 | } |
lib/std/math/sin.zig+27-27| ... | ... | @@ -89,47 +89,47 @@ fn sin_(comptime T: type, x_: T) T { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "math.sin" { |
| 92 | expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0)); | |
| 93 | expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0)); | |
| 94 | expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2))); | |
| 92 | try expect(sin(@as(f32, 0.0)) == sin_(f32, 0.0)); | |
| 93 | try expect(sin(@as(f64, 0.0)) == sin_(f64, 0.0)); | |
| 94 | try expect(comptime (math.sin(@as(f64, 2))) == math.sin(@as(f64, 2))); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | test "math.sin32" { |
| 98 | 98 | const epsilon = 0.000001; |
| 99 | 99 | |
| 100 | expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon)); | |
| 101 | expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon)); | |
| 102 | expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon)); | |
| 103 | expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon)); | |
| 104 | expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon)); | |
| 105 | expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon)); | |
| 106 | expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon)); | |
| 100 | try expect(math.approxEqAbs(f32, sin_(f32, 0.0), 0.0, epsilon)); | |
| 101 | try expect(math.approxEqAbs(f32, sin_(f32, 0.2), 0.198669, epsilon)); | |
| 102 | try expect(math.approxEqAbs(f32, sin_(f32, 0.8923), 0.778517, epsilon)); | |
| 103 | try expect(math.approxEqAbs(f32, sin_(f32, 1.5), 0.997495, epsilon)); | |
| 104 | try expect(math.approxEqAbs(f32, sin_(f32, -1.5), -0.997495, epsilon)); | |
| 105 | try expect(math.approxEqAbs(f32, sin_(f32, 37.45), -0.246544, epsilon)); | |
| 106 | try expect(math.approxEqAbs(f32, sin_(f32, 89.123), 0.916166, epsilon)); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "math.sin64" { |
| 110 | 110 | const epsilon = 0.000001; |
| 111 | 111 | |
| 112 | expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon)); | |
| 113 | expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon)); | |
| 114 | expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon)); | |
| 115 | expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon)); | |
| 116 | expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon)); | |
| 117 | expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon)); | |
| 118 | expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon)); | |
| 112 | try expect(math.approxEqAbs(f64, sin_(f64, 0.0), 0.0, epsilon)); | |
| 113 | try expect(math.approxEqAbs(f64, sin_(f64, 0.2), 0.198669, epsilon)); | |
| 114 | try expect(math.approxEqAbs(f64, sin_(f64, 0.8923), 0.778517, epsilon)); | |
| 115 | try expect(math.approxEqAbs(f64, sin_(f64, 1.5), 0.997495, epsilon)); | |
| 116 | try expect(math.approxEqAbs(f64, sin_(f64, -1.5), -0.997495, epsilon)); | |
| 117 | try expect(math.approxEqAbs(f64, sin_(f64, 37.45), -0.246543, epsilon)); | |
| 118 | try expect(math.approxEqAbs(f64, sin_(f64, 89.123), 0.916166, epsilon)); | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | test "math.sin32.special" { |
| 122 | expect(sin_(f32, 0.0) == 0.0); | |
| 123 | expect(sin_(f32, -0.0) == -0.0); | |
| 124 | expect(math.isNan(sin_(f32, math.inf(f32)))); | |
| 125 | expect(math.isNan(sin_(f32, -math.inf(f32)))); | |
| 126 | expect(math.isNan(sin_(f32, math.nan(f32)))); | |
| 122 | try expect(sin_(f32, 0.0) == 0.0); | |
| 123 | try expect(sin_(f32, -0.0) == -0.0); | |
| 124 | try expect(math.isNan(sin_(f32, math.inf(f32)))); | |
| 125 | try expect(math.isNan(sin_(f32, -math.inf(f32)))); | |
| 126 | try expect(math.isNan(sin_(f32, math.nan(f32)))); | |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | test "math.sin64.special" { |
| 130 | expect(sin_(f64, 0.0) == 0.0); | |
| 131 | expect(sin_(f64, -0.0) == -0.0); | |
| 132 | expect(math.isNan(sin_(f64, math.inf(f64)))); | |
| 133 | expect(math.isNan(sin_(f64, -math.inf(f64)))); | |
| 134 | expect(math.isNan(sin_(f64, math.nan(f64)))); | |
| 130 | try expect(sin_(f64, 0.0) == 0.0); | |
| 131 | try expect(sin_(f64, -0.0) == -0.0); | |
| 132 | try expect(math.isNan(sin_(f64, math.inf(f64)))); | |
| 133 | try expect(math.isNan(sin_(f64, -math.inf(f64)))); | |
| 134 | try expect(math.isNan(sin_(f64, math.nan(f64)))); | |
| 135 | 135 | } |
lib/std/math/sinh.zig+28-28| ... | ... | @@ -98,48 +98,48 @@ fn sinh64(x: f64) f64 { |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "math.sinh" { |
| 101 | expect(sinh(@as(f32, 1.5)) == sinh32(1.5)); | |
| 102 | expect(sinh(@as(f64, 1.5)) == sinh64(1.5)); | |
| 101 | try expect(sinh(@as(f32, 1.5)) == sinh32(1.5)); | |
| 102 | try expect(sinh(@as(f64, 1.5)) == sinh64(1.5)); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "math.sinh32" { |
| 106 | 106 | const epsilon = 0.000001; |
| 107 | 107 | |
| 108 | expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon)); | |
| 109 | expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon)); | |
| 110 | expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon)); | |
| 111 | expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon)); | |
| 112 | expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon)); | |
| 113 | expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon)); | |
| 114 | expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon)); | |
| 115 | expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon)); | |
| 108 | try expect(math.approxEqAbs(f32, sinh32(0.0), 0.0, epsilon)); | |
| 109 | try expect(math.approxEqAbs(f32, sinh32(0.2), 0.201336, epsilon)); | |
| 110 | try expect(math.approxEqAbs(f32, sinh32(0.8923), 1.015512, epsilon)); | |
| 111 | try expect(math.approxEqAbs(f32, sinh32(1.5), 2.129279, epsilon)); | |
| 112 | try expect(math.approxEqAbs(f32, sinh32(-0.0), -0.0, epsilon)); | |
| 113 | try expect(math.approxEqAbs(f32, sinh32(-0.2), -0.201336, epsilon)); | |
| 114 | try expect(math.approxEqAbs(f32, sinh32(-0.8923), -1.015512, epsilon)); | |
| 115 | try expect(math.approxEqAbs(f32, sinh32(-1.5), -2.129279, epsilon)); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | test "math.sinh64" { |
| 119 | 119 | const epsilon = 0.000001; |
| 120 | 120 | |
| 121 | expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon)); | |
| 122 | expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon)); | |
| 123 | expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon)); | |
| 124 | expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon)); | |
| 125 | expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon)); | |
| 126 | expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon)); | |
| 127 | expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon)); | |
| 128 | expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon)); | |
| 121 | try expect(math.approxEqAbs(f64, sinh64(0.0), 0.0, epsilon)); | |
| 122 | try expect(math.approxEqAbs(f64, sinh64(0.2), 0.201336, epsilon)); | |
| 123 | try expect(math.approxEqAbs(f64, sinh64(0.8923), 1.015512, epsilon)); | |
| 124 | try expect(math.approxEqAbs(f64, sinh64(1.5), 2.129279, epsilon)); | |
| 125 | try expect(math.approxEqAbs(f64, sinh64(-0.0), -0.0, epsilon)); | |
| 126 | try expect(math.approxEqAbs(f64, sinh64(-0.2), -0.201336, epsilon)); | |
| 127 | try expect(math.approxEqAbs(f64, sinh64(-0.8923), -1.015512, epsilon)); | |
| 128 | try expect(math.approxEqAbs(f64, sinh64(-1.5), -2.129279, epsilon)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.sinh32.special" { |
| 132 | expect(sinh32(0.0) == 0.0); | |
| 133 | expect(sinh32(-0.0) == -0.0); | |
| 134 | expect(math.isPositiveInf(sinh32(math.inf(f32)))); | |
| 135 | expect(math.isNegativeInf(sinh32(-math.inf(f32)))); | |
| 136 | expect(math.isNan(sinh32(math.nan(f32)))); | |
| 132 | try expect(sinh32(0.0) == 0.0); | |
| 133 | try expect(sinh32(-0.0) == -0.0); | |
| 134 | try expect(math.isPositiveInf(sinh32(math.inf(f32)))); | |
| 135 | try expect(math.isNegativeInf(sinh32(-math.inf(f32)))); | |
| 136 | try expect(math.isNan(sinh32(math.nan(f32)))); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | test "math.sinh64.special" { |
| 140 | expect(sinh64(0.0) == 0.0); | |
| 141 | expect(sinh64(-0.0) == -0.0); | |
| 142 | expect(math.isPositiveInf(sinh64(math.inf(f64)))); | |
| 143 | expect(math.isNegativeInf(sinh64(-math.inf(f64)))); | |
| 144 | expect(math.isNan(sinh64(math.nan(f64)))); | |
| 140 | try expect(sinh64(0.0) == 0.0); | |
| 141 | try expect(sinh64(-0.0) == -0.0); | |
| 142 | try expect(math.isPositiveInf(sinh64(math.inf(f64)))); | |
| 143 | try expect(math.isNegativeInf(sinh64(-math.inf(f64)))); | |
| 144 | try expect(math.isNan(sinh64(math.nan(f64)))); | |
| 145 | 145 | } |
lib/std/math/sqrt.zig+8-8| ... | ... | @@ -69,14 +69,14 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) { |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "math.sqrt_int" { |
| 72 | expect(sqrt_int(u0, 0) == 0); | |
| 73 | expect(sqrt_int(u1, 1) == 1); | |
| 74 | expect(sqrt_int(u32, 3) == 1); | |
| 75 | expect(sqrt_int(u32, 4) == 2); | |
| 76 | expect(sqrt_int(u32, 5) == 2); | |
| 77 | expect(sqrt_int(u32, 8) == 2); | |
| 78 | expect(sqrt_int(u32, 9) == 3); | |
| 79 | expect(sqrt_int(u32, 10) == 3); | |
| 72 | try expect(sqrt_int(u0, 0) == 0); | |
| 73 | try expect(sqrt_int(u1, 1) == 1); | |
| 74 | try expect(sqrt_int(u32, 3) == 1); | |
| 75 | try expect(sqrt_int(u32, 4) == 2); | |
| 76 | try expect(sqrt_int(u32, 5) == 2); | |
| 77 | try expect(sqrt_int(u32, 8) == 2); | |
| 78 | try expect(sqrt_int(u32, 9) == 3); | |
| 79 | try expect(sqrt_int(u32, 10) == 3); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /// Returns the return type `sqrt` will return given an operand of type `T`. |
lib/std/math/tan.zig+24-24| ... | ... | @@ -80,44 +80,44 @@ fn tan_(comptime T: type, x_: T) T { |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | test "math.tan" { |
| 83 | expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0)); | |
| 84 | expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0)); | |
| 83 | try expect(tan(@as(f32, 0.0)) == tan_(f32, 0.0)); | |
| 84 | try expect(tan(@as(f64, 0.0)) == tan_(f64, 0.0)); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | test "math.tan32" { |
| 88 | 88 | const epsilon = 0.000001; |
| 89 | 89 | |
| 90 | expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon)); | |
| 91 | expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon)); | |
| 92 | expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon)); | |
| 93 | expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon)); | |
| 94 | expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon)); | |
| 95 | expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon)); | |
| 90 | try expect(math.approxEqAbs(f32, tan_(f32, 0.0), 0.0, epsilon)); | |
| 91 | try expect(math.approxEqAbs(f32, tan_(f32, 0.2), 0.202710, epsilon)); | |
| 92 | try expect(math.approxEqAbs(f32, tan_(f32, 0.8923), 1.240422, epsilon)); | |
| 93 | try expect(math.approxEqAbs(f32, tan_(f32, 1.5), 14.101420, epsilon)); | |
| 94 | try expect(math.approxEqAbs(f32, tan_(f32, 37.45), -0.254397, epsilon)); | |
| 95 | try expect(math.approxEqAbs(f32, tan_(f32, 89.123), 2.285852, epsilon)); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "math.tan64" { |
| 99 | 99 | const epsilon = 0.000001; |
| 100 | 100 | |
| 101 | expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon)); | |
| 102 | expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon)); | |
| 103 | expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon)); | |
| 104 | expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon)); | |
| 105 | expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon)); | |
| 106 | expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon)); | |
| 101 | try expect(math.approxEqAbs(f64, tan_(f64, 0.0), 0.0, epsilon)); | |
| 102 | try expect(math.approxEqAbs(f64, tan_(f64, 0.2), 0.202710, epsilon)); | |
| 103 | try expect(math.approxEqAbs(f64, tan_(f64, 0.8923), 1.240422, epsilon)); | |
| 104 | try expect(math.approxEqAbs(f64, tan_(f64, 1.5), 14.101420, epsilon)); | |
| 105 | try expect(math.approxEqAbs(f64, tan_(f64, 37.45), -0.254397, epsilon)); | |
| 106 | try expect(math.approxEqAbs(f64, tan_(f64, 89.123), 2.2858376, epsilon)); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "math.tan32.special" { |
| 110 | expect(tan_(f32, 0.0) == 0.0); | |
| 111 | expect(tan_(f32, -0.0) == -0.0); | |
| 112 | expect(math.isNan(tan_(f32, math.inf(f32)))); | |
| 113 | expect(math.isNan(tan_(f32, -math.inf(f32)))); | |
| 114 | expect(math.isNan(tan_(f32, math.nan(f32)))); | |
| 110 | try expect(tan_(f32, 0.0) == 0.0); | |
| 111 | try expect(tan_(f32, -0.0) == -0.0); | |
| 112 | try expect(math.isNan(tan_(f32, math.inf(f32)))); | |
| 113 | try expect(math.isNan(tan_(f32, -math.inf(f32)))); | |
| 114 | try expect(math.isNan(tan_(f32, math.nan(f32)))); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "math.tan64.special" { |
| 118 | expect(tan_(f64, 0.0) == 0.0); | |
| 119 | expect(tan_(f64, -0.0) == -0.0); | |
| 120 | expect(math.isNan(tan_(f64, math.inf(f64)))); | |
| 121 | expect(math.isNan(tan_(f64, -math.inf(f64)))); | |
| 122 | expect(math.isNan(tan_(f64, math.nan(f64)))); | |
| 118 | try expect(tan_(f64, 0.0) == 0.0); | |
| 119 | try expect(tan_(f64, -0.0) == -0.0); | |
| 120 | try expect(math.isNan(tan_(f64, math.inf(f64)))); | |
| 121 | try expect(math.isNan(tan_(f64, -math.inf(f64)))); | |
| 122 | try expect(math.isNan(tan_(f64, math.nan(f64)))); | |
| 123 | 123 | } |
lib/std/math/tanh.zig+22-22| ... | ... | @@ -124,42 +124,42 @@ fn tanh64(x: f64) f64 { |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | test "math.tanh" { |
| 127 | expect(tanh(@as(f32, 1.5)) == tanh32(1.5)); | |
| 128 | expect(tanh(@as(f64, 1.5)) == tanh64(1.5)); | |
| 127 | try expect(tanh(@as(f32, 1.5)) == tanh32(1.5)); | |
| 128 | try expect(tanh(@as(f64, 1.5)) == tanh64(1.5)); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "math.tanh32" { |
| 132 | 132 | const epsilon = 0.000001; |
| 133 | 133 | |
| 134 | expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon)); | |
| 135 | expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon)); | |
| 136 | expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon)); | |
| 137 | expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon)); | |
| 138 | expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon)); | |
| 134 | try expect(math.approxEqAbs(f32, tanh32(0.0), 0.0, epsilon)); | |
| 135 | try expect(math.approxEqAbs(f32, tanh32(0.2), 0.197375, epsilon)); | |
| 136 | try expect(math.approxEqAbs(f32, tanh32(0.8923), 0.712528, epsilon)); | |
| 137 | try expect(math.approxEqAbs(f32, tanh32(1.5), 0.905148, epsilon)); | |
| 138 | try expect(math.approxEqAbs(f32, tanh32(37.45), 1.0, epsilon)); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "math.tanh64" { |
| 142 | 142 | const epsilon = 0.000001; |
| 143 | 143 | |
| 144 | expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon)); | |
| 145 | expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon)); | |
| 146 | expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon)); | |
| 147 | expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon)); | |
| 148 | expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon)); | |
| 144 | try expect(math.approxEqAbs(f64, tanh64(0.0), 0.0, epsilon)); | |
| 145 | try expect(math.approxEqAbs(f64, tanh64(0.2), 0.197375, epsilon)); | |
| 146 | try expect(math.approxEqAbs(f64, tanh64(0.8923), 0.712528, epsilon)); | |
| 147 | try expect(math.approxEqAbs(f64, tanh64(1.5), 0.905148, epsilon)); | |
| 148 | try expect(math.approxEqAbs(f64, tanh64(37.45), 1.0, epsilon)); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "math.tanh32.special" { |
| 152 | expect(tanh32(0.0) == 0.0); | |
| 153 | expect(tanh32(-0.0) == -0.0); | |
| 154 | expect(tanh32(math.inf(f32)) == 1.0); | |
| 155 | expect(tanh32(-math.inf(f32)) == -1.0); | |
| 156 | expect(math.isNan(tanh32(math.nan(f32)))); | |
| 152 | try expect(tanh32(0.0) == 0.0); | |
| 153 | try expect(tanh32(-0.0) == -0.0); | |
| 154 | try expect(tanh32(math.inf(f32)) == 1.0); | |
| 155 | try expect(tanh32(-math.inf(f32)) == -1.0); | |
| 156 | try expect(math.isNan(tanh32(math.nan(f32)))); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "math.tanh64.special" { |
| 160 | expect(tanh64(0.0) == 0.0); | |
| 161 | expect(tanh64(-0.0) == -0.0); | |
| 162 | expect(tanh64(math.inf(f64)) == 1.0); | |
| 163 | expect(tanh64(-math.inf(f64)) == -1.0); | |
| 164 | expect(math.isNan(tanh64(math.nan(f64)))); | |
| 160 | try expect(tanh64(0.0) == 0.0); | |
| 161 | try expect(tanh64(-0.0) == -0.0); | |
| 162 | try expect(tanh64(math.inf(f64)) == 1.0); | |
| 163 | try expect(tanh64(-math.inf(f64)) == -1.0); | |
| 164 | try expect(math.isNan(tanh64(math.nan(f64)))); | |
| 165 | 165 | } |
lib/std/math/trunc.zig+27-27| ... | ... | @@ -94,49 +94,49 @@ fn trunc128(x: f128) f128 { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "math.trunc" { |
| 97 | expect(trunc(@as(f32, 1.3)) == trunc32(1.3)); | |
| 98 | expect(trunc(@as(f64, 1.3)) == trunc64(1.3)); | |
| 99 | expect(trunc(@as(f128, 1.3)) == trunc128(1.3)); | |
| 97 | try expect(trunc(@as(f32, 1.3)) == trunc32(1.3)); | |
| 98 | try expect(trunc(@as(f64, 1.3)) == trunc64(1.3)); | |
| 99 | try expect(trunc(@as(f128, 1.3)) == trunc128(1.3)); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "math.trunc32" { |
| 103 | expect(trunc32(1.3) == 1.0); | |
| 104 | expect(trunc32(-1.3) == -1.0); | |
| 105 | expect(trunc32(0.2) == 0.0); | |
| 103 | try expect(trunc32(1.3) == 1.0); | |
| 104 | try expect(trunc32(-1.3) == -1.0); | |
| 105 | try expect(trunc32(0.2) == 0.0); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | test "math.trunc64" { |
| 109 | expect(trunc64(1.3) == 1.0); | |
| 110 | expect(trunc64(-1.3) == -1.0); | |
| 111 | expect(trunc64(0.2) == 0.0); | |
| 109 | try expect(trunc64(1.3) == 1.0); | |
| 110 | try expect(trunc64(-1.3) == -1.0); | |
| 111 | try expect(trunc64(0.2) == 0.0); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | test "math.trunc128" { |
| 115 | expect(trunc128(1.3) == 1.0); | |
| 116 | expect(trunc128(-1.3) == -1.0); | |
| 117 | expect(trunc128(0.2) == 0.0); | |
| 115 | try expect(trunc128(1.3) == 1.0); | |
| 116 | try expect(trunc128(-1.3) == -1.0); | |
| 117 | try expect(trunc128(0.2) == 0.0); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "math.trunc32.special" { |
| 121 | expect(trunc32(0.0) == 0.0); // 0x3F800000 | |
| 122 | expect(trunc32(-0.0) == -0.0); | |
| 123 | expect(math.isPositiveInf(trunc32(math.inf(f32)))); | |
| 124 | expect(math.isNegativeInf(trunc32(-math.inf(f32)))); | |
| 125 | expect(math.isNan(trunc32(math.nan(f32)))); | |
| 121 | try expect(trunc32(0.0) == 0.0); // 0x3F800000 | |
| 122 | try expect(trunc32(-0.0) == -0.0); | |
| 123 | try expect(math.isPositiveInf(trunc32(math.inf(f32)))); | |
| 124 | try expect(math.isNegativeInf(trunc32(-math.inf(f32)))); | |
| 125 | try expect(math.isNan(trunc32(math.nan(f32)))); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | test "math.trunc64.special" { |
| 129 | expect(trunc64(0.0) == 0.0); | |
| 130 | expect(trunc64(-0.0) == -0.0); | |
| 131 | expect(math.isPositiveInf(trunc64(math.inf(f64)))); | |
| 132 | expect(math.isNegativeInf(trunc64(-math.inf(f64)))); | |
| 133 | expect(math.isNan(trunc64(math.nan(f64)))); | |
| 129 | try expect(trunc64(0.0) == 0.0); | |
| 130 | try expect(trunc64(-0.0) == -0.0); | |
| 131 | try expect(math.isPositiveInf(trunc64(math.inf(f64)))); | |
| 132 | try expect(math.isNegativeInf(trunc64(-math.inf(f64)))); | |
| 133 | try expect(math.isNan(trunc64(math.nan(f64)))); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "math.trunc128.special" { |
| 137 | expect(trunc128(0.0) == 0.0); | |
| 138 | expect(trunc128(-0.0) == -0.0); | |
| 139 | expect(math.isPositiveInf(trunc128(math.inf(f128)))); | |
| 140 | expect(math.isNegativeInf(trunc128(-math.inf(f128)))); | |
| 141 | expect(math.isNan(trunc128(math.nan(f128)))); | |
| 137 | try expect(trunc128(0.0) == 0.0); | |
| 138 | try expect(trunc128(-0.0) == -0.0); | |
| 139 | try expect(math.isPositiveInf(trunc128(math.inf(f128)))); | |
| 140 | try expect(math.isNegativeInf(trunc128(-math.inf(f128)))); | |
| 141 | try expect(math.isNan(trunc128(math.nan(f128)))); | |
| 142 | 142 | } |
lib/std/mem.zig+359-359| ... | ... | @@ -142,8 +142,8 @@ fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29 |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "mem.Allocator basics" { |
| 145 | testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1)); | |
| 146 | testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0)); | |
| 145 | try testing.expectError(error.OutOfMemory, failAllocator.alloc(u8, 1)); | |
| 146 | try testing.expectError(error.OutOfMemory, failAllocator.allocSentinel(u8, 1, 0)); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /// Copy all of source into dest at position 0. |
| ... | ... | @@ -276,8 +276,8 @@ test "mem.zeroes" { |
| 276 | 276 | var a = zeroes(C_struct); |
| 277 | 277 | a.y += 10; |
| 278 | 278 | |
| 279 | testing.expect(a.x == 0); | |
| 280 | testing.expect(a.y == 10); | |
| 279 | try testing.expect(a.x == 0); | |
| 280 | try testing.expect(a.y == 10); | |
| 281 | 281 | |
| 282 | 282 | const ZigStruct = struct { |
| 283 | 283 | integral_types: struct { |
| ... | ... | @@ -314,32 +314,32 @@ test "mem.zeroes" { |
| 314 | 314 | }; |
| 315 | 315 | |
| 316 | 316 | const b = zeroes(ZigStruct); |
| 317 | testing.expectEqual(@as(i8, 0), b.integral_types.integer_0); | |
| 318 | testing.expectEqual(@as(i8, 0), b.integral_types.integer_8); | |
| 319 | testing.expectEqual(@as(i16, 0), b.integral_types.integer_16); | |
| 320 | testing.expectEqual(@as(i32, 0), b.integral_types.integer_32); | |
| 321 | testing.expectEqual(@as(i64, 0), b.integral_types.integer_64); | |
| 322 | testing.expectEqual(@as(i128, 0), b.integral_types.integer_128); | |
| 323 | testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0); | |
| 324 | testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8); | |
| 325 | testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16); | |
| 326 | testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32); | |
| 327 | testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64); | |
| 328 | testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128); | |
| 329 | testing.expectEqual(@as(f32, 0), b.integral_types.float_32); | |
| 330 | testing.expectEqual(@as(f64, 0), b.integral_types.float_64); | |
| 331 | testing.expectEqual(@as(?*u8, null), b.pointers.optional); | |
| 332 | testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer); | |
| 333 | testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice); | |
| 317 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0); | |
| 318 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8); | |
| 319 | try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16); | |
| 320 | try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32); | |
| 321 | try testing.expectEqual(@as(i64, 0), b.integral_types.integer_64); | |
| 322 | try testing.expectEqual(@as(i128, 0), b.integral_types.integer_128); | |
| 323 | try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_0); | |
| 324 | try testing.expectEqual(@as(u8, 0), b.integral_types.unsigned_8); | |
| 325 | try testing.expectEqual(@as(u16, 0), b.integral_types.unsigned_16); | |
| 326 | try testing.expectEqual(@as(u32, 0), b.integral_types.unsigned_32); | |
| 327 | try testing.expectEqual(@as(u64, 0), b.integral_types.unsigned_64); | |
| 328 | try testing.expectEqual(@as(u128, 0), b.integral_types.unsigned_128); | |
| 329 | try testing.expectEqual(@as(f32, 0), b.integral_types.float_32); | |
| 330 | try testing.expectEqual(@as(f64, 0), b.integral_types.float_64); | |
| 331 | try testing.expectEqual(@as(?*u8, null), b.pointers.optional); | |
| 332 | try testing.expectEqual(@as([*c]u8, null), b.pointers.c_pointer); | |
| 333 | try testing.expectEqual(@as([]u8, &[_]u8{}), b.pointers.slice); | |
| 334 | 334 | for (b.array) |e| { |
| 335 | testing.expectEqual(@as(u32, 0), e); | |
| 335 | try testing.expectEqual(@as(u32, 0), e); | |
| 336 | 336 | } |
| 337 | testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32); | |
| 338 | testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32); | |
| 339 | testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool); | |
| 340 | testing.expectEqual(@as(?u8, null), b.optional_int); | |
| 337 | try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32); | |
| 338 | try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32); | |
| 339 | try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool); | |
| 340 | try testing.expectEqual(@as(?u8, null), b.optional_int); | |
| 341 | 341 | for (b.sentinel) |e| { |
| 342 | testing.expectEqual(@as(u8, 0), e); | |
| 342 | try testing.expectEqual(@as(u8, 0), e); | |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | const C_union = extern union { |
| ... | ... | @@ -348,7 +348,7 @@ test "mem.zeroes" { |
| 348 | 348 | }; |
| 349 | 349 | |
| 350 | 350 | var c = zeroes(C_union); |
| 351 | testing.expectEqual(@as(u8, 0), c.a); | |
| 351 | try testing.expectEqual(@as(u8, 0), c.a); | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /// Initializes all fields of the struct with their default value, or zero values if no default value is present. |
| ... | ... | @@ -421,7 +421,7 @@ test "zeroInit" { |
| 421 | 421 | .a = 42, |
| 422 | 422 | }); |
| 423 | 423 | |
| 424 | testing.expectEqual(S{ | |
| 424 | try testing.expectEqual(S{ | |
| 425 | 425 | .a = 42, |
| 426 | 426 | .b = null, |
| 427 | 427 | .c = .{ |
| ... | ... | @@ -439,7 +439,7 @@ test "zeroInit" { |
| 439 | 439 | }; |
| 440 | 440 | |
| 441 | 441 | const c = zeroInit(Color, .{ 255, 255 }); |
| 442 | testing.expectEqual(Color{ | |
| 442 | try testing.expectEqual(Color{ | |
| 443 | 443 | .r = 255, |
| 444 | 444 | .g = 255, |
| 445 | 445 | .b = 0, |
| ... | ... | @@ -462,11 +462,11 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order { |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | test "order" { |
| 465 | testing.expect(order(u8, "abcd", "bee") == .lt); | |
| 466 | testing.expect(order(u8, "abc", "abc") == .eq); | |
| 467 | testing.expect(order(u8, "abc", "abc0") == .lt); | |
| 468 | testing.expect(order(u8, "", "") == .eq); | |
| 469 | testing.expect(order(u8, "", "a") == .lt); | |
| 465 | try testing.expect(order(u8, "abcd", "bee") == .lt); | |
| 466 | try testing.expect(order(u8, "abc", "abc") == .eq); | |
| 467 | try testing.expect(order(u8, "abc", "abc0") == .lt); | |
| 468 | try testing.expect(order(u8, "", "") == .eq); | |
| 469 | try testing.expect(order(u8, "", "a") == .lt); | |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /// Returns true if lhs < rhs, false otherwise |
| ... | ... | @@ -475,11 +475,11 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool { |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | test "mem.lessThan" { |
| 478 | testing.expect(lessThan(u8, "abcd", "bee")); | |
| 479 | testing.expect(!lessThan(u8, "abc", "abc")); | |
| 480 | testing.expect(lessThan(u8, "abc", "abc0")); | |
| 481 | testing.expect(!lessThan(u8, "", "")); | |
| 482 | testing.expect(lessThan(u8, "", "a")); | |
| 478 | try testing.expect(lessThan(u8, "abcd", "bee")); | |
| 479 | try testing.expect(!lessThan(u8, "abc", "abc")); | |
| 480 | try testing.expect(lessThan(u8, "abc", "abc0")); | |
| 481 | try testing.expect(!lessThan(u8, "", "")); | |
| 482 | try testing.expect(lessThan(u8, "", "a")); | |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /// Compares two slices and returns whether they are equal. |
| ... | ... | @@ -504,11 +504,11 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize { |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | test "indexOfDiff" { |
| 507 | testing.expectEqual(indexOfDiff(u8, "one", "one"), null); | |
| 508 | testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3); | |
| 509 | testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3); | |
| 510 | testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6); | |
| 511 | testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0); | |
| 507 | try testing.expectEqual(indexOfDiff(u8, "one", "one"), null); | |
| 508 | try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3); | |
| 509 | try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3); | |
| 510 | try testing.expectEqual(indexOfDiff(u8, "one twx", "one two"), 6); | |
| 511 | try testing.expectEqual(indexOfDiff(u8, "xne", "one"), 0); | |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ"); |
| ... | ... | @@ -548,26 +548,26 @@ pub fn Span(comptime T: type) type { |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | test "Span" { |
| 551 | testing.expect(Span(*[5]u16) == []u16); | |
| 552 | testing.expect(Span(?*[5]u16) == ?[]u16); | |
| 553 | testing.expect(Span(*const [5]u16) == []const u16); | |
| 554 | testing.expect(Span(?*const [5]u16) == ?[]const u16); | |
| 555 | testing.expect(Span([]u16) == []u16); | |
| 556 | testing.expect(Span(?[]u16) == ?[]u16); | |
| 557 | testing.expect(Span([]const u8) == []const u8); | |
| 558 | testing.expect(Span(?[]const u8) == ?[]const u8); | |
| 559 | testing.expect(Span([:1]u16) == [:1]u16); | |
| 560 | testing.expect(Span(?[:1]u16) == ?[:1]u16); | |
| 561 | testing.expect(Span([:1]const u8) == [:1]const u8); | |
| 562 | testing.expect(Span(?[:1]const u8) == ?[:1]const u8); | |
| 563 | testing.expect(Span([*:1]u16) == [:1]u16); | |
| 564 | testing.expect(Span(?[*:1]u16) == ?[:1]u16); | |
| 565 | testing.expect(Span([*:1]const u8) == [:1]const u8); | |
| 566 | testing.expect(Span(?[*:1]const u8) == ?[:1]const u8); | |
| 567 | testing.expect(Span([*c]u16) == [:0]u16); | |
| 568 | testing.expect(Span(?[*c]u16) == ?[:0]u16); | |
| 569 | testing.expect(Span([*c]const u8) == [:0]const u8); | |
| 570 | testing.expect(Span(?[*c]const u8) == ?[:0]const u8); | |
| 551 | try testing.expect(Span(*[5]u16) == []u16); | |
| 552 | try testing.expect(Span(?*[5]u16) == ?[]u16); | |
| 553 | try testing.expect(Span(*const [5]u16) == []const u16); | |
| 554 | try testing.expect(Span(?*const [5]u16) == ?[]const u16); | |
| 555 | try testing.expect(Span([]u16) == []u16); | |
| 556 | try testing.expect(Span(?[]u16) == ?[]u16); | |
| 557 | try testing.expect(Span([]const u8) == []const u8); | |
| 558 | try testing.expect(Span(?[]const u8) == ?[]const u8); | |
| 559 | try testing.expect(Span([:1]u16) == [:1]u16); | |
| 560 | try testing.expect(Span(?[:1]u16) == ?[:1]u16); | |
| 561 | try testing.expect(Span([:1]const u8) == [:1]const u8); | |
| 562 | try testing.expect(Span(?[:1]const u8) == ?[:1]const u8); | |
| 563 | try testing.expect(Span([*:1]u16) == [:1]u16); | |
| 564 | try testing.expect(Span(?[*:1]u16) == ?[:1]u16); | |
| 565 | try testing.expect(Span([*:1]const u8) == [:1]const u8); | |
| 566 | try testing.expect(Span(?[*:1]const u8) == ?[:1]const u8); | |
| 567 | try testing.expect(Span([*c]u16) == [:0]u16); | |
| 568 | try testing.expect(Span(?[*c]u16) == ?[:0]u16); | |
| 569 | try testing.expect(Span([*c]const u8) == [:0]const u8); | |
| 570 | try testing.expect(Span(?[*c]const u8) == ?[:0]const u8); | |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and |
| ... | ... | @@ -597,9 +597,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) { |
| 597 | 597 | test "span" { |
| 598 | 598 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; |
| 599 | 599 | const ptr = @as([*:3]u16, array[0..2 :3]); |
| 600 | testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 })); | |
| 601 | testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 })); | |
| 602 | testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null))); | |
| 600 | try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 })); | |
| 601 | try testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 })); | |
| 602 | try testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null))); | |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /// Same as `span`, except when there is both a sentinel and an array |
| ... | ... | @@ -625,9 +625,9 @@ pub fn spanZ(ptr: anytype) Span(@TypeOf(ptr)) { |
| 625 | 625 | test "spanZ" { |
| 626 | 626 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; |
| 627 | 627 | const ptr = @as([*:3]u16, array[0..2 :3]); |
| 628 | testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 })); | |
| 629 | testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 })); | |
| 630 | testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null))); | |
| 628 | try testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 })); | |
| 629 | try testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 })); | |
| 630 | try testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null))); | |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /// Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer, |
| ... | ... | @@ -661,30 +661,30 @@ pub fn len(value: anytype) usize { |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | test "len" { |
| 664 | testing.expect(len("aoeu") == 4); | |
| 664 | try testing.expect(len("aoeu") == 4); | |
| 665 | 665 | |
| 666 | 666 | { |
| 667 | 667 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; |
| 668 | testing.expect(len(&array) == 5); | |
| 669 | testing.expect(len(array[0..3]) == 3); | |
| 668 | try testing.expect(len(&array) == 5); | |
| 669 | try testing.expect(len(array[0..3]) == 3); | |
| 670 | 670 | array[2] = 0; |
| 671 | 671 | const ptr = @as([*:0]u16, array[0..2 :0]); |
| 672 | testing.expect(len(ptr) == 2); | |
| 672 | try testing.expect(len(ptr) == 2); | |
| 673 | 673 | } |
| 674 | 674 | { |
| 675 | 675 | var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; |
| 676 | testing.expect(len(&array) == 5); | |
| 676 | try testing.expect(len(&array) == 5); | |
| 677 | 677 | array[2] = 0; |
| 678 | testing.expect(len(&array) == 5); | |
| 678 | try testing.expect(len(&array) == 5); | |
| 679 | 679 | } |
| 680 | 680 | { |
| 681 | 681 | const vector: meta.Vector(2, u32) = [2]u32{ 1, 2 }; |
| 682 | testing.expect(len(vector) == 2); | |
| 682 | try testing.expect(len(vector) == 2); | |
| 683 | 683 | } |
| 684 | 684 | { |
| 685 | 685 | const tuple = .{ 1, 2 }; |
| 686 | testing.expect(len(tuple) == 2); | |
| 687 | testing.expect(tuple[0] == 1); | |
| 686 | try testing.expect(len(tuple) == 2); | |
| 687 | try testing.expect(tuple[0] == 1); | |
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | |
| ... | ... | @@ -725,21 +725,21 @@ pub fn lenZ(ptr: anytype) usize { |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | test "lenZ" { |
| 728 | testing.expect(lenZ("aoeu") == 4); | |
| 728 | try testing.expect(lenZ("aoeu") == 4); | |
| 729 | 729 | |
| 730 | 730 | { |
| 731 | 731 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; |
| 732 | testing.expect(lenZ(&array) == 5); | |
| 733 | testing.expect(lenZ(array[0..3]) == 3); | |
| 732 | try testing.expect(lenZ(&array) == 5); | |
| 733 | try testing.expect(lenZ(array[0..3]) == 3); | |
| 734 | 734 | array[2] = 0; |
| 735 | 735 | const ptr = @as([*:0]u16, array[0..2 :0]); |
| 736 | testing.expect(lenZ(ptr) == 2); | |
| 736 | try testing.expect(lenZ(ptr) == 2); | |
| 737 | 737 | } |
| 738 | 738 | { |
| 739 | 739 | var array: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; |
| 740 | testing.expect(lenZ(&array) == 5); | |
| 740 | try testing.expect(lenZ(&array) == 5); | |
| 741 | 741 | array[2] = 0; |
| 742 | testing.expect(lenZ(&array) == 2); | |
| 742 | try testing.expect(lenZ(&array) == 2); | |
| 743 | 743 | } |
| 744 | 744 | } |
| 745 | 745 | |
| ... | ... | @@ -793,10 +793,10 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | test "mem.trim" { |
| 796 | testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); | |
| 797 | testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); | |
| 798 | testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); | |
| 799 | testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n")); | |
| 796 | try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); | |
| 797 | try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); | |
| 798 | try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); | |
| 799 | try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n")); | |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /// Linear search for the index of a scalar value inside a slice. |
| ... | ... | @@ -951,28 +951,28 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | test "mem.indexOf" { |
| 954 | testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | |
| 955 | testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | |
| 956 | testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); | |
| 957 | testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); | |
| 958 | ||
| 959 | testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0); | |
| 960 | testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48); | |
| 961 | ||
| 962 | testing.expect(indexOf(u8, "one two three four", "four").? == 14); | |
| 963 | testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14); | |
| 964 | testing.expect(indexOf(u8, "one two three four", "gour") == null); | |
| 965 | testing.expect(lastIndexOf(u8, "one two three four", "gour") == null); | |
| 966 | testing.expect(indexOf(u8, "foo", "foo").? == 0); | |
| 967 | testing.expect(lastIndexOf(u8, "foo", "foo").? == 0); | |
| 968 | testing.expect(indexOf(u8, "foo", "fool") == null); | |
| 969 | testing.expect(lastIndexOf(u8, "foo", "lfoo") == null); | |
| 970 | testing.expect(lastIndexOf(u8, "foo", "fool") == null); | |
| 971 | ||
| 972 | testing.expect(indexOf(u8, "foo foo", "foo").? == 0); | |
| 973 | testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4); | |
| 974 | testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6); | |
| 975 | testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2); | |
| 954 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | |
| 955 | try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | |
| 956 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); | |
| 957 | try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); | |
| 958 | ||
| 959 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0); | |
| 960 | try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48); | |
| 961 | ||
| 962 | try testing.expect(indexOf(u8, "one two three four", "four").? == 14); | |
| 963 | try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14); | |
| 964 | try testing.expect(indexOf(u8, "one two three four", "gour") == null); | |
| 965 | try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null); | |
| 966 | try testing.expect(indexOf(u8, "foo", "foo").? == 0); | |
| 967 | try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0); | |
| 968 | try testing.expect(indexOf(u8, "foo", "fool") == null); | |
| 969 | try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null); | |
| 970 | try testing.expect(lastIndexOf(u8, "foo", "fool") == null); | |
| 971 | ||
| 972 | try testing.expect(indexOf(u8, "foo foo", "foo").? == 0); | |
| 973 | try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4); | |
| 974 | try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6); | |
| 975 | try testing.expect(lastIndexOfScalar(u8, "boo", 'o').? == 2); | |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | /// Returns the number of needles inside the haystack |
| ... | ... | @@ -992,17 +992,17 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize { |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | test "mem.count" { |
| 995 | testing.expect(count(u8, "", "h") == 0); | |
| 996 | testing.expect(count(u8, "h", "h") == 1); | |
| 997 | testing.expect(count(u8, "hh", "h") == 2); | |
| 998 | testing.expect(count(u8, "world!", "hello") == 0); | |
| 999 | testing.expect(count(u8, "hello world!", "hello") == 1); | |
| 1000 | testing.expect(count(u8, " abcabc abc", "abc") == 3); | |
| 1001 | testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1); | |
| 1002 | testing.expect(count(u8, "foo bar", "o bar") == 1); | |
| 1003 | testing.expect(count(u8, "foofoofoo", "foo") == 3); | |
| 1004 | testing.expect(count(u8, "fffffff", "ff") == 3); | |
| 1005 | testing.expect(count(u8, "owowowu", "owowu") == 1); | |
| 995 | try testing.expect(count(u8, "", "h") == 0); | |
| 996 | try testing.expect(count(u8, "h", "h") == 1); | |
| 997 | try testing.expect(count(u8, "hh", "h") == 2); | |
| 998 | try testing.expect(count(u8, "world!", "hello") == 0); | |
| 999 | try testing.expect(count(u8, "hello world!", "hello") == 1); | |
| 1000 | try testing.expect(count(u8, " abcabc abc", "abc") == 3); | |
| 1001 | try testing.expect(count(u8, "udexdcbvbruhasdrw", "bruh") == 1); | |
| 1002 | try testing.expect(count(u8, "foo bar", "o bar") == 1); | |
| 1003 | try testing.expect(count(u8, "foofoofoo", "foo") == 3); | |
| 1004 | try testing.expect(count(u8, "fffffff", "ff") == 3); | |
| 1005 | try testing.expect(count(u8, "owowowu", "owowu") == 1); | |
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /// Returns true if the haystack contains expected_count or more needles |
| ... | ... | @@ -1024,19 +1024,19 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | test "mem.containsAtLeast" { |
| 1027 | testing.expect(containsAtLeast(u8, "aa", 0, "a")); | |
| 1028 | testing.expect(containsAtLeast(u8, "aa", 1, "a")); | |
| 1029 | testing.expect(containsAtLeast(u8, "aa", 2, "a")); | |
| 1030 | testing.expect(!containsAtLeast(u8, "aa", 3, "a")); | |
| 1027 | try testing.expect(containsAtLeast(u8, "aa", 0, "a")); | |
| 1028 | try testing.expect(containsAtLeast(u8, "aa", 1, "a")); | |
| 1029 | try testing.expect(containsAtLeast(u8, "aa", 2, "a")); | |
| 1030 | try testing.expect(!containsAtLeast(u8, "aa", 3, "a")); | |
| 1031 | 1031 | |
| 1032 | testing.expect(containsAtLeast(u8, "radaradar", 1, "radar")); | |
| 1033 | testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar")); | |
| 1032 | try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar")); | |
| 1033 | try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar")); | |
| 1034 | 1034 | |
| 1035 | testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar")); | |
| 1036 | testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar")); | |
| 1035 | try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar")); | |
| 1036 | try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar")); | |
| 1037 | 1037 | |
| 1038 | testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar")); | |
| 1039 | testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar")); | |
| 1038 | try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar")); | |
| 1039 | try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar")); | |
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /// Reads an integer from memory with size equal to bytes.len. |
| ... | ... | @@ -1141,34 +1141,34 @@ test "comptime read/write int" { |
| 1141 | 1141 | var bytes: [2]u8 = undefined; |
| 1142 | 1142 | writeIntLittle(u16, &bytes, 0x1234); |
| 1143 | 1143 | const result = readIntBig(u16, &bytes); |
| 1144 | testing.expect(result == 0x3412); | |
| 1144 | try testing.expect(result == 0x3412); | |
| 1145 | 1145 | } |
| 1146 | 1146 | comptime { |
| 1147 | 1147 | var bytes: [2]u8 = undefined; |
| 1148 | 1148 | writeIntBig(u16, &bytes, 0x1234); |
| 1149 | 1149 | const result = readIntLittle(u16, &bytes); |
| 1150 | testing.expect(result == 0x3412); | |
| 1150 | try testing.expect(result == 0x3412); | |
| 1151 | 1151 | } |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | test "readIntBig and readIntLittle" { |
| 1155 | testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); | |
| 1156 | testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); | |
| 1155 | try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); | |
| 1156 | try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); | |
| 1157 | 1157 | |
| 1158 | testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32); | |
| 1159 | testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12); | |
| 1158 | try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32); | |
| 1159 | try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12); | |
| 1160 | 1160 | |
| 1161 | testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234); | |
| 1162 | testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412); | |
| 1161 | try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234); | |
| 1162 | try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412); | |
| 1163 | 1163 | |
| 1164 | testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); | |
| 1165 | testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); | |
| 1164 | try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); | |
| 1165 | try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); | |
| 1166 | 1166 | |
| 1167 | testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1); | |
| 1168 | testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2); | |
| 1167 | try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1); | |
| 1168 | try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2); | |
| 1169 | 1169 | |
| 1170 | testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3); | |
| 1171 | testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4); | |
| 1170 | try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3); | |
| 1171 | try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4); | |
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /// Writes an integer to memory, storing it in twos-complement. |
| ... | ... | @@ -1283,34 +1283,34 @@ test "writeIntBig and writeIntLittle" { |
| 1283 | 1283 | var buf9: [9]u8 = undefined; |
| 1284 | 1284 | |
| 1285 | 1285 | writeIntBig(u0, &buf0, 0x0); |
| 1286 | testing.expect(eql(u8, buf0[0..], &[_]u8{})); | |
| 1286 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); | |
| 1287 | 1287 | writeIntLittle(u0, &buf0, 0x0); |
| 1288 | testing.expect(eql(u8, buf0[0..], &[_]u8{})); | |
| 1288 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); | |
| 1289 | 1289 | |
| 1290 | 1290 | writeIntBig(u8, &buf1, 0x12); |
| 1291 | testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); | |
| 1291 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); | |
| 1292 | 1292 | writeIntLittle(u8, &buf1, 0x34); |
| 1293 | testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); | |
| 1293 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); | |
| 1294 | 1294 | |
| 1295 | 1295 | writeIntBig(u16, &buf2, 0x1234); |
| 1296 | testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); | |
| 1296 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); | |
| 1297 | 1297 | writeIntLittle(u16, &buf2, 0x5678); |
| 1298 | testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); | |
| 1298 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); | |
| 1299 | 1299 | |
| 1300 | 1300 | writeIntBig(u72, &buf9, 0x123456789abcdef024); |
| 1301 | testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 1301 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | |
| 1302 | 1302 | writeIntLittle(u72, &buf9, 0xfedcba9876543210ec); |
| 1303 | testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 1303 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | |
| 1304 | 1304 | |
| 1305 | 1305 | writeIntBig(i8, &buf1, -1); |
| 1306 | testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); | |
| 1306 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); | |
| 1307 | 1307 | writeIntLittle(i8, &buf1, -2); |
| 1308 | testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); | |
| 1308 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); | |
| 1309 | 1309 | |
| 1310 | 1310 | writeIntBig(i16, &buf2, -3); |
| 1311 | testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); | |
| 1311 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); | |
| 1312 | 1312 | writeIntLittle(i16, &buf2, -4); |
| 1313 | testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); | |
| 1313 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); | |
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | 1316 | /// Returns an iterator that iterates over the slices of `buffer` that are not |
| ... | ... | @@ -1331,60 +1331,60 @@ pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator { |
| 1331 | 1331 | |
| 1332 | 1332 | test "mem.tokenize" { |
| 1333 | 1333 | var it = tokenize(" abc def ghi ", " "); |
| 1334 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 1335 | testing.expect(eql(u8, it.next().?, "def")); | |
| 1336 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1337 | testing.expect(it.next() == null); | |
| 1334 | try testing.expect(eql(u8, it.next().?, "abc")); | |
| 1335 | try testing.expect(eql(u8, it.next().?, "def")); | |
| 1336 | try testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1337 | try testing.expect(it.next() == null); | |
| 1338 | 1338 | |
| 1339 | 1339 | it = tokenize("..\\bob", "\\"); |
| 1340 | testing.expect(eql(u8, it.next().?, "..")); | |
| 1341 | testing.expect(eql(u8, "..", "..\\bob"[0..it.index])); | |
| 1342 | testing.expect(eql(u8, it.next().?, "bob")); | |
| 1343 | testing.expect(it.next() == null); | |
| 1340 | try testing.expect(eql(u8, it.next().?, "..")); | |
| 1341 | try testing.expect(eql(u8, "..", "..\\bob"[0..it.index])); | |
| 1342 | try testing.expect(eql(u8, it.next().?, "bob")); | |
| 1343 | try testing.expect(it.next() == null); | |
| 1344 | 1344 | |
| 1345 | 1345 | it = tokenize("//a/b", "/"); |
| 1346 | testing.expect(eql(u8, it.next().?, "a")); | |
| 1347 | testing.expect(eql(u8, it.next().?, "b")); | |
| 1348 | testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index])); | |
| 1349 | testing.expect(it.next() == null); | |
| 1346 | try testing.expect(eql(u8, it.next().?, "a")); | |
| 1347 | try testing.expect(eql(u8, it.next().?, "b")); | |
| 1348 | try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index])); | |
| 1349 | try testing.expect(it.next() == null); | |
| 1350 | 1350 | |
| 1351 | 1351 | it = tokenize("|", "|"); |
| 1352 | testing.expect(it.next() == null); | |
| 1352 | try testing.expect(it.next() == null); | |
| 1353 | 1353 | |
| 1354 | 1354 | it = tokenize("", "|"); |
| 1355 | testing.expect(it.next() == null); | |
| 1355 | try testing.expect(it.next() == null); | |
| 1356 | 1356 | |
| 1357 | 1357 | it = tokenize("hello", ""); |
| 1358 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 1359 | testing.expect(it.next() == null); | |
| 1358 | try testing.expect(eql(u8, it.next().?, "hello")); | |
| 1359 | try testing.expect(it.next() == null); | |
| 1360 | 1360 | |
| 1361 | 1361 | it = tokenize("hello", " "); |
| 1362 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 1363 | testing.expect(it.next() == null); | |
| 1362 | try testing.expect(eql(u8, it.next().?, "hello")); | |
| 1363 | try testing.expect(it.next() == null); | |
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | 1366 | test "mem.tokenize (multibyte)" { |
| 1367 | 1367 | var it = tokenize("a|b,c/d e", " /,|"); |
| 1368 | testing.expect(eql(u8, it.next().?, "a")); | |
| 1369 | testing.expect(eql(u8, it.next().?, "b")); | |
| 1370 | testing.expect(eql(u8, it.next().?, "c")); | |
| 1371 | testing.expect(eql(u8, it.next().?, "d")); | |
| 1372 | testing.expect(eql(u8, it.next().?, "e")); | |
| 1373 | testing.expect(it.next() == null); | |
| 1368 | try testing.expect(eql(u8, it.next().?, "a")); | |
| 1369 | try testing.expect(eql(u8, it.next().?, "b")); | |
| 1370 | try testing.expect(eql(u8, it.next().?, "c")); | |
| 1371 | try testing.expect(eql(u8, it.next().?, "d")); | |
| 1372 | try testing.expect(eql(u8, it.next().?, "e")); | |
| 1373 | try testing.expect(it.next() == null); | |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | test "mem.tokenize (reset)" { |
| 1377 | 1377 | var it = tokenize(" abc def ghi ", " "); |
| 1378 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 1379 | testing.expect(eql(u8, it.next().?, "def")); | |
| 1380 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1378 | try testing.expect(eql(u8, it.next().?, "abc")); | |
| 1379 | try testing.expect(eql(u8, it.next().?, "def")); | |
| 1380 | try testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1381 | 1381 | |
| 1382 | 1382 | it.reset(); |
| 1383 | 1383 | |
| 1384 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 1385 | testing.expect(eql(u8, it.next().?, "def")); | |
| 1386 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1387 | testing.expect(it.next() == null); | |
| 1384 | try testing.expect(eql(u8, it.next().?, "abc")); | |
| 1385 | try testing.expect(eql(u8, it.next().?, "def")); | |
| 1386 | try testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1387 | try testing.expect(it.next() == null); | |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | /// Returns an iterator that iterates over the slices of `buffer` that |
| ... | ... | @@ -1408,34 +1408,34 @@ pub const separate = @compileError("deprecated: renamed to split (behavior remai |
| 1408 | 1408 | |
| 1409 | 1409 | test "mem.split" { |
| 1410 | 1410 | var it = split("abc|def||ghi", "|"); |
| 1411 | testing.expect(eql(u8, it.next().?, "abc")); | |
| 1412 | testing.expect(eql(u8, it.next().?, "def")); | |
| 1413 | testing.expect(eql(u8, it.next().?, "")); | |
| 1414 | testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1415 | testing.expect(it.next() == null); | |
| 1411 | try testing.expect(eql(u8, it.next().?, "abc")); | |
| 1412 | try testing.expect(eql(u8, it.next().?, "def")); | |
| 1413 | try testing.expect(eql(u8, it.next().?, "")); | |
| 1414 | try testing.expect(eql(u8, it.next().?, "ghi")); | |
| 1415 | try testing.expect(it.next() == null); | |
| 1416 | 1416 | |
| 1417 | 1417 | it = split("", "|"); |
| 1418 | testing.expect(eql(u8, it.next().?, "")); | |
| 1419 | testing.expect(it.next() == null); | |
| 1418 | try testing.expect(eql(u8, it.next().?, "")); | |
| 1419 | try testing.expect(it.next() == null); | |
| 1420 | 1420 | |
| 1421 | 1421 | it = split("|", "|"); |
| 1422 | testing.expect(eql(u8, it.next().?, "")); | |
| 1423 | testing.expect(eql(u8, it.next().?, "")); | |
| 1424 | testing.expect(it.next() == null); | |
| 1422 | try testing.expect(eql(u8, it.next().?, "")); | |
| 1423 | try testing.expect(eql(u8, it.next().?, "")); | |
| 1424 | try testing.expect(it.next() == null); | |
| 1425 | 1425 | |
| 1426 | 1426 | it = split("hello", " "); |
| 1427 | testing.expect(eql(u8, it.next().?, "hello")); | |
| 1428 | testing.expect(it.next() == null); | |
| 1427 | try testing.expect(eql(u8, it.next().?, "hello")); | |
| 1428 | try testing.expect(it.next() == null); | |
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | test "mem.split (multibyte)" { |
| 1432 | 1432 | var it = split("a, b ,, c, d, e", ", "); |
| 1433 | testing.expect(eql(u8, it.next().?, "a")); | |
| 1434 | testing.expect(eql(u8, it.next().?, "b ,")); | |
| 1435 | testing.expect(eql(u8, it.next().?, "c")); | |
| 1436 | testing.expect(eql(u8, it.next().?, "d")); | |
| 1437 | testing.expect(eql(u8, it.next().?, "e")); | |
| 1438 | testing.expect(it.next() == null); | |
| 1433 | try testing.expect(eql(u8, it.next().?, "a")); | |
| 1434 | try testing.expect(eql(u8, it.next().?, "b ,")); | |
| 1435 | try testing.expect(eql(u8, it.next().?, "c")); | |
| 1436 | try testing.expect(eql(u8, it.next().?, "d")); | |
| 1437 | try testing.expect(eql(u8, it.next().?, "e")); | |
| 1438 | try testing.expect(it.next() == null); | |
| 1439 | 1439 | } |
| 1440 | 1440 | |
| 1441 | 1441 | pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| ... | ... | @@ -1443,8 +1443,8 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | test "mem.startsWith" { |
| 1446 | testing.expect(startsWith(u8, "Bob", "Bo")); | |
| 1447 | testing.expect(!startsWith(u8, "Needle in haystack", "haystack")); | |
| 1446 | try testing.expect(startsWith(u8, "Bob", "Bo")); | |
| 1447 | try testing.expect(!startsWith(u8, "Needle in haystack", "haystack")); | |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| ... | ... | @@ -1452,8 +1452,8 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | test "mem.endsWith" { |
| 1455 | testing.expect(endsWith(u8, "Needle in haystack", "haystack")); | |
| 1456 | testing.expect(!endsWith(u8, "Bob", "Bo")); | |
| 1455 | try testing.expect(endsWith(u8, "Needle in haystack", "haystack")); | |
| 1456 | try testing.expect(!endsWith(u8, "Bob", "Bo")); | |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | pub const TokenIterator = struct { |
| ... | ... | @@ -1571,22 +1571,22 @@ test "mem.join" { |
| 1571 | 1571 | { |
| 1572 | 1572 | const str = try join(testing.allocator, ",", &[_][]const u8{}); |
| 1573 | 1573 | defer testing.allocator.free(str); |
| 1574 | testing.expect(eql(u8, str, "")); | |
| 1574 | try testing.expect(eql(u8, str, "")); | |
| 1575 | 1575 | } |
| 1576 | 1576 | { |
| 1577 | 1577 | const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); |
| 1578 | 1578 | defer testing.allocator.free(str); |
| 1579 | testing.expect(eql(u8, str, "a,b,c")); | |
| 1579 | try testing.expect(eql(u8, str, "a,b,c")); | |
| 1580 | 1580 | } |
| 1581 | 1581 | { |
| 1582 | 1582 | const str = try join(testing.allocator, ",", &[_][]const u8{"a"}); |
| 1583 | 1583 | defer testing.allocator.free(str); |
| 1584 | testing.expect(eql(u8, str, "a")); | |
| 1584 | try testing.expect(eql(u8, str, "a")); | |
| 1585 | 1585 | } |
| 1586 | 1586 | { |
| 1587 | 1587 | const str = try join(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" }); |
| 1588 | 1588 | defer testing.allocator.free(str); |
| 1589 | testing.expect(eql(u8, str, "a,,b,,c")); | |
| 1589 | try testing.expect(eql(u8, str, "a,,b,,c")); | |
| 1590 | 1590 | } |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| ... | ... | @@ -1594,26 +1594,26 @@ test "mem.joinZ" { |
| 1594 | 1594 | { |
| 1595 | 1595 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{}); |
| 1596 | 1596 | defer testing.allocator.free(str); |
| 1597 | testing.expect(eql(u8, str, "")); | |
| 1598 | testing.expectEqual(str[str.len], 0); | |
| 1597 | try testing.expect(eql(u8, str, "")); | |
| 1598 | try testing.expectEqual(str[str.len], 0); | |
| 1599 | 1599 | } |
| 1600 | 1600 | { |
| 1601 | 1601 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "b", "c" }); |
| 1602 | 1602 | defer testing.allocator.free(str); |
| 1603 | testing.expect(eql(u8, str, "a,b,c")); | |
| 1604 | testing.expectEqual(str[str.len], 0); | |
| 1603 | try testing.expect(eql(u8, str, "a,b,c")); | |
| 1604 | try testing.expectEqual(str[str.len], 0); | |
| 1605 | 1605 | } |
| 1606 | 1606 | { |
| 1607 | 1607 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{"a"}); |
| 1608 | 1608 | defer testing.allocator.free(str); |
| 1609 | testing.expect(eql(u8, str, "a")); | |
| 1610 | testing.expectEqual(str[str.len], 0); | |
| 1609 | try testing.expect(eql(u8, str, "a")); | |
| 1610 | try testing.expectEqual(str[str.len], 0); | |
| 1611 | 1611 | } |
| 1612 | 1612 | { |
| 1613 | 1613 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{ "a", "", "b", "", "c" }); |
| 1614 | 1614 | defer testing.allocator.free(str); |
| 1615 | testing.expect(eql(u8, str, "a,,b,,c")); | |
| 1616 | testing.expectEqual(str[str.len], 0); | |
| 1615 | try testing.expect(eql(u8, str, "a,,b,,c")); | |
| 1616 | try testing.expectEqual(str[str.len], 0); | |
| 1617 | 1617 | } |
| 1618 | 1618 | } |
| 1619 | 1619 | |
| ... | ... | @@ -1646,7 +1646,7 @@ test "concat" { |
| 1646 | 1646 | { |
| 1647 | 1647 | const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }); |
| 1648 | 1648 | defer testing.allocator.free(str); |
| 1649 | testing.expect(eql(u8, str, "abcdefghi")); | |
| 1649 | try testing.expect(eql(u8, str, "abcdefghi")); | |
| 1650 | 1650 | } |
| 1651 | 1651 | { |
| 1652 | 1652 | const str = try concat(testing.allocator, u32, &[_][]const u32{ |
| ... | ... | @@ -1656,21 +1656,21 @@ test "concat" { |
| 1656 | 1656 | &[_]u32{5}, |
| 1657 | 1657 | }); |
| 1658 | 1658 | defer testing.allocator.free(str); |
| 1659 | testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 })); | |
| 1659 | try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 })); | |
| 1660 | 1660 | } |
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | test "testStringEquality" { |
| 1664 | testing.expect(eql(u8, "abcd", "abcd")); | |
| 1665 | testing.expect(!eql(u8, "abcdef", "abZdef")); | |
| 1666 | testing.expect(!eql(u8, "abcdefg", "abcdef")); | |
| 1664 | try testing.expect(eql(u8, "abcd", "abcd")); | |
| 1665 | try testing.expect(!eql(u8, "abcdef", "abZdef")); | |
| 1666 | try testing.expect(!eql(u8, "abcdefg", "abcdef")); | |
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | test "testReadInt" { |
| 1670 | testReadIntImpl(); | |
| 1671 | comptime testReadIntImpl(); | |
| 1670 | try testReadIntImpl(); | |
| 1671 | comptime try testReadIntImpl(); | |
| 1672 | 1672 | } |
| 1673 | fn testReadIntImpl() void { | |
| 1673 | fn testReadIntImpl() !void { | |
| 1674 | 1674 | { |
| 1675 | 1675 | const bytes = [_]u8{ |
| 1676 | 1676 | 0x12, |
| ... | ... | @@ -1678,12 +1678,12 @@ fn testReadIntImpl() void { |
| 1678 | 1678 | 0x56, |
| 1679 | 1679 | 0x78, |
| 1680 | 1680 | }; |
| 1681 | testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678); | |
| 1682 | testing.expect(readIntBig(u32, &bytes) == 0x12345678); | |
| 1683 | testing.expect(readIntBig(i32, &bytes) == 0x12345678); | |
| 1684 | testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412); | |
| 1685 | testing.expect(readIntLittle(u32, &bytes) == 0x78563412); | |
| 1686 | testing.expect(readIntLittle(i32, &bytes) == 0x78563412); | |
| 1681 | try testing.expect(readInt(u32, &bytes, builtin.Endian.Big) == 0x12345678); | |
| 1682 | try testing.expect(readIntBig(u32, &bytes) == 0x12345678); | |
| 1683 | try testing.expect(readIntBig(i32, &bytes) == 0x12345678); | |
| 1684 | try testing.expect(readInt(u32, &bytes, builtin.Endian.Little) == 0x78563412); | |
| 1685 | try testing.expect(readIntLittle(u32, &bytes) == 0x78563412); | |
| 1686 | try testing.expect(readIntLittle(i32, &bytes) == 0x78563412); | |
| 1687 | 1687 | } |
| 1688 | 1688 | { |
| 1689 | 1689 | const buf = [_]u8{ |
| ... | ... | @@ -1693,7 +1693,7 @@ fn testReadIntImpl() void { |
| 1693 | 1693 | 0x34, |
| 1694 | 1694 | }; |
| 1695 | 1695 | const answer = readInt(u32, &buf, builtin.Endian.Big); |
| 1696 | testing.expect(answer == 0x00001234); | |
| 1696 | try testing.expect(answer == 0x00001234); | |
| 1697 | 1697 | } |
| 1698 | 1698 | { |
| 1699 | 1699 | const buf = [_]u8{ |
| ... | ... | @@ -1703,41 +1703,41 @@ fn testReadIntImpl() void { |
| 1703 | 1703 | 0x00, |
| 1704 | 1704 | }; |
| 1705 | 1705 | const answer = readInt(u32, &buf, builtin.Endian.Little); |
| 1706 | testing.expect(answer == 0x00003412); | |
| 1706 | try testing.expect(answer == 0x00003412); | |
| 1707 | 1707 | } |
| 1708 | 1708 | { |
| 1709 | 1709 | const bytes = [_]u8{ |
| 1710 | 1710 | 0xff, |
| 1711 | 1711 | 0xfe, |
| 1712 | 1712 | }; |
| 1713 | testing.expect(readIntBig(u16, &bytes) == 0xfffe); | |
| 1714 | testing.expect(readIntBig(i16, &bytes) == -0x0002); | |
| 1715 | testing.expect(readIntLittle(u16, &bytes) == 0xfeff); | |
| 1716 | testing.expect(readIntLittle(i16, &bytes) == -0x0101); | |
| 1713 | try testing.expect(readIntBig(u16, &bytes) == 0xfffe); | |
| 1714 | try testing.expect(readIntBig(i16, &bytes) == -0x0002); | |
| 1715 | try testing.expect(readIntLittle(u16, &bytes) == 0xfeff); | |
| 1716 | try testing.expect(readIntLittle(i16, &bytes) == -0x0101); | |
| 1717 | 1717 | } |
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | 1720 | test "writeIntSlice" { |
| 1721 | testWriteIntImpl(); | |
| 1722 | comptime testWriteIntImpl(); | |
| 1721 | try testWriteIntImpl(); | |
| 1722 | comptime try testWriteIntImpl(); | |
| 1723 | 1723 | } |
| 1724 | fn testWriteIntImpl() void { | |
| 1724 | fn testWriteIntImpl() !void { | |
| 1725 | 1725 | var bytes: [8]u8 = undefined; |
| 1726 | 1726 | |
| 1727 | 1727 | writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big); |
| 1728 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1728 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1729 | 1729 | 0x00, 0x00, 0x00, 0x00, |
| 1730 | 1730 | 0x00, 0x00, 0x00, 0x00, |
| 1731 | 1731 | })); |
| 1732 | 1732 | |
| 1733 | 1733 | writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little); |
| 1734 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1734 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1735 | 1735 | 0x00, 0x00, 0x00, 0x00, |
| 1736 | 1736 | 0x00, 0x00, 0x00, 0x00, |
| 1737 | 1737 | })); |
| 1738 | 1738 | |
| 1739 | 1739 | writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big); |
| 1740 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1740 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1741 | 1741 | 0x12, |
| 1742 | 1742 | 0x34, |
| 1743 | 1743 | 0x56, |
| ... | ... | @@ -1749,7 +1749,7 @@ fn testWriteIntImpl() void { |
| 1749 | 1749 | })); |
| 1750 | 1750 | |
| 1751 | 1751 | writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little); |
| 1752 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1752 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1753 | 1753 | 0x12, |
| 1754 | 1754 | 0x34, |
| 1755 | 1755 | 0x56, |
| ... | ... | @@ -1761,7 +1761,7 @@ fn testWriteIntImpl() void { |
| 1761 | 1761 | })); |
| 1762 | 1762 | |
| 1763 | 1763 | writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big); |
| 1764 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1764 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1765 | 1765 | 0x00, |
| 1766 | 1766 | 0x00, |
| 1767 | 1767 | 0x00, |
| ... | ... | @@ -1773,7 +1773,7 @@ fn testWriteIntImpl() void { |
| 1773 | 1773 | })); |
| 1774 | 1774 | |
| 1775 | 1775 | writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little); |
| 1776 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1776 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1777 | 1777 | 0x12, |
| 1778 | 1778 | 0x34, |
| 1779 | 1779 | 0x56, |
| ... | ... | @@ -1785,7 +1785,7 @@ fn testWriteIntImpl() void { |
| 1785 | 1785 | })); |
| 1786 | 1786 | |
| 1787 | 1787 | writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big); |
| 1788 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1788 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1789 | 1789 | 0x00, |
| 1790 | 1790 | 0x00, |
| 1791 | 1791 | 0x00, |
| ... | ... | @@ -1797,7 +1797,7 @@ fn testWriteIntImpl() void { |
| 1797 | 1797 | })); |
| 1798 | 1798 | |
| 1799 | 1799 | writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little); |
| 1800 | testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1800 | try testing.expect(eql(u8, &bytes, &[_]u8{ | |
| 1801 | 1801 | 0x34, |
| 1802 | 1802 | 0x12, |
| 1803 | 1803 | 0x00, |
| ... | ... | @@ -1820,7 +1820,7 @@ pub fn min(comptime T: type, slice: []const T) T { |
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | test "mem.min" { |
| 1823 | testing.expect(min(u8, "abcdefg") == 'a'); | |
| 1823 | try testing.expect(min(u8, "abcdefg") == 'a'); | |
| 1824 | 1824 | } |
| 1825 | 1825 | |
| 1826 | 1826 | /// Returns the largest number in a slice. O(n). |
| ... | ... | @@ -1834,7 +1834,7 @@ pub fn max(comptime T: type, slice: []const T) T { |
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | 1836 | test "mem.max" { |
| 1837 | testing.expect(max(u8, "abcdefg") == 'g'); | |
| 1837 | try testing.expect(max(u8, "abcdefg") == 'g'); | |
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | 1840 | pub fn swap(comptime T: type, a: *T, b: *T) void { |
| ... | ... | @@ -1856,7 +1856,7 @@ test "reverse" { |
| 1856 | 1856 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; |
| 1857 | 1857 | reverse(i32, arr[0..]); |
| 1858 | 1858 | |
| 1859 | testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 })); | |
| 1859 | try testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 })); | |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | /// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) |
| ... | ... | @@ -1871,7 +1871,7 @@ test "rotate" { |
| 1871 | 1871 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; |
| 1872 | 1872 | rotate(i32, arr[0..], 2); |
| 1873 | 1873 | |
| 1874 | testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 })); | |
| 1874 | try testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 })); | |
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | 1877 | /// Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of |
| ... | ... | @@ -1904,31 +1904,31 @@ test "replace" { |
| 1904 | 1904 | var output: [29]u8 = undefined; |
| 1905 | 1905 | var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]); |
| 1906 | 1906 | var expected: []const u8 = "All your Zig are belong to us"; |
| 1907 | testing.expect(replacements == 1); | |
| 1908 | testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1907 | try testing.expect(replacements == 1); | |
| 1908 | try testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1909 | 1909 | |
| 1910 | 1910 | replacements = replace(u8, "Favor reading code over writing code.", "code", "", output[0..]); |
| 1911 | 1911 | expected = "Favor reading over writing ."; |
| 1912 | testing.expect(replacements == 2); | |
| 1913 | testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1912 | try testing.expect(replacements == 2); | |
| 1913 | try testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1914 | 1914 | |
| 1915 | 1915 | // Empty needle is not allowed but input may be empty. |
| 1916 | 1916 | replacements = replace(u8, "", "x", "y", output[0..0]); |
| 1917 | 1917 | expected = ""; |
| 1918 | testing.expect(replacements == 0); | |
| 1919 | testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1918 | try testing.expect(replacements == 0); | |
| 1919 | try testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1920 | 1920 | |
| 1921 | 1921 | // Adjacent replacements. |
| 1922 | 1922 | |
| 1923 | 1923 | replacements = replace(u8, "\\n\\n", "\\n", "\n", output[0..]); |
| 1924 | 1924 | expected = "\n\n"; |
| 1925 | testing.expect(replacements == 2); | |
| 1926 | testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1925 | try testing.expect(replacements == 2); | |
| 1926 | try testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1927 | 1927 | |
| 1928 | 1928 | replacements = replace(u8, "abbba", "b", "cd", output[0..]); |
| 1929 | 1929 | expected = "acdcdcda"; |
| 1930 | testing.expect(replacements == 3); | |
| 1931 | testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1930 | try testing.expect(replacements == 3); | |
| 1931 | try testing.expectEqualStrings(expected, output[0..expected.len]); | |
| 1932 | 1932 | } |
| 1933 | 1933 | |
| 1934 | 1934 | /// Calculate the size needed in an output buffer to perform a replacement. |
| ... | ... | @@ -1952,16 +1952,16 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re |
| 1952 | 1952 | } |
| 1953 | 1953 | |
| 1954 | 1954 | test "replacementSize" { |
| 1955 | testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29); | |
| 1956 | testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29); | |
| 1957 | testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41); | |
| 1955 | try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29); | |
| 1956 | try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29); | |
| 1957 | try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41); | |
| 1958 | 1958 | |
| 1959 | 1959 | // Empty needle is not allowed but input may be empty. |
| 1960 | testing.expect(replacementSize(u8, "", "x", "y") == 0); | |
| 1960 | try testing.expect(replacementSize(u8, "", "x", "y") == 0); | |
| 1961 | 1961 | |
| 1962 | 1962 | // Adjacent replacements. |
| 1963 | testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2); | |
| 1964 | testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8); | |
| 1963 | try testing.expect(replacementSize(u8, "\\n\\n", "\\n", "\n") == 2); | |
| 1964 | try testing.expect(replacementSize(u8, "abbba", "b", "cd") == 8); | |
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. |
| ... | ... | @@ -1976,11 +1976,11 @@ test "replaceOwned" { |
| 1976 | 1976 | |
| 1977 | 1977 | const base_replace = replaceOwned(u8, allocator, "All your base are belong to us", "base", "Zig") catch unreachable; |
| 1978 | 1978 | defer allocator.free(base_replace); |
| 1979 | testing.expect(eql(u8, base_replace, "All your Zig are belong to us")); | |
| 1979 | try testing.expect(eql(u8, base_replace, "All your Zig are belong to us")); | |
| 1980 | 1980 | |
| 1981 | 1981 | const zen_replace = replaceOwned(u8, allocator, "Favor reading code over writing code.", " code", "") catch unreachable; |
| 1982 | 1982 | defer allocator.free(zen_replace); |
| 1983 | testing.expect(eql(u8, zen_replace, "Favor reading over writing.")); | |
| 1983 | try testing.expect(eql(u8, zen_replace, "Favor reading over writing.")); | |
| 1984 | 1984 | } |
| 1985 | 1985 | |
| 1986 | 1986 | /// Converts a little-endian integer to host endianness. |
| ... | ... | @@ -2068,12 +2068,12 @@ test "asBytes" { |
| 2068 | 2068 | .Little => "\xEF\xBE\xAD\xDE", |
| 2069 | 2069 | }; |
| 2070 | 2070 | |
| 2071 | testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | |
| 2071 | try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | |
| 2072 | 2072 | |
| 2073 | 2073 | var codeface = @as(u32, 0xC0DEFACE); |
| 2074 | 2074 | for (asBytes(&codeface).*) |*b| |
| 2075 | 2075 | b.* = 0; |
| 2076 | testing.expect(codeface == 0); | |
| 2076 | try testing.expect(codeface == 0); | |
| 2077 | 2077 | |
| 2078 | 2078 | const S = packed struct { |
| 2079 | 2079 | a: u8, |
| ... | ... | @@ -2088,11 +2088,11 @@ test "asBytes" { |
| 2088 | 2088 | .c = 0xDE, |
| 2089 | 2089 | .d = 0xA1, |
| 2090 | 2090 | }; |
| 2091 | testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | |
| 2091 | try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | |
| 2092 | 2092 | |
| 2093 | 2093 | const ZST = struct {}; |
| 2094 | 2094 | const zero = ZST{}; |
| 2095 | testing.expect(eql(u8, asBytes(&zero), "")); | |
| 2095 | try testing.expect(eql(u8, asBytes(&zero), "")); | |
| 2096 | 2096 | } |
| 2097 | 2097 | |
| 2098 | 2098 | test "asBytes preserves pointer attributes" { |
| ... | ... | @@ -2103,10 +2103,10 @@ test "asBytes preserves pointer attributes" { |
| 2103 | 2103 | const in = @typeInfo(@TypeOf(inPtr)).Pointer; |
| 2104 | 2104 | const out = @typeInfo(@TypeOf(outSlice)).Pointer; |
| 2105 | 2105 | |
| 2106 | testing.expectEqual(in.is_const, out.is_const); | |
| 2107 | testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2108 | testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2109 | testing.expectEqual(in.alignment, out.alignment); | |
| 2106 | try testing.expectEqual(in.is_const, out.is_const); | |
| 2107 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2108 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2109 | try testing.expectEqual(in.alignment, out.alignment); | |
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | 2112 | /// Given any value, returns a copy of its bytes in an array. |
| ... | ... | @@ -2117,14 +2117,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { |
| 2117 | 2117 | test "toBytes" { |
| 2118 | 2118 | var my_bytes = toBytes(@as(u32, 0x12345678)); |
| 2119 | 2119 | switch (builtin.endian) { |
| 2120 | .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | |
| 2121 | .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), | |
| 2120 | .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | |
| 2121 | .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), | |
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | 2124 | my_bytes[0] = '\x99'; |
| 2125 | 2125 | switch (builtin.endian) { |
| 2126 | .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), | |
| 2127 | .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), | |
| 2126 | .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), | |
| 2127 | .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), | |
| 2128 | 2128 | } |
| 2129 | 2129 | } |
| 2130 | 2130 | |
| ... | ... | @@ -2154,17 +2154,17 @@ test "bytesAsValue" { |
| 2154 | 2154 | .Little => "\xEF\xBE\xAD\xDE", |
| 2155 | 2155 | }; |
| 2156 | 2156 | |
| 2157 | testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); | |
| 2157 | try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); | |
| 2158 | 2158 | |
| 2159 | 2159 | var codeface_bytes: [4]u8 = switch (builtin.endian) { |
| 2160 | 2160 | .Big => "\xC0\xDE\xFA\xCE", |
| 2161 | 2161 | .Little => "\xCE\xFA\xDE\xC0", |
| 2162 | 2162 | }.*; |
| 2163 | 2163 | var codeface = bytesAsValue(u32, &codeface_bytes); |
| 2164 | testing.expect(codeface.* == 0xC0DEFACE); | |
| 2164 | try testing.expect(codeface.* == 0xC0DEFACE); | |
| 2165 | 2165 | codeface.* = 0; |
| 2166 | 2166 | for (codeface_bytes) |b| |
| 2167 | testing.expect(b == 0); | |
| 2167 | try testing.expect(b == 0); | |
| 2168 | 2168 | |
| 2169 | 2169 | const S = packed struct { |
| 2170 | 2170 | a: u8, |
| ... | ... | @@ -2181,7 +2181,7 @@ test "bytesAsValue" { |
| 2181 | 2181 | }; |
| 2182 | 2182 | const inst_bytes = "\xBE\xEF\xDE\xA1"; |
| 2183 | 2183 | const inst2 = bytesAsValue(S, inst_bytes); |
| 2184 | testing.expect(meta.eql(inst, inst2.*)); | |
| 2184 | try testing.expect(meta.eql(inst, inst2.*)); | |
| 2185 | 2185 | } |
| 2186 | 2186 | |
| 2187 | 2187 | test "bytesAsValue preserves pointer attributes" { |
| ... | ... | @@ -2192,10 +2192,10 @@ test "bytesAsValue preserves pointer attributes" { |
| 2192 | 2192 | const in = @typeInfo(@TypeOf(inSlice)).Pointer; |
| 2193 | 2193 | const out = @typeInfo(@TypeOf(outPtr)).Pointer; |
| 2194 | 2194 | |
| 2195 | testing.expectEqual(in.is_const, out.is_const); | |
| 2196 | testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2197 | testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2198 | testing.expectEqual(in.alignment, out.alignment); | |
| 2195 | try testing.expectEqual(in.is_const, out.is_const); | |
| 2196 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2197 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2198 | try testing.expectEqual(in.alignment, out.alignment); | |
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | 2201 | /// Given a pointer to an array of bytes, returns a value of the specified type backed by a |
| ... | ... | @@ -2210,7 +2210,7 @@ test "bytesToValue" { |
| 2210 | 2210 | }; |
| 2211 | 2211 | |
| 2212 | 2212 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
| 2213 | testing.expect(deadbeef == @as(u32, 0xDEADBEEF)); | |
| 2213 | try testing.expect(deadbeef == @as(u32, 0xDEADBEEF)); | |
| 2214 | 2214 | } |
| 2215 | 2215 | |
| 2216 | 2216 | fn BytesAsSliceReturnType(comptime T: type, comptime bytesType: type) type { |
| ... | ... | @@ -2243,17 +2243,17 @@ test "bytesAsSlice" { |
| 2243 | 2243 | { |
| 2244 | 2244 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; |
| 2245 | 2245 | const slice = bytesAsSlice(u16, bytes[0..]); |
| 2246 | testing.expect(slice.len == 2); | |
| 2247 | testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); | |
| 2248 | testing.expect(bigToNative(u16, slice[1]) == 0xBEEF); | |
| 2246 | try testing.expect(slice.len == 2); | |
| 2247 | try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); | |
| 2248 | try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF); | |
| 2249 | 2249 | } |
| 2250 | 2250 | { |
| 2251 | 2251 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; |
| 2252 | 2252 | var runtime_zero: usize = 0; |
| 2253 | 2253 | const slice = bytesAsSlice(u16, bytes[runtime_zero..]); |
| 2254 | testing.expect(slice.len == 2); | |
| 2255 | testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); | |
| 2256 | testing.expect(bigToNative(u16, slice[1]) == 0xBEEF); | |
| 2254 | try testing.expect(slice.len == 2); | |
| 2255 | try testing.expect(bigToNative(u16, slice[0]) == 0xDEAD); | |
| 2256 | try testing.expect(bigToNative(u16, slice[1]) == 0xBEEF); | |
| 2257 | 2257 | } |
| 2258 | 2258 | } |
| 2259 | 2259 | |
| ... | ... | @@ -2261,13 +2261,13 @@ test "bytesAsSlice keeps pointer alignment" { |
| 2261 | 2261 | { |
| 2262 | 2262 | var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; |
| 2263 | 2263 | const numbers = bytesAsSlice(u32, bytes[0..]); |
| 2264 | comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); | |
| 2264 | comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); | |
| 2265 | 2265 | } |
| 2266 | 2266 | { |
| 2267 | 2267 | var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; |
| 2268 | 2268 | var runtime_zero: usize = 0; |
| 2269 | 2269 | const numbers = bytesAsSlice(u32, bytes[runtime_zero..]); |
| 2270 | comptime testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); | |
| 2270 | comptime try testing.expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); | |
| 2271 | 2271 | } |
| 2272 | 2272 | } |
| 2273 | 2273 | |
| ... | ... | @@ -2278,7 +2278,7 @@ test "bytesAsSlice on a packed struct" { |
| 2278 | 2278 | |
| 2279 | 2279 | var b = [1]u8{9}; |
| 2280 | 2280 | var f = bytesAsSlice(F, &b); |
| 2281 | testing.expect(f[0].a == 9); | |
| 2281 | try testing.expect(f[0].a == 9); | |
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | test "bytesAsSlice with specified alignment" { |
| ... | ... | @@ -2289,7 +2289,7 @@ test "bytesAsSlice with specified alignment" { |
| 2289 | 2289 | 0x33, |
| 2290 | 2290 | }; |
| 2291 | 2291 | const slice: []u32 = std.mem.bytesAsSlice(u32, bytes[0..]); |
| 2292 | testing.expect(slice[0] == 0x33333333); | |
| 2292 | try testing.expect(slice[0] == 0x33333333); | |
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | 2295 | test "bytesAsSlice preserves pointer attributes" { |
| ... | ... | @@ -2300,10 +2300,10 @@ test "bytesAsSlice preserves pointer attributes" { |
| 2300 | 2300 | const in = @typeInfo(@TypeOf(inSlice)).Pointer; |
| 2301 | 2301 | const out = @typeInfo(@TypeOf(outSlice)).Pointer; |
| 2302 | 2302 | |
| 2303 | testing.expectEqual(in.is_const, out.is_const); | |
| 2304 | testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2305 | testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2306 | testing.expectEqual(in.alignment, out.alignment); | |
| 2303 | try testing.expectEqual(in.is_const, out.is_const); | |
| 2304 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2305 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2306 | try testing.expectEqual(in.alignment, out.alignment); | |
| 2307 | 2307 | } |
| 2308 | 2308 | |
| 2309 | 2309 | fn SliceAsBytesReturnType(comptime sliceType: type) type { |
| ... | ... | @@ -2332,8 +2332,8 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) { |
| 2332 | 2332 | test "sliceAsBytes" { |
| 2333 | 2333 | const bytes = [_]u16{ 0xDEAD, 0xBEEF }; |
| 2334 | 2334 | const slice = sliceAsBytes(bytes[0..]); |
| 2335 | testing.expect(slice.len == 4); | |
| 2336 | testing.expect(eql(u8, slice, switch (builtin.endian) { | |
| 2335 | try testing.expect(slice.len == 4); | |
| 2336 | try testing.expect(eql(u8, slice, switch (builtin.endian) { | |
| 2337 | 2337 | .Big => "\xDE\xAD\xBE\xEF", |
| 2338 | 2338 | .Little => "\xAD\xDE\xEF\xBE", |
| 2339 | 2339 | })); |
| ... | ... | @@ -2342,7 +2342,7 @@ test "sliceAsBytes" { |
| 2342 | 2342 | test "sliceAsBytes with sentinel slice" { |
| 2343 | 2343 | const empty_string: [:0]const u8 = ""; |
| 2344 | 2344 | const bytes = sliceAsBytes(empty_string); |
| 2345 | testing.expect(bytes.len == 0); | |
| 2345 | try testing.expect(bytes.len == 0); | |
| 2346 | 2346 | } |
| 2347 | 2347 | |
| 2348 | 2348 | test "sliceAsBytes packed struct at runtime and comptime" { |
| ... | ... | @@ -2351,49 +2351,49 @@ test "sliceAsBytes packed struct at runtime and comptime" { |
| 2351 | 2351 | b: u4, |
| 2352 | 2352 | }; |
| 2353 | 2353 | const S = struct { |
| 2354 | fn doTheTest() void { | |
| 2354 | fn doTheTest() !void { | |
| 2355 | 2355 | var foo: Foo = undefined; |
| 2356 | 2356 | var slice = sliceAsBytes(@as(*[1]Foo, &foo)[0..1]); |
| 2357 | 2357 | slice[0] = 0x13; |
| 2358 | 2358 | switch (builtin.endian) { |
| 2359 | 2359 | .Big => { |
| 2360 | testing.expect(foo.a == 0x1); | |
| 2361 | testing.expect(foo.b == 0x3); | |
| 2360 | try testing.expect(foo.a == 0x1); | |
| 2361 | try testing.expect(foo.b == 0x3); | |
| 2362 | 2362 | }, |
| 2363 | 2363 | .Little => { |
| 2364 | testing.expect(foo.a == 0x3); | |
| 2365 | testing.expect(foo.b == 0x1); | |
| 2364 | try testing.expect(foo.a == 0x3); | |
| 2365 | try testing.expect(foo.b == 0x1); | |
| 2366 | 2366 | }, |
| 2367 | 2367 | } |
| 2368 | 2368 | } |
| 2369 | 2369 | }; |
| 2370 | S.doTheTest(); | |
| 2371 | comptime S.doTheTest(); | |
| 2370 | try S.doTheTest(); | |
| 2371 | comptime try S.doTheTest(); | |
| 2372 | 2372 | } |
| 2373 | 2373 | |
| 2374 | 2374 | test "sliceAsBytes and bytesAsSlice back" { |
| 2375 | testing.expect(@sizeOf(i32) == 4); | |
| 2375 | try testing.expect(@sizeOf(i32) == 4); | |
| 2376 | 2376 | |
| 2377 | 2377 | var big_thing_array = [_]i32{ 1, 2, 3, 4 }; |
| 2378 | 2378 | const big_thing_slice: []i32 = big_thing_array[0..]; |
| 2379 | 2379 | |
| 2380 | 2380 | const bytes = sliceAsBytes(big_thing_slice); |
| 2381 | testing.expect(bytes.len == 4 * 4); | |
| 2381 | try testing.expect(bytes.len == 4 * 4); | |
| 2382 | 2382 | |
| 2383 | 2383 | bytes[4] = 0; |
| 2384 | 2384 | bytes[5] = 0; |
| 2385 | 2385 | bytes[6] = 0; |
| 2386 | 2386 | bytes[7] = 0; |
| 2387 | testing.expect(big_thing_slice[1] == 0); | |
| 2387 | try testing.expect(big_thing_slice[1] == 0); | |
| 2388 | 2388 | |
| 2389 | 2389 | const big_thing_again = bytesAsSlice(i32, bytes); |
| 2390 | testing.expect(big_thing_again[2] == 3); | |
| 2390 | try testing.expect(big_thing_again[2] == 3); | |
| 2391 | 2391 | |
| 2392 | 2392 | big_thing_again[2] = -1; |
| 2393 | testing.expect(bytes[8] == math.maxInt(u8)); | |
| 2394 | testing.expect(bytes[9] == math.maxInt(u8)); | |
| 2395 | testing.expect(bytes[10] == math.maxInt(u8)); | |
| 2396 | testing.expect(bytes[11] == math.maxInt(u8)); | |
| 2393 | try testing.expect(bytes[8] == math.maxInt(u8)); | |
| 2394 | try testing.expect(bytes[9] == math.maxInt(u8)); | |
| 2395 | try testing.expect(bytes[10] == math.maxInt(u8)); | |
| 2396 | try testing.expect(bytes[11] == math.maxInt(u8)); | |
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | 2399 | test "sliceAsBytes preserves pointer attributes" { |
| ... | ... | @@ -2404,10 +2404,10 @@ test "sliceAsBytes preserves pointer attributes" { |
| 2404 | 2404 | const in = @typeInfo(@TypeOf(inSlice)).Pointer; |
| 2405 | 2405 | const out = @typeInfo(@TypeOf(outSlice)).Pointer; |
| 2406 | 2406 | |
| 2407 | testing.expectEqual(in.is_const, out.is_const); | |
| 2408 | testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2409 | testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2410 | testing.expectEqual(in.alignment, out.alignment); | |
| 2407 | try testing.expectEqual(in.is_const, out.is_const); | |
| 2408 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 2409 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 2410 | try testing.expectEqual(in.alignment, out.alignment); | |
| 2411 | 2411 | } |
| 2412 | 2412 | |
| 2413 | 2413 | /// Round an address up to the nearest aligned address |
| ... | ... | @@ -2434,18 +2434,18 @@ pub fn doNotOptimizeAway(val: anytype) void { |
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | 2436 | test "alignForward" { |
| 2437 | testing.expect(alignForward(1, 1) == 1); | |
| 2438 | testing.expect(alignForward(2, 1) == 2); | |
| 2439 | testing.expect(alignForward(1, 2) == 2); | |
| 2440 | testing.expect(alignForward(2, 2) == 2); | |
| 2441 | testing.expect(alignForward(3, 2) == 4); | |
| 2442 | testing.expect(alignForward(4, 2) == 4); | |
| 2443 | testing.expect(alignForward(7, 8) == 8); | |
| 2444 | testing.expect(alignForward(8, 8) == 8); | |
| 2445 | testing.expect(alignForward(9, 8) == 16); | |
| 2446 | testing.expect(alignForward(15, 8) == 16); | |
| 2447 | testing.expect(alignForward(16, 8) == 16); | |
| 2448 | testing.expect(alignForward(17, 8) == 24); | |
| 2437 | try testing.expect(alignForward(1, 1) == 1); | |
| 2438 | try testing.expect(alignForward(2, 1) == 2); | |
| 2439 | try testing.expect(alignForward(1, 2) == 2); | |
| 2440 | try testing.expect(alignForward(2, 2) == 2); | |
| 2441 | try testing.expect(alignForward(3, 2) == 4); | |
| 2442 | try testing.expect(alignForward(4, 2) == 4); | |
| 2443 | try testing.expect(alignForward(7, 8) == 8); | |
| 2444 | try testing.expect(alignForward(8, 8) == 8); | |
| 2445 | try testing.expect(alignForward(9, 8) == 16); | |
| 2446 | try testing.expect(alignForward(15, 8) == 16); | |
| 2447 | try testing.expect(alignForward(16, 8) == 16); | |
| 2448 | try testing.expect(alignForward(17, 8) == 24); | |
| 2449 | 2449 | } |
| 2450 | 2450 | |
| 2451 | 2451 | /// Round an address up to the previous aligned address |
| ... | ... | @@ -2497,19 +2497,19 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool { |
| 2497 | 2497 | } |
| 2498 | 2498 | |
| 2499 | 2499 | test "isAligned" { |
| 2500 | testing.expect(isAligned(0, 4)); | |
| 2501 | testing.expect(isAligned(1, 1)); | |
| 2502 | testing.expect(isAligned(2, 1)); | |
| 2503 | testing.expect(isAligned(2, 2)); | |
| 2504 | testing.expect(!isAligned(2, 4)); | |
| 2505 | testing.expect(isAligned(3, 1)); | |
| 2506 | testing.expect(!isAligned(3, 2)); | |
| 2507 | testing.expect(!isAligned(3, 4)); | |
| 2508 | testing.expect(isAligned(4, 4)); | |
| 2509 | testing.expect(isAligned(4, 2)); | |
| 2510 | testing.expect(isAligned(4, 1)); | |
| 2511 | testing.expect(!isAligned(4, 8)); | |
| 2512 | testing.expect(!isAligned(4, 16)); | |
| 2500 | try testing.expect(isAligned(0, 4)); | |
| 2501 | try testing.expect(isAligned(1, 1)); | |
| 2502 | try testing.expect(isAligned(2, 1)); | |
| 2503 | try testing.expect(isAligned(2, 2)); | |
| 2504 | try testing.expect(!isAligned(2, 4)); | |
| 2505 | try testing.expect(isAligned(3, 1)); | |
| 2506 | try testing.expect(!isAligned(3, 2)); | |
| 2507 | try testing.expect(!isAligned(3, 4)); | |
| 2508 | try testing.expect(isAligned(4, 4)); | |
| 2509 | try testing.expect(isAligned(4, 2)); | |
| 2510 | try testing.expect(isAligned(4, 1)); | |
| 2511 | try testing.expect(!isAligned(4, 8)); | |
| 2512 | try testing.expect(!isAligned(4, 16)); | |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | 2515 | test "freeing empty string with null-terminated sentinel" { |
lib/std/meta.zig+190-190| ... | ... | @@ -47,16 +47,16 @@ test "std.meta.tagName" { |
| 47 | 47 | var u2a = U2{ .C = 0 }; |
| 48 | 48 | var u2b = U2{ .D = 0 }; |
| 49 | 49 | |
| 50 | testing.expect(mem.eql(u8, tagName(E1.A), "A")); | |
| 51 | testing.expect(mem.eql(u8, tagName(E1.B), "B")); | |
| 52 | testing.expect(mem.eql(u8, tagName(E2.C), "C")); | |
| 53 | testing.expect(mem.eql(u8, tagName(E2.D), "D")); | |
| 54 | testing.expect(mem.eql(u8, tagName(error.E), "E")); | |
| 55 | testing.expect(mem.eql(u8, tagName(error.F), "F")); | |
| 56 | testing.expect(mem.eql(u8, tagName(u1g), "G")); | |
| 57 | testing.expect(mem.eql(u8, tagName(u1h), "H")); | |
| 58 | testing.expect(mem.eql(u8, tagName(u2a), "C")); | |
| 59 | testing.expect(mem.eql(u8, tagName(u2b), "D")); | |
| 50 | try testing.expect(mem.eql(u8, tagName(E1.A), "A")); | |
| 51 | try testing.expect(mem.eql(u8, tagName(E1.B), "B")); | |
| 52 | try testing.expect(mem.eql(u8, tagName(E2.C), "C")); | |
| 53 | try testing.expect(mem.eql(u8, tagName(E2.D), "D")); | |
| 54 | try testing.expect(mem.eql(u8, tagName(error.E), "E")); | |
| 55 | try testing.expect(mem.eql(u8, tagName(error.F), "F")); | |
| 56 | try testing.expect(mem.eql(u8, tagName(u1g), "G")); | |
| 57 | try testing.expect(mem.eql(u8, tagName(u1h), "H")); | |
| 58 | try testing.expect(mem.eql(u8, tagName(u2a), "C")); | |
| 59 | try testing.expect(mem.eql(u8, tagName(u2b), "D")); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | pub fn stringToEnum(comptime T: type, str: []const u8) ?T { |
| ... | ... | @@ -98,9 +98,9 @@ test "std.meta.stringToEnum" { |
| 98 | 98 | A, |
| 99 | 99 | B, |
| 100 | 100 | }; |
| 101 | testing.expect(E1.A == stringToEnum(E1, "A").?); | |
| 102 | testing.expect(E1.B == stringToEnum(E1, "B").?); | |
| 103 | testing.expect(null == stringToEnum(E1, "C")); | |
| 101 | try testing.expect(E1.A == stringToEnum(E1, "A").?); | |
| 102 | try testing.expect(E1.B == stringToEnum(E1, "B").?); | |
| 103 | try testing.expect(null == stringToEnum(E1, "C")); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | pub fn bitCount(comptime T: type) comptime_int { |
| ... | ... | @@ -113,8 +113,8 @@ pub fn bitCount(comptime T: type) comptime_int { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "std.meta.bitCount" { |
| 116 | testing.expect(bitCount(u8) == 8); | |
| 117 | testing.expect(bitCount(f32) == 32); | |
| 116 | try testing.expect(bitCount(u8) == 8); | |
| 117 | try testing.expect(bitCount(f32) == 32); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /// Returns the alignment of type T. |
| ... | ... | @@ -135,13 +135,13 @@ pub fn alignment(comptime T: type) comptime_int { |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | test "std.meta.alignment" { |
| 138 | testing.expect(alignment(u8) == 1); | |
| 139 | testing.expect(alignment(*align(1) u8) == 1); | |
| 140 | testing.expect(alignment(*align(2) u8) == 2); | |
| 141 | testing.expect(alignment([]align(1) u8) == 1); | |
| 142 | testing.expect(alignment([]align(2) u8) == 2); | |
| 143 | testing.expect(alignment(fn () void) > 0); | |
| 144 | testing.expect(alignment(fn () align(128) void) == 128); | |
| 138 | try testing.expect(alignment(u8) == 1); | |
| 139 | try testing.expect(alignment(*align(1) u8) == 1); | |
| 140 | try testing.expect(alignment(*align(2) u8) == 2); | |
| 141 | try testing.expect(alignment([]align(1) u8) == 1); | |
| 142 | try testing.expect(alignment([]align(2) u8) == 2); | |
| 143 | try testing.expect(alignment(fn () void) > 0); | |
| 144 | try testing.expect(alignment(fn () align(128) void) == 128); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | pub fn Child(comptime T: type) type { |
| ... | ... | @@ -155,11 +155,11 @@ pub fn Child(comptime T: type) type { |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | test "std.meta.Child" { |
| 158 | testing.expect(Child([1]u8) == u8); | |
| 159 | testing.expect(Child(*u8) == u8); | |
| 160 | testing.expect(Child([]u8) == u8); | |
| 161 | testing.expect(Child(?u8) == u8); | |
| 162 | testing.expect(Child(Vector(2, u8)) == u8); | |
| 158 | try testing.expect(Child([1]u8) == u8); | |
| 159 | try testing.expect(Child(*u8) == u8); | |
| 160 | try testing.expect(Child([]u8) == u8); | |
| 161 | try testing.expect(Child(?u8) == u8); | |
| 162 | try testing.expect(Child(Vector(2, u8)) == u8); | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /// Given a "memory span" type, returns the "element type". |
| ... | ... | @@ -188,13 +188,13 @@ pub fn Elem(comptime T: type) type { |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "std.meta.Elem" { |
| 191 | testing.expect(Elem([1]u8) == u8); | |
| 192 | testing.expect(Elem([*]u8) == u8); | |
| 193 | testing.expect(Elem([]u8) == u8); | |
| 194 | testing.expect(Elem(*[10]u8) == u8); | |
| 195 | testing.expect(Elem(Vector(2, u8)) == u8); | |
| 196 | testing.expect(Elem(*Vector(2, u8)) == u8); | |
| 197 | testing.expect(Elem(?[*]u8) == u8); | |
| 191 | try testing.expect(Elem([1]u8) == u8); | |
| 192 | try testing.expect(Elem([*]u8) == u8); | |
| 193 | try testing.expect(Elem([]u8) == u8); | |
| 194 | try testing.expect(Elem(*[10]u8) == u8); | |
| 195 | try testing.expect(Elem(Vector(2, u8)) == u8); | |
| 196 | try testing.expect(Elem(*Vector(2, u8)) == u8); | |
| 197 | try testing.expect(Elem(?[*]u8) == u8); | |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 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 | 219 | } |
| 220 | 220 | |
| 221 | 221 | test "std.meta.sentinel" { |
| 222 | testSentinel(); | |
| 223 | comptime testSentinel(); | |
| 222 | try testSentinel(); | |
| 223 | comptime try testSentinel(); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | fn testSentinel() void { | |
| 227 | testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?); | |
| 228 | testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?); | |
| 229 | testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?); | |
| 230 | testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?); | |
| 226 | fn testSentinel() !void { | |
| 227 | try testing.expectEqual(@as(u8, 0), sentinel([:0]u8).?); | |
| 228 | try testing.expectEqual(@as(u8, 0), sentinel([*:0]u8).?); | |
| 229 | try testing.expectEqual(@as(u8, 0), sentinel([5:0]u8).?); | |
| 230 | try testing.expectEqual(@as(u8, 0), sentinel(*const [5:0]u8).?); | |
| 231 | 231 | |
| 232 | testing.expect(sentinel([]u8) == null); | |
| 233 | testing.expect(sentinel([*]u8) == null); | |
| 234 | testing.expect(sentinel([5]u8) == null); | |
| 235 | testing.expect(sentinel(*const [5]u8) == null); | |
| 232 | try testing.expect(sentinel([]u8) == null); | |
| 233 | try testing.expect(sentinel([*]u8) == null); | |
| 234 | try testing.expect(sentinel([5]u8) == null); | |
| 235 | try testing.expect(sentinel(*const [5]u8) == null); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 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 | 322 | } |
| 323 | 323 | |
| 324 | 324 | test "std.meta.assumeSentinel" { |
| 325 | testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0))); | |
| 326 | testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0))); | |
| 327 | testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0))); | |
| 328 | testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0))); | |
| 329 | testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0))); | |
| 330 | testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0))); | |
| 331 | testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3))); | |
| 332 | testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null))); | |
| 333 | testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null))); | |
| 334 | testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0))); | |
| 335 | testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0))); | |
| 325 | try testing.expect([*:0]u8 == @TypeOf(assumeSentinel(@as([*]u8, undefined), 0))); | |
| 326 | try testing.expect([:0]u8 == @TypeOf(assumeSentinel(@as([]u8, undefined), 0))); | |
| 327 | try testing.expect([*:0]const u8 == @TypeOf(assumeSentinel(@as([*]const u8, undefined), 0))); | |
| 328 | try testing.expect([:0]const u8 == @TypeOf(assumeSentinel(@as([]const u8, undefined), 0))); | |
| 329 | try testing.expect([*:0]u16 == @TypeOf(assumeSentinel(@as([*]u16, undefined), 0))); | |
| 330 | try testing.expect([:0]const u16 == @TypeOf(assumeSentinel(@as([]const u16, undefined), 0))); | |
| 331 | try testing.expect([*:3]u8 == @TypeOf(assumeSentinel(@as([*:1]u8, undefined), 3))); | |
| 332 | try testing.expect([:null]?[*]u8 == @TypeOf(assumeSentinel(@as([]?[*]u8, undefined), null))); | |
| 333 | try testing.expect([*:null]?[*]u8 == @TypeOf(assumeSentinel(@as([*]?[*]u8, undefined), null))); | |
| 334 | try testing.expect(*[10:0]u8 == @TypeOf(assumeSentinel(@as(*[10]u8, undefined), 0))); | |
| 335 | try testing.expect(?[*:0]u8 == @TypeOf(assumeSentinel(@as(?[*]u8, undefined), 0))); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout { |
| ... | ... | @@ -367,15 +367,15 @@ test "std.meta.containerLayout" { |
| 367 | 367 | a: u8, |
| 368 | 368 | }; |
| 369 | 369 | |
| 370 | testing.expect(containerLayout(E1) == .Auto); | |
| 371 | testing.expect(containerLayout(E2) == .Packed); | |
| 372 | testing.expect(containerLayout(E3) == .Extern); | |
| 373 | testing.expect(containerLayout(S1) == .Auto); | |
| 374 | testing.expect(containerLayout(S2) == .Packed); | |
| 375 | testing.expect(containerLayout(S3) == .Extern); | |
| 376 | testing.expect(containerLayout(U1) == .Auto); | |
| 377 | testing.expect(containerLayout(U2) == .Packed); | |
| 378 | testing.expect(containerLayout(U3) == .Extern); | |
| 370 | try testing.expect(containerLayout(E1) == .Auto); | |
| 371 | try testing.expect(containerLayout(E2) == .Packed); | |
| 372 | try testing.expect(containerLayout(E3) == .Extern); | |
| 373 | try testing.expect(containerLayout(S1) == .Auto); | |
| 374 | try testing.expect(containerLayout(S2) == .Packed); | |
| 375 | try testing.expect(containerLayout(S3) == .Extern); | |
| 376 | try testing.expect(containerLayout(U1) == .Auto); | |
| 377 | try testing.expect(containerLayout(U2) == .Packed); | |
| 378 | try testing.expect(containerLayout(U3) == .Extern); | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | pub fn declarations(comptime T: type) []const TypeInfo.Declaration { |
| ... | ... | @@ -414,8 +414,8 @@ test "std.meta.declarations" { |
| 414 | 414 | }; |
| 415 | 415 | |
| 416 | 416 | inline for (decls) |decl| { |
| 417 | testing.expect(decl.len == 1); | |
| 418 | testing.expect(comptime mem.eql(u8, decl[0].name, "a")); | |
| 417 | try testing.expect(decl.len == 1); | |
| 418 | try testing.expect(comptime mem.eql(u8, decl[0].name, "a")); | |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | |
| ... | ... | @@ -450,8 +450,8 @@ test "std.meta.declarationInfo" { |
| 450 | 450 | }; |
| 451 | 451 | |
| 452 | 452 | inline for (infos) |info| { |
| 453 | testing.expect(comptime mem.eql(u8, info.name, "a")); | |
| 454 | testing.expect(!info.is_pub); | |
| 453 | try testing.expect(comptime mem.eql(u8, info.name, "a")); | |
| 454 | try testing.expect(!info.is_pub); | |
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | |
| ... | ... | @@ -488,16 +488,16 @@ test "std.meta.fields" { |
| 488 | 488 | const sf = comptime fields(S1); |
| 489 | 489 | const uf = comptime fields(U1); |
| 490 | 490 | |
| 491 | testing.expect(e1f.len == 1); | |
| 492 | testing.expect(e2f.len == 1); | |
| 493 | testing.expect(sf.len == 1); | |
| 494 | testing.expect(uf.len == 1); | |
| 495 | testing.expect(mem.eql(u8, e1f[0].name, "A")); | |
| 496 | testing.expect(mem.eql(u8, e2f[0].name, "A")); | |
| 497 | testing.expect(mem.eql(u8, sf[0].name, "a")); | |
| 498 | testing.expect(mem.eql(u8, uf[0].name, "a")); | |
| 499 | testing.expect(comptime sf[0].field_type == u8); | |
| 500 | testing.expect(comptime uf[0].field_type == u8); | |
| 491 | try testing.expect(e1f.len == 1); | |
| 492 | try testing.expect(e2f.len == 1); | |
| 493 | try testing.expect(sf.len == 1); | |
| 494 | try testing.expect(uf.len == 1); | |
| 495 | try testing.expect(mem.eql(u8, e1f[0].name, "A")); | |
| 496 | try testing.expect(mem.eql(u8, e2f[0].name, "A")); | |
| 497 | try testing.expect(mem.eql(u8, sf[0].name, "a")); | |
| 498 | try testing.expect(mem.eql(u8, uf[0].name, "a")); | |
| 499 | try testing.expect(comptime sf[0].field_type == u8); | |
| 500 | try testing.expect(comptime uf[0].field_type == u8); | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) { |
| ... | ... | @@ -527,12 +527,12 @@ test "std.meta.fieldInfo" { |
| 527 | 527 | const sf = fieldInfo(S1, .a); |
| 528 | 528 | const uf = fieldInfo(U1, .a); |
| 529 | 529 | |
| 530 | testing.expect(mem.eql(u8, e1f.name, "A")); | |
| 531 | testing.expect(mem.eql(u8, e2f.name, "A")); | |
| 532 | testing.expect(mem.eql(u8, sf.name, "a")); | |
| 533 | testing.expect(mem.eql(u8, uf.name, "a")); | |
| 534 | testing.expect(comptime sf.field_type == u8); | |
| 535 | testing.expect(comptime uf.field_type == u8); | |
| 530 | try testing.expect(mem.eql(u8, e1f.name, "A")); | |
| 531 | try testing.expect(mem.eql(u8, e2f.name, "A")); | |
| 532 | try testing.expect(mem.eql(u8, sf.name, "a")); | |
| 533 | try testing.expect(mem.eql(u8, uf.name, "a")); | |
| 534 | try testing.expect(comptime sf.field_type == u8); | |
| 535 | try testing.expect(comptime uf.field_type == u8); | |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 { |
| ... | ... | @@ -562,16 +562,16 @@ test "std.meta.fieldNames" { |
| 562 | 562 | const s1names = fieldNames(S1); |
| 563 | 563 | const u1names = fieldNames(U1); |
| 564 | 564 | |
| 565 | testing.expect(e1names.len == 2); | |
| 566 | testing.expectEqualSlices(u8, e1names[0], "A"); | |
| 567 | testing.expectEqualSlices(u8, e1names[1], "B"); | |
| 568 | testing.expect(e2names.len == 1); | |
| 569 | testing.expectEqualSlices(u8, e2names[0], "A"); | |
| 570 | testing.expect(s1names.len == 1); | |
| 571 | testing.expectEqualSlices(u8, s1names[0], "a"); | |
| 572 | testing.expect(u1names.len == 2); | |
| 573 | testing.expectEqualSlices(u8, u1names[0], "a"); | |
| 574 | testing.expectEqualSlices(u8, u1names[1], "b"); | |
| 565 | try testing.expect(e1names.len == 2); | |
| 566 | try testing.expectEqualSlices(u8, e1names[0], "A"); | |
| 567 | try testing.expectEqualSlices(u8, e1names[1], "B"); | |
| 568 | try testing.expect(e2names.len == 1); | |
| 569 | try testing.expectEqualSlices(u8, e2names[0], "A"); | |
| 570 | try testing.expect(s1names.len == 1); | |
| 571 | try testing.expectEqualSlices(u8, s1names[0], "a"); | |
| 572 | try testing.expect(u1names.len == 2); | |
| 573 | try testing.expectEqualSlices(u8, u1names[0], "a"); | |
| 574 | try testing.expectEqualSlices(u8, u1names[1], "b"); | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | pub fn FieldEnum(comptime T: type) type { |
| ... | ... | @@ -595,20 +595,20 @@ pub fn FieldEnum(comptime T: type) type { |
| 595 | 595 | }); |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) void { | |
| 598 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | |
| 599 | 599 | // TODO: https://github.com/ziglang/zig/issues/7419 |
| 600 | 600 | // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum); |
| 601 | testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout); | |
| 602 | testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type); | |
| 603 | comptime testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields); | |
| 604 | comptime testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls); | |
| 605 | testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive); | |
| 601 | try testing.expectEqual(@typeInfo(expected).Enum.layout, @typeInfo(actual).Enum.layout); | |
| 602 | try testing.expectEqual(@typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type); | |
| 603 | comptime try testing.expectEqualSlices(std.builtin.TypeInfo.EnumField, @typeInfo(expected).Enum.fields, @typeInfo(actual).Enum.fields); | |
| 604 | comptime try testing.expectEqualSlices(std.builtin.TypeInfo.Declaration, @typeInfo(expected).Enum.decls, @typeInfo(actual).Enum.decls); | |
| 605 | try testing.expectEqual(@typeInfo(expected).Enum.is_exhaustive, @typeInfo(actual).Enum.is_exhaustive); | |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | test "std.meta.FieldEnum" { |
| 609 | expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 })); | |
| 610 | expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 })); | |
| 611 | expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); | |
| 609 | try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 })); | |
| 610 | try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 })); | |
| 611 | try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); | |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | // Deprecated: use Tag |
| ... | ... | @@ -632,8 +632,8 @@ test "std.meta.Tag" { |
| 632 | 632 | D: u16, |
| 633 | 633 | }; |
| 634 | 634 | |
| 635 | testing.expect(Tag(E) == u8); | |
| 636 | testing.expect(Tag(U) == E); | |
| 635 | try testing.expect(Tag(E) == u8); | |
| 636 | try testing.expect(Tag(U) == E); | |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | ///Returns the active tag of a tagged union |
| ... | ... | @@ -654,10 +654,10 @@ test "std.meta.activeTag" { |
| 654 | 654 | }; |
| 655 | 655 | |
| 656 | 656 | var u = U{ .Int = 32 }; |
| 657 | testing.expect(activeTag(u) == UE.Int); | |
| 657 | try testing.expect(activeTag(u) == UE.Int); | |
| 658 | 658 | |
| 659 | 659 | u = U{ .Float = 112.9876 }; |
| 660 | testing.expect(activeTag(u) == UE.Float); | |
| 660 | try testing.expect(activeTag(u) == UE.Float); | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | const TagPayloadType = TagPayload; |
| ... | ... | @@ -665,7 +665,7 @@ const TagPayloadType = TagPayload; |
| 665 | 665 | ///Given a tagged union type, and an enum, return the type of the union |
| 666 | 666 | /// field corresponding to the enum tag. |
| 667 | 667 | pub fn TagPayload(comptime U: type, tag: Tag(U)) type { |
| 668 | testing.expect(trait.is(.Union)(U)); | |
| 668 | try testing.expect(trait.is(.Union)(U)); | |
| 669 | 669 | |
| 670 | 670 | const info = @typeInfo(U).Union; |
| 671 | 671 | const tag_info = @typeInfo(Tag(U)).Enum; |
| ... | ... | @@ -687,7 +687,7 @@ test "std.meta.TagPayload" { |
| 687 | 687 | }; |
| 688 | 688 | const MovedEvent = TagPayload(Event, Event.Moved); |
| 689 | 689 | var e: Event = undefined; |
| 690 | testing.expect(MovedEvent == @TypeOf(e.Moved)); | |
| 690 | try testing.expect(MovedEvent == @TypeOf(e.Moved)); | |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /// Compares two of any type for equality. Containers are compared on a field-by-field basis, |
| ... | ... | @@ -787,19 +787,19 @@ test "std.meta.eql" { |
| 787 | 787 | const u_2 = U{ .s = s_1 }; |
| 788 | 788 | const u_3 = U{ .f = 24 }; |
| 789 | 789 | |
| 790 | testing.expect(eql(s_1, s_3)); | |
| 791 | testing.expect(eql(&s_1, &s_1)); | |
| 792 | testing.expect(!eql(&s_1, &s_3)); | |
| 793 | testing.expect(eql(u_1, u_3)); | |
| 794 | testing.expect(!eql(u_1, u_2)); | |
| 790 | try testing.expect(eql(s_1, s_3)); | |
| 791 | try testing.expect(eql(&s_1, &s_1)); | |
| 792 | try testing.expect(!eql(&s_1, &s_3)); | |
| 793 | try testing.expect(eql(u_1, u_3)); | |
| 794 | try testing.expect(!eql(u_1, u_2)); | |
| 795 | 795 | |
| 796 | 796 | var a1 = "abcdef".*; |
| 797 | 797 | var a2 = "abcdef".*; |
| 798 | 798 | var a3 = "ghijkl".*; |
| 799 | 799 | |
| 800 | testing.expect(eql(a1, a2)); | |
| 801 | testing.expect(!eql(a1, a3)); | |
| 802 | testing.expect(!eql(a1[0..], a2[0..])); | |
| 800 | try testing.expect(eql(a1, a2)); | |
| 801 | try testing.expect(!eql(a1, a3)); | |
| 802 | try testing.expect(!eql(a1[0..], a2[0..])); | |
| 803 | 803 | |
| 804 | 804 | const EU = struct { |
| 805 | 805 | fn tst(err: bool) !u8 { |
| ... | ... | @@ -808,16 +808,16 @@ test "std.meta.eql" { |
| 808 | 808 | } |
| 809 | 809 | }; |
| 810 | 810 | |
| 811 | testing.expect(eql(EU.tst(true), EU.tst(true))); | |
| 812 | testing.expect(eql(EU.tst(false), EU.tst(false))); | |
| 813 | testing.expect(!eql(EU.tst(false), EU.tst(true))); | |
| 811 | try testing.expect(eql(EU.tst(true), EU.tst(true))); | |
| 812 | try testing.expect(eql(EU.tst(false), EU.tst(false))); | |
| 813 | try testing.expect(!eql(EU.tst(false), EU.tst(true))); | |
| 814 | 814 | |
| 815 | 815 | var v1 = @splat(4, @as(u32, 1)); |
| 816 | 816 | var v2 = @splat(4, @as(u32, 1)); |
| 817 | 817 | var v3 = @splat(4, @as(u32, 2)); |
| 818 | 818 | |
| 819 | testing.expect(eql(v1, v2)); | |
| 820 | testing.expect(!eql(v1, v3)); | |
| 819 | try testing.expect(eql(v1, v2)); | |
| 820 | try testing.expect(!eql(v1, v3)); | |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | test "intToEnum with error return" { |
| ... | ... | @@ -831,9 +831,9 @@ test "intToEnum with error return" { |
| 831 | 831 | |
| 832 | 832 | var zero: u8 = 0; |
| 833 | 833 | var one: u16 = 1; |
| 834 | testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); | |
| 835 | testing.expect(intToEnum(E2, one) catch unreachable == E2.B); | |
| 836 | testing.expectError(error.InvalidEnumTag, intToEnum(E1, one)); | |
| 834 | try testing.expect(intToEnum(E1, zero) catch unreachable == E1.A); | |
| 835 | try testing.expect(intToEnum(E2, one) catch unreachable == E2.B); | |
| 836 | try testing.expectError(error.InvalidEnumTag, intToEnum(E1, one)); | |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | pub const IntToEnumError = error{InvalidEnumTag}; |
| ... | ... | @@ -1008,27 +1008,27 @@ test "std.meta.cast" { |
| 1008 | 1008 | |
| 1009 | 1009 | var i = @as(i64, 10); |
| 1010 | 1010 | |
| 1011 | testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16)); | |
| 1012 | testing.expect(cast(*u64, &i).* == @as(u64, 10)); | |
| 1013 | testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i); | |
| 1011 | try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16)); | |
| 1012 | try testing.expect(cast(*u64, &i).* == @as(u64, 10)); | |
| 1013 | try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i); | |
| 1014 | 1014 | |
| 1015 | testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2)); | |
| 1016 | testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i); | |
| 1017 | testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i); | |
| 1015 | try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2)); | |
| 1016 | try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i); | |
| 1017 | try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i); | |
| 1018 | 1018 | |
| 1019 | testing.expect(cast(E, 1) == .One); | |
| 1019 | try testing.expect(cast(E, 1) == .One); | |
| 1020 | 1020 | |
| 1021 | testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4))); | |
| 1022 | testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4))); | |
| 1023 | testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10))); | |
| 1024 | testing.expectEqual(@as(u8, 2), cast(u8, E.Two)); | |
| 1021 | try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4))); | |
| 1022 | try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4))); | |
| 1023 | try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10))); | |
| 1024 | try testing.expectEqual(@as(u8, 2), cast(u8, E.Two)); | |
| 1025 | 1025 | |
| 1026 | testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000))); | |
| 1026 | try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000))); | |
| 1027 | 1027 | |
| 1028 | testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2))); | |
| 1029 | testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2))); | |
| 1028 | try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2))); | |
| 1029 | try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2))); | |
| 1030 | 1030 | |
| 1031 | testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2))); | |
| 1031 | try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2))); | |
| 1032 | 1032 | |
| 1033 | 1033 | const C_ENUM = extern enum(c_int) { |
| 1034 | 1034 | A = 0, |
| ... | ... | @@ -1036,10 +1036,10 @@ test "std.meta.cast" { |
| 1036 | 1036 | C, |
| 1037 | 1037 | _, |
| 1038 | 1038 | }; |
| 1039 | testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1)); | |
| 1040 | testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B); | |
| 1041 | testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B); | |
| 1042 | testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42)); | |
| 1039 | try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1)); | |
| 1040 | try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B); | |
| 1041 | try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B); | |
| 1042 | try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42)); | |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | /// Given a value returns its size as C's sizeof operator would. |
| ... | ... | @@ -1118,43 +1118,43 @@ test "sizeof" { |
| 1118 | 1118 | |
| 1119 | 1119 | const ptr_size = @sizeOf(*c_void); |
| 1120 | 1120 | |
| 1121 | testing.expect(sizeof(u32) == 4); | |
| 1122 | testing.expect(sizeof(@as(u32, 2)) == 4); | |
| 1123 | testing.expect(sizeof(2) == @sizeOf(c_int)); | |
| 1121 | try testing.expect(sizeof(u32) == 4); | |
| 1122 | try testing.expect(sizeof(@as(u32, 2)) == 4); | |
| 1123 | try testing.expect(sizeof(2) == @sizeOf(c_int)); | |
| 1124 | 1124 | |
| 1125 | testing.expect(sizeof(2.0) == @sizeOf(f64)); | |
| 1125 | try testing.expect(sizeof(2.0) == @sizeOf(f64)); | |
| 1126 | 1126 | |
| 1127 | testing.expect(sizeof(E) == @sizeOf(c_int)); | |
| 1128 | testing.expect(sizeof(E.One) == @sizeOf(c_int)); | |
| 1127 | try testing.expect(sizeof(E) == @sizeOf(c_int)); | |
| 1128 | try testing.expect(sizeof(E.One) == @sizeOf(c_int)); | |
| 1129 | 1129 | |
| 1130 | testing.expect(sizeof(S) == 4); | |
| 1130 | try testing.expect(sizeof(S) == 4); | |
| 1131 | 1131 | |
| 1132 | testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12); | |
| 1133 | testing.expect(sizeof([3]u32) == 12); | |
| 1134 | testing.expect(sizeof([3:0]u32) == 16); | |
| 1135 | testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size); | |
| 1132 | try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12); | |
| 1133 | try testing.expect(sizeof([3]u32) == 12); | |
| 1134 | try testing.expect(sizeof([3:0]u32) == 16); | |
| 1135 | try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size); | |
| 1136 | 1136 | |
| 1137 | testing.expect(sizeof(*u32) == ptr_size); | |
| 1138 | testing.expect(sizeof([*]u32) == ptr_size); | |
| 1139 | testing.expect(sizeof([*c]u32) == ptr_size); | |
| 1140 | testing.expect(sizeof(?*u32) == ptr_size); | |
| 1141 | testing.expect(sizeof(?[*]u32) == ptr_size); | |
| 1142 | testing.expect(sizeof(*c_void) == ptr_size); | |
| 1143 | testing.expect(sizeof(*void) == ptr_size); | |
| 1144 | testing.expect(sizeof(null) == ptr_size); | |
| 1137 | try testing.expect(sizeof(*u32) == ptr_size); | |
| 1138 | try testing.expect(sizeof([*]u32) == ptr_size); | |
| 1139 | try testing.expect(sizeof([*c]u32) == ptr_size); | |
| 1140 | try testing.expect(sizeof(?*u32) == ptr_size); | |
| 1141 | try testing.expect(sizeof(?[*]u32) == ptr_size); | |
| 1142 | try testing.expect(sizeof(*c_void) == ptr_size); | |
| 1143 | try testing.expect(sizeof(*void) == ptr_size); | |
| 1144 | try testing.expect(sizeof(null) == ptr_size); | |
| 1145 | 1145 | |
| 1146 | testing.expect(sizeof("foobar") == 7); | |
| 1147 | testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14); | |
| 1148 | testing.expect(sizeof(*const [4:0]u8) == 5); | |
| 1149 | testing.expect(sizeof(*[4:0]u8) == ptr_size); | |
| 1150 | testing.expect(sizeof([*]const [4:0]u8) == ptr_size); | |
| 1151 | testing.expect(sizeof(*const *const [4:0]u8) == ptr_size); | |
| 1152 | testing.expect(sizeof(*const [4]u8) == ptr_size); | |
| 1146 | try testing.expect(sizeof("foobar") == 7); | |
| 1147 | try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14); | |
| 1148 | try testing.expect(sizeof(*const [4:0]u8) == 5); | |
| 1149 | try testing.expect(sizeof(*[4:0]u8) == ptr_size); | |
| 1150 | try testing.expect(sizeof([*]const [4:0]u8) == ptr_size); | |
| 1151 | try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size); | |
| 1152 | try testing.expect(sizeof(*const [4]u8) == ptr_size); | |
| 1153 | 1153 | |
| 1154 | testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof))); | |
| 1154 | try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof))); | |
| 1155 | 1155 | |
| 1156 | testing.expect(sizeof(void) == 1); | |
| 1157 | testing.expect(sizeof(c_void) == 1); | |
| 1156 | try testing.expect(sizeof(void) == 1); | |
| 1157 | try testing.expect(sizeof(c_void) == 1); | |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal }; |
| ... | ... | @@ -1193,7 +1193,7 @@ pub fn promoteIntLiteral( |
| 1193 | 1193 | |
| 1194 | 1194 | test "promoteIntLiteral" { |
| 1195 | 1195 | const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal); |
| 1196 | testing.expectEqual(c_uint, @TypeOf(signed_hex)); | |
| 1196 | try testing.expectEqual(c_uint, @TypeOf(signed_hex)); | |
| 1197 | 1197 | |
| 1198 | 1198 | if (math.maxInt(c_longlong) == math.maxInt(c_int)) return; |
| 1199 | 1199 | |
| ... | ... | @@ -1201,11 +1201,11 @@ test "promoteIntLiteral" { |
| 1201 | 1201 | const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal); |
| 1202 | 1202 | |
| 1203 | 1203 | if (math.maxInt(c_long) > math.maxInt(c_int)) { |
| 1204 | testing.expectEqual(c_long, @TypeOf(signed_decimal)); | |
| 1205 | testing.expectEqual(c_ulong, @TypeOf(unsigned)); | |
| 1204 | try testing.expectEqual(c_long, @TypeOf(signed_decimal)); | |
| 1205 | try testing.expectEqual(c_ulong, @TypeOf(unsigned)); | |
| 1206 | 1206 | } else { |
| 1207 | testing.expectEqual(c_longlong, @TypeOf(signed_decimal)); | |
| 1208 | testing.expectEqual(c_ulonglong, @TypeOf(unsigned)); | |
| 1207 | try testing.expectEqual(c_longlong, @TypeOf(signed_decimal)); | |
| 1208 | try testing.expectEqual(c_ulonglong, @TypeOf(unsigned)); | |
| 1209 | 1209 | } |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| ... | ... | @@ -1347,17 +1347,17 @@ pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len |
| 1347 | 1347 | test "shuffleVectorIndex" { |
| 1348 | 1348 | const vector_len: usize = 4; |
| 1349 | 1349 | |
| 1350 | testing.expect(shuffleVectorIndex(-1, vector_len) == 0); | |
| 1350 | try testing.expect(shuffleVectorIndex(-1, vector_len) == 0); | |
| 1351 | 1351 | |
| 1352 | testing.expect(shuffleVectorIndex(0, vector_len) == 0); | |
| 1353 | testing.expect(shuffleVectorIndex(1, vector_len) == 1); | |
| 1354 | testing.expect(shuffleVectorIndex(2, vector_len) == 2); | |
| 1355 | testing.expect(shuffleVectorIndex(3, vector_len) == 3); | |
| 1352 | try testing.expect(shuffleVectorIndex(0, vector_len) == 0); | |
| 1353 | try testing.expect(shuffleVectorIndex(1, vector_len) == 1); | |
| 1354 | try testing.expect(shuffleVectorIndex(2, vector_len) == 2); | |
| 1355 | try testing.expect(shuffleVectorIndex(3, vector_len) == 3); | |
| 1356 | 1356 | |
| 1357 | testing.expect(shuffleVectorIndex(4, vector_len) == -1); | |
| 1358 | testing.expect(shuffleVectorIndex(5, vector_len) == -2); | |
| 1359 | testing.expect(shuffleVectorIndex(6, vector_len) == -3); | |
| 1360 | testing.expect(shuffleVectorIndex(7, vector_len) == -4); | |
| 1357 | try testing.expect(shuffleVectorIndex(4, vector_len) == -1); | |
| 1358 | try testing.expect(shuffleVectorIndex(5, vector_len) == -2); | |
| 1359 | try testing.expect(shuffleVectorIndex(6, vector_len) == -3); | |
| 1360 | try testing.expect(shuffleVectorIndex(7, vector_len) == -4); | |
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | /// Returns whether `error_union` contains an error. |
| ... | ... | @@ -1366,6 +1366,6 @@ pub fn isError(error_union: anytype) bool { |
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | test "isError" { |
| 1369 | std.testing.expect(isError(math.absInt(@as(i8, -128)))); | |
| 1370 | std.testing.expect(!isError(math.absInt(@as(i8, -127)))); | |
| 1369 | try std.testing.expect(isError(math.absInt(@as(i8, -128)))); | |
| 1370 | try std.testing.expect(!isError(math.absInt(@as(i8, -127)))); | |
| 1371 | 1371 | } |
lib/std/meta/trailer_flags.zig+7-7| ... | ... | @@ -146,7 +146,7 @@ test "TrailerFlags" { |
| 146 | 146 | b: bool, |
| 147 | 147 | c: u64, |
| 148 | 148 | }); |
| 149 | testing.expectEqual(u2, meta.Tag(Flags.FieldEnum)); | |
| 149 | try testing.expectEqual(u2, meta.Tag(Flags.FieldEnum)); | |
| 150 | 150 | |
| 151 | 151 | var flags = Flags.init(.{ |
| 152 | 152 | .b = true, |
| ... | ... | @@ -158,16 +158,16 @@ test "TrailerFlags" { |
| 158 | 158 | flags.set(slice.ptr, .b, false); |
| 159 | 159 | flags.set(slice.ptr, .c, 12345678); |
| 160 | 160 | |
| 161 | testing.expect(flags.get(slice.ptr, .a) == null); | |
| 162 | testing.expect(!flags.get(slice.ptr, .b).?); | |
| 163 | testing.expect(flags.get(slice.ptr, .c).? == 12345678); | |
| 161 | try testing.expect(flags.get(slice.ptr, .a) == null); | |
| 162 | try testing.expect(!flags.get(slice.ptr, .b).?); | |
| 163 | try testing.expect(flags.get(slice.ptr, .c).? == 12345678); | |
| 164 | 164 | |
| 165 | 165 | flags.setMany(slice.ptr, .{ |
| 166 | 166 | .b = true, |
| 167 | 167 | .c = 5678, |
| 168 | 168 | }); |
| 169 | 169 | |
| 170 | testing.expect(flags.get(slice.ptr, .a) == null); | |
| 171 | testing.expect(flags.get(slice.ptr, .b).?); | |
| 172 | testing.expect(flags.get(slice.ptr, .c).? == 5678); | |
| 170 | try testing.expect(flags.get(slice.ptr, .a) == null); | |
| 171 | try testing.expect(flags.get(slice.ptr, .b).?); | |
| 172 | try testing.expect(flags.get(slice.ptr, .c).? == 5678); | |
| 173 | 173 | } |
lib/std/meta/trait.zig+142-142| ... | ... | @@ -45,8 +45,8 @@ test "std.meta.trait.multiTrait" { |
| 45 | 45 | hasField("x"), |
| 46 | 46 | hasField("y"), |
| 47 | 47 | }); |
| 48 | testing.expect(isVector(Vector2)); | |
| 49 | testing.expect(!isVector(u8)); | |
| 48 | try testing.expect(isVector(Vector2)); | |
| 49 | try testing.expect(!isVector(u8)); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | pub fn hasFn(comptime name: []const u8) TraitFn { |
| ... | ... | @@ -66,9 +66,9 @@ test "std.meta.trait.hasFn" { |
| 66 | 66 | pub fn useless() void {} |
| 67 | 67 | }; |
| 68 | 68 | |
| 69 | testing.expect(hasFn("useless")(TestStruct)); | |
| 70 | testing.expect(!hasFn("append")(TestStruct)); | |
| 71 | testing.expect(!hasFn("useless")(u8)); | |
| 69 | try testing.expect(hasFn("useless")(TestStruct)); | |
| 70 | try testing.expect(!hasFn("append")(TestStruct)); | |
| 71 | try testing.expect(!hasFn("useless")(u8)); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | pub fn hasField(comptime name: []const u8) TraitFn { |
| ... | ... | @@ -96,11 +96,11 @@ test "std.meta.trait.hasField" { |
| 96 | 96 | value: u32, |
| 97 | 97 | }; |
| 98 | 98 | |
| 99 | testing.expect(hasField("value")(TestStruct)); | |
| 100 | testing.expect(!hasField("value")(*TestStruct)); | |
| 101 | testing.expect(!hasField("x")(TestStruct)); | |
| 102 | testing.expect(!hasField("x")(**TestStruct)); | |
| 103 | testing.expect(!hasField("value")(u8)); | |
| 99 | try testing.expect(hasField("value")(TestStruct)); | |
| 100 | try testing.expect(!hasField("value")(*TestStruct)); | |
| 101 | try testing.expect(!hasField("x")(TestStruct)); | |
| 102 | try testing.expect(!hasField("x")(**TestStruct)); | |
| 103 | try testing.expect(!hasField("value")(u8)); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | pub fn is(comptime id: builtin.TypeId) TraitFn { |
| ... | ... | @@ -113,11 +113,11 @@ pub fn is(comptime id: builtin.TypeId) TraitFn { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "std.meta.trait.is" { |
| 116 | testing.expect(is(.Int)(u8)); | |
| 117 | testing.expect(!is(.Int)(f32)); | |
| 118 | testing.expect(is(.Pointer)(*u8)); | |
| 119 | testing.expect(is(.Void)(void)); | |
| 120 | testing.expect(!is(.Optional)(anyerror)); | |
| 116 | try testing.expect(is(.Int)(u8)); | |
| 117 | try testing.expect(!is(.Int)(f32)); | |
| 118 | try testing.expect(is(.Pointer)(*u8)); | |
| 119 | try testing.expect(is(.Void)(void)); | |
| 120 | try testing.expect(!is(.Optional)(anyerror)); | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn { |
| ... | ... | @@ -131,9 +131,9 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn { |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "std.meta.trait.isPtrTo" { |
| 134 | testing.expect(!isPtrTo(.Struct)(struct {})); | |
| 135 | testing.expect(isPtrTo(.Struct)(*struct {})); | |
| 136 | testing.expect(!isPtrTo(.Struct)(**struct {})); | |
| 134 | try testing.expect(!isPtrTo(.Struct)(struct {})); | |
| 135 | try testing.expect(isPtrTo(.Struct)(*struct {})); | |
| 136 | try testing.expect(!isPtrTo(.Struct)(**struct {})); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn { |
| ... | ... | @@ -147,9 +147,9 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn { |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | test "std.meta.trait.isSliceOf" { |
| 150 | testing.expect(!isSliceOf(.Struct)(struct {})); | |
| 151 | testing.expect(isSliceOf(.Struct)([]struct {})); | |
| 152 | testing.expect(!isSliceOf(.Struct)([][]struct {})); | |
| 150 | try testing.expect(!isSliceOf(.Struct)(struct {})); | |
| 151 | try testing.expect(isSliceOf(.Struct)([]struct {})); | |
| 152 | try testing.expect(!isSliceOf(.Struct)([][]struct {})); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | ///////////Strait trait Fns |
| ... | ... | @@ -170,9 +170,9 @@ test "std.meta.trait.isExtern" { |
| 170 | 170 | const TestExStruct = extern struct {}; |
| 171 | 171 | const TestStruct = struct {}; |
| 172 | 172 | |
| 173 | testing.expect(isExtern(TestExStruct)); | |
| 174 | testing.expect(!isExtern(TestStruct)); | |
| 175 | testing.expect(!isExtern(u8)); | |
| 173 | try testing.expect(isExtern(TestExStruct)); | |
| 174 | try testing.expect(!isExtern(TestStruct)); | |
| 175 | try testing.expect(!isExtern(u8)); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | pub fn isPacked(comptime T: type) bool { |
| ... | ... | @@ -188,9 +188,9 @@ test "std.meta.trait.isPacked" { |
| 188 | 188 | const TestPStruct = packed struct {}; |
| 189 | 189 | const TestStruct = struct {}; |
| 190 | 190 | |
| 191 | testing.expect(isPacked(TestPStruct)); | |
| 192 | testing.expect(!isPacked(TestStruct)); | |
| 193 | testing.expect(!isPacked(u8)); | |
| 191 | try testing.expect(isPacked(TestPStruct)); | |
| 192 | try testing.expect(!isPacked(TestStruct)); | |
| 193 | try testing.expect(!isPacked(u8)); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | pub fn isUnsignedInt(comptime T: type) bool { |
| ... | ... | @@ -201,10 +201,10 @@ pub fn isUnsignedInt(comptime T: type) bool { |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | test "isUnsignedInt" { |
| 204 | testing.expect(isUnsignedInt(u32) == true); | |
| 205 | testing.expect(isUnsignedInt(comptime_int) == false); | |
| 206 | testing.expect(isUnsignedInt(i64) == false); | |
| 207 | testing.expect(isUnsignedInt(f64) == false); | |
| 204 | try testing.expect(isUnsignedInt(u32) == true); | |
| 205 | try testing.expect(isUnsignedInt(comptime_int) == false); | |
| 206 | try testing.expect(isUnsignedInt(i64) == false); | |
| 207 | try testing.expect(isUnsignedInt(f64) == false); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | pub fn isSignedInt(comptime T: type) bool { |
| ... | ... | @@ -216,10 +216,10 @@ pub fn isSignedInt(comptime T: type) bool { |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | test "isSignedInt" { |
| 219 | testing.expect(isSignedInt(u32) == false); | |
| 220 | testing.expect(isSignedInt(comptime_int) == true); | |
| 221 | testing.expect(isSignedInt(i64) == true); | |
| 222 | testing.expect(isSignedInt(f64) == false); | |
| 219 | try testing.expect(isSignedInt(u32) == false); | |
| 220 | try testing.expect(isSignedInt(comptime_int) == true); | |
| 221 | try testing.expect(isSignedInt(i64) == true); | |
| 222 | try testing.expect(isSignedInt(f64) == false); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | pub fn isSingleItemPtr(comptime T: type) bool { |
| ... | ... | @@ -231,10 +231,10 @@ pub fn isSingleItemPtr(comptime T: type) bool { |
| 231 | 231 | |
| 232 | 232 | test "std.meta.trait.isSingleItemPtr" { |
| 233 | 233 | const array = [_]u8{0} ** 10; |
| 234 | comptime testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); | |
| 235 | comptime testing.expect(!isSingleItemPtr(@TypeOf(array))); | |
| 234 | comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); | |
| 235 | comptime try testing.expect(!isSingleItemPtr(@TypeOf(array))); | |
| 236 | 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 | } |
| 239 | 239 | |
| 240 | 240 | pub fn isManyItemPtr(comptime T: type) bool { |
| ... | ... | @@ -247,9 +247,9 @@ pub fn isManyItemPtr(comptime T: type) bool { |
| 247 | 247 | test "std.meta.trait.isManyItemPtr" { |
| 248 | 248 | const array = [_]u8{0} ** 10; |
| 249 | 249 | const mip = @ptrCast([*]const u8, &array[0]); |
| 250 | testing.expect(isManyItemPtr(@TypeOf(mip))); | |
| 251 | testing.expect(!isManyItemPtr(@TypeOf(array))); | |
| 252 | testing.expect(!isManyItemPtr(@TypeOf(array[0..1]))); | |
| 250 | try testing.expect(isManyItemPtr(@TypeOf(mip))); | |
| 251 | try testing.expect(!isManyItemPtr(@TypeOf(array))); | |
| 252 | try testing.expect(!isManyItemPtr(@TypeOf(array[0..1]))); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | pub fn isSlice(comptime T: type) bool { |
| ... | ... | @@ -262,9 +262,9 @@ pub fn isSlice(comptime T: type) bool { |
| 262 | 262 | test "std.meta.trait.isSlice" { |
| 263 | 263 | const array = [_]u8{0} ** 10; |
| 264 | 264 | var runtime_zero: usize = 0; |
| 265 | testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); | |
| 266 | testing.expect(!isSlice(@TypeOf(array))); | |
| 267 | testing.expect(!isSlice(@TypeOf(&array[0]))); | |
| 265 | try testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); | |
| 266 | try testing.expect(!isSlice(@TypeOf(array))); | |
| 267 | try testing.expect(!isSlice(@TypeOf(&array[0]))); | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | pub fn isIndexable(comptime T: type) bool { |
| ... | ... | @@ -283,12 +283,12 @@ test "std.meta.trait.isIndexable" { |
| 283 | 283 | const vector: meta.Vector(2, u32) = [_]u32{0} ** 2; |
| 284 | 284 | const tuple = .{ 1, 2, 3 }; |
| 285 | 285 | |
| 286 | testing.expect(isIndexable(@TypeOf(array))); | |
| 287 | testing.expect(isIndexable(@TypeOf(&array))); | |
| 288 | testing.expect(isIndexable(@TypeOf(slice))); | |
| 289 | testing.expect(!isIndexable(meta.Child(@TypeOf(slice)))); | |
| 290 | testing.expect(isIndexable(@TypeOf(vector))); | |
| 291 | testing.expect(isIndexable(@TypeOf(tuple))); | |
| 286 | try testing.expect(isIndexable(@TypeOf(array))); | |
| 287 | try testing.expect(isIndexable(@TypeOf(&array))); | |
| 288 | try testing.expect(isIndexable(@TypeOf(slice))); | |
| 289 | try testing.expect(!isIndexable(meta.Child(@TypeOf(slice)))); | |
| 290 | try testing.expect(isIndexable(@TypeOf(vector))); | |
| 291 | try testing.expect(isIndexable(@TypeOf(tuple))); | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | pub fn isNumber(comptime T: type) bool { |
| ... | ... | @@ -317,13 +317,13 @@ test "std.meta.trait.isNumber" { |
| 317 | 317 | number: u8, |
| 318 | 318 | }; |
| 319 | 319 | |
| 320 | testing.expect(isNumber(u32)); | |
| 321 | testing.expect(isNumber(f32)); | |
| 322 | testing.expect(isNumber(u64)); | |
| 323 | testing.expect(isNumber(@TypeOf(102))); | |
| 324 | testing.expect(isNumber(@TypeOf(102.123))); | |
| 325 | testing.expect(!isNumber([]u8)); | |
| 326 | testing.expect(!isNumber(NotANumber)); | |
| 320 | try testing.expect(isNumber(u32)); | |
| 321 | try testing.expect(isNumber(f32)); | |
| 322 | try testing.expect(isNumber(u64)); | |
| 323 | try testing.expect(isNumber(@TypeOf(102))); | |
| 324 | try testing.expect(isNumber(@TypeOf(102.123))); | |
| 325 | try testing.expect(!isNumber([]u8)); | |
| 326 | try testing.expect(!isNumber(NotANumber)); | |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | pub fn isIntegral(comptime T: type) bool { |
| ... | ... | @@ -334,12 +334,12 @@ pub fn isIntegral(comptime T: type) bool { |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | test "isIntegral" { |
| 337 | testing.expect(isIntegral(u32)); | |
| 338 | testing.expect(!isIntegral(f32)); | |
| 339 | testing.expect(isIntegral(@TypeOf(102))); | |
| 340 | testing.expect(!isIntegral(@TypeOf(102.123))); | |
| 341 | testing.expect(!isIntegral(*u8)); | |
| 342 | testing.expect(!isIntegral([]u8)); | |
| 337 | try testing.expect(isIntegral(u32)); | |
| 338 | try testing.expect(!isIntegral(f32)); | |
| 339 | try testing.expect(isIntegral(@TypeOf(102))); | |
| 340 | try testing.expect(!isIntegral(@TypeOf(102.123))); | |
| 341 | try testing.expect(!isIntegral(*u8)); | |
| 342 | try testing.expect(!isIntegral([]u8)); | |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | pub fn isFloat(comptime T: type) bool { |
| ... | ... | @@ -350,12 +350,12 @@ pub fn isFloat(comptime T: type) bool { |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | test "isFloat" { |
| 353 | testing.expect(!isFloat(u32)); | |
| 354 | testing.expect(isFloat(f32)); | |
| 355 | testing.expect(!isFloat(@TypeOf(102))); | |
| 356 | testing.expect(isFloat(@TypeOf(102.123))); | |
| 357 | testing.expect(!isFloat(*f64)); | |
| 358 | testing.expect(!isFloat([]f32)); | |
| 353 | try testing.expect(!isFloat(u32)); | |
| 354 | try testing.expect(isFloat(f32)); | |
| 355 | try testing.expect(!isFloat(@TypeOf(102))); | |
| 356 | try testing.expect(isFloat(@TypeOf(102.123))); | |
| 357 | try testing.expect(!isFloat(*f64)); | |
| 358 | try testing.expect(!isFloat([]f32)); | |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | pub fn isConstPtr(comptime T: type) bool { |
| ... | ... | @@ -366,10 +366,10 @@ pub fn isConstPtr(comptime T: type) bool { |
| 366 | 366 | test "std.meta.trait.isConstPtr" { |
| 367 | 367 | var t = @as(u8, 0); |
| 368 | 368 | const c = @as(u8, 0); |
| 369 | testing.expect(isConstPtr(*const @TypeOf(t))); | |
| 370 | testing.expect(isConstPtr(@TypeOf(&c))); | |
| 371 | testing.expect(!isConstPtr(*@TypeOf(t))); | |
| 372 | testing.expect(!isConstPtr(@TypeOf(6))); | |
| 369 | try testing.expect(isConstPtr(*const @TypeOf(t))); | |
| 370 | try testing.expect(isConstPtr(@TypeOf(&c))); | |
| 371 | try testing.expect(!isConstPtr(*@TypeOf(t))); | |
| 372 | try testing.expect(!isConstPtr(@TypeOf(6))); | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | pub fn isContainer(comptime T: type) bool { |
| ... | ... | @@ -389,10 +389,10 @@ test "std.meta.trait.isContainer" { |
| 389 | 389 | B, |
| 390 | 390 | }; |
| 391 | 391 | |
| 392 | testing.expect(isContainer(TestStruct)); | |
| 393 | testing.expect(isContainer(TestUnion)); | |
| 394 | testing.expect(isContainer(TestEnum)); | |
| 395 | testing.expect(!isContainer(u8)); | |
| 392 | try testing.expect(isContainer(TestStruct)); | |
| 393 | try testing.expect(isContainer(TestUnion)); | |
| 394 | try testing.expect(isContainer(TestEnum)); | |
| 395 | try testing.expect(!isContainer(u8)); | |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | pub fn isTuple(comptime T: type) bool { |
| ... | ... | @@ -403,9 +403,9 @@ test "std.meta.trait.isTuple" { |
| 403 | 403 | const t1 = struct {}; |
| 404 | 404 | const t2 = .{ .a = 0 }; |
| 405 | 405 | const t3 = .{ 1, 2, 3 }; |
| 406 | testing.expect(!isTuple(t1)); | |
| 407 | testing.expect(!isTuple(@TypeOf(t2))); | |
| 408 | testing.expect(isTuple(@TypeOf(t3))); | |
| 406 | try testing.expect(!isTuple(t1)); | |
| 407 | try testing.expect(!isTuple(@TypeOf(t2))); | |
| 408 | try testing.expect(isTuple(@TypeOf(t3))); | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /// Returns true if the passed type will coerce to []const u8. |
| ... | ... | @@ -449,41 +449,41 @@ pub fn isZigString(comptime T: type) bool { |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | test "std.meta.trait.isZigString" { |
| 452 | testing.expect(isZigString([]const u8)); | |
| 453 | testing.expect(isZigString([]u8)); | |
| 454 | testing.expect(isZigString([:0]const u8)); | |
| 455 | testing.expect(isZigString([:0]u8)); | |
| 456 | testing.expect(isZigString([:5]const u8)); | |
| 457 | testing.expect(isZigString([:5]u8)); | |
| 458 | testing.expect(isZigString(*const [0]u8)); | |
| 459 | testing.expect(isZigString(*[0]u8)); | |
| 460 | testing.expect(isZigString(*const [0:0]u8)); | |
| 461 | testing.expect(isZigString(*[0:0]u8)); | |
| 462 | testing.expect(isZigString(*const [0:5]u8)); | |
| 463 | testing.expect(isZigString(*[0:5]u8)); | |
| 464 | testing.expect(isZigString(*const [10]u8)); | |
| 465 | testing.expect(isZigString(*[10]u8)); | |
| 466 | testing.expect(isZigString(*const [10:0]u8)); | |
| 467 | testing.expect(isZigString(*[10:0]u8)); | |
| 468 | testing.expect(isZigString(*const [10:5]u8)); | |
| 469 | testing.expect(isZigString(*[10:5]u8)); | |
| 470 | ||
| 471 | testing.expect(!isZigString(u8)); | |
| 472 | testing.expect(!isZigString([4]u8)); | |
| 473 | testing.expect(!isZigString([4:0]u8)); | |
| 474 | testing.expect(!isZigString([*]const u8)); | |
| 475 | testing.expect(!isZigString([*]const [4]u8)); | |
| 476 | testing.expect(!isZigString([*c]const u8)); | |
| 477 | testing.expect(!isZigString([*c]const [4]u8)); | |
| 478 | testing.expect(!isZigString([*:0]const u8)); | |
| 479 | testing.expect(!isZigString([*:0]const u8)); | |
| 480 | testing.expect(!isZigString(*[]const u8)); | |
| 481 | testing.expect(!isZigString(?[]const u8)); | |
| 482 | testing.expect(!isZigString(?*const [4]u8)); | |
| 483 | testing.expect(!isZigString([]allowzero u8)); | |
| 484 | testing.expect(!isZigString([]volatile u8)); | |
| 485 | testing.expect(!isZigString(*allowzero [4]u8)); | |
| 486 | testing.expect(!isZigString(*volatile [4]u8)); | |
| 452 | try testing.expect(isZigString([]const u8)); | |
| 453 | try testing.expect(isZigString([]u8)); | |
| 454 | try testing.expect(isZigString([:0]const u8)); | |
| 455 | try testing.expect(isZigString([:0]u8)); | |
| 456 | try testing.expect(isZigString([:5]const u8)); | |
| 457 | try testing.expect(isZigString([:5]u8)); | |
| 458 | try testing.expect(isZigString(*const [0]u8)); | |
| 459 | try testing.expect(isZigString(*[0]u8)); | |
| 460 | try testing.expect(isZigString(*const [0:0]u8)); | |
| 461 | try testing.expect(isZigString(*[0:0]u8)); | |
| 462 | try testing.expect(isZigString(*const [0:5]u8)); | |
| 463 | try testing.expect(isZigString(*[0:5]u8)); | |
| 464 | try testing.expect(isZigString(*const [10]u8)); | |
| 465 | try testing.expect(isZigString(*[10]u8)); | |
| 466 | try testing.expect(isZigString(*const [10:0]u8)); | |
| 467 | try testing.expect(isZigString(*[10:0]u8)); | |
| 468 | try testing.expect(isZigString(*const [10:5]u8)); | |
| 469 | try testing.expect(isZigString(*[10:5]u8)); | |
| 470 | ||
| 471 | try testing.expect(!isZigString(u8)); | |
| 472 | try testing.expect(!isZigString([4]u8)); | |
| 473 | try testing.expect(!isZigString([4:0]u8)); | |
| 474 | try testing.expect(!isZigString([*]const u8)); | |
| 475 | try testing.expect(!isZigString([*]const [4]u8)); | |
| 476 | try testing.expect(!isZigString([*c]const u8)); | |
| 477 | try testing.expect(!isZigString([*c]const [4]u8)); | |
| 478 | try testing.expect(!isZigString([*:0]const u8)); | |
| 479 | try testing.expect(!isZigString([*:0]const u8)); | |
| 480 | try testing.expect(!isZigString(*[]const u8)); | |
| 481 | try testing.expect(!isZigString(?[]const u8)); | |
| 482 | try testing.expect(!isZigString(?*const [4]u8)); | |
| 483 | try testing.expect(!isZigString([]allowzero u8)); | |
| 484 | try testing.expect(!isZigString([]volatile u8)); | |
| 485 | try testing.expect(!isZigString(*allowzero [4]u8)); | |
| 486 | try testing.expect(!isZigString(*volatile [4]u8)); | |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | pub fn hasDecls(comptime T: type, comptime names: anytype) bool { |
| ... | ... | @@ -505,11 +505,11 @@ test "std.meta.trait.hasDecls" { |
| 505 | 505 | |
| 506 | 506 | const tuple = .{ "a", "b", "c" }; |
| 507 | 507 | |
| 508 | testing.expect(!hasDecls(TestStruct1, .{"a"})); | |
| 509 | testing.expect(hasDecls(TestStruct2, .{ "a", "b" })); | |
| 510 | testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" })); | |
| 511 | testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" })); | |
| 512 | testing.expect(!hasDecls(TestStruct2, tuple)); | |
| 508 | try testing.expect(!hasDecls(TestStruct1, .{"a"})); | |
| 509 | try testing.expect(hasDecls(TestStruct2, .{ "a", "b" })); | |
| 510 | try testing.expect(hasDecls(TestStruct2, .{ "a", "b", "useless" })); | |
| 511 | try testing.expect(!hasDecls(TestStruct2, .{ "a", "b", "c" })); | |
| 512 | try testing.expect(!hasDecls(TestStruct2, tuple)); | |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | pub fn hasFields(comptime T: type, comptime names: anytype) bool { |
| ... | ... | @@ -531,11 +531,11 @@ test "std.meta.trait.hasFields" { |
| 531 | 531 | |
| 532 | 532 | const tuple = .{ "a", "b", "c" }; |
| 533 | 533 | |
| 534 | testing.expect(!hasFields(TestStruct1, .{"a"})); | |
| 535 | testing.expect(hasFields(TestStruct2, .{ "a", "b" })); | |
| 536 | testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" })); | |
| 537 | testing.expect(hasFields(TestStruct2, tuple)); | |
| 538 | testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" })); | |
| 534 | try testing.expect(!hasFields(TestStruct1, .{"a"})); | |
| 535 | try testing.expect(hasFields(TestStruct2, .{ "a", "b" })); | |
| 536 | try testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" })); | |
| 537 | try testing.expect(hasFields(TestStruct2, tuple)); | |
| 538 | try testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" })); | |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | pub fn hasFunctions(comptime T: type, comptime names: anytype) bool { |
| ... | ... | @@ -555,10 +555,10 @@ test "std.meta.trait.hasFunctions" { |
| 555 | 555 | |
| 556 | 556 | const tuple = .{ "a", "b", "c" }; |
| 557 | 557 | |
| 558 | testing.expect(!hasFunctions(TestStruct1, .{"a"})); | |
| 559 | testing.expect(hasFunctions(TestStruct2, .{ "a", "b" })); | |
| 560 | testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" })); | |
| 561 | testing.expect(!hasFunctions(TestStruct2, tuple)); | |
| 558 | try testing.expect(!hasFunctions(TestStruct1, .{"a"})); | |
| 559 | try testing.expect(hasFunctions(TestStruct2, .{ "a", "b" })); | |
| 560 | try testing.expect(!hasFunctions(TestStruct2, .{ "a", "b", "c" })); | |
| 561 | try testing.expect(!hasFunctions(TestStruct2, tuple)); | |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 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 | 606 | b: u32, |
| 607 | 607 | }; |
| 608 | 608 | |
| 609 | testing.expect(hasUniqueRepresentation(TestStruct1)); | |
| 609 | try testing.expect(hasUniqueRepresentation(TestStruct1)); | |
| 610 | 610 | |
| 611 | 611 | const TestStruct2 = struct { |
| 612 | 612 | a: u32, |
| 613 | 613 | b: u16, |
| 614 | 614 | }; |
| 615 | 615 | |
| 616 | testing.expect(!hasUniqueRepresentation(TestStruct2)); | |
| 616 | try testing.expect(!hasUniqueRepresentation(TestStruct2)); | |
| 617 | 617 | |
| 618 | 618 | const TestStruct3 = struct { |
| 619 | 619 | a: u32, |
| 620 | 620 | b: u32, |
| 621 | 621 | }; |
| 622 | 622 | |
| 623 | testing.expect(hasUniqueRepresentation(TestStruct3)); | |
| 623 | try testing.expect(hasUniqueRepresentation(TestStruct3)); | |
| 624 | 624 | |
| 625 | 625 | const TestStruct4 = struct { a: []const u8 }; |
| 626 | 626 | |
| 627 | testing.expect(!hasUniqueRepresentation(TestStruct4)); | |
| 627 | try testing.expect(!hasUniqueRepresentation(TestStruct4)); | |
| 628 | 628 | |
| 629 | 629 | const TestStruct5 = struct { a: TestStruct4 }; |
| 630 | 630 | |
| 631 | testing.expect(!hasUniqueRepresentation(TestStruct5)); | |
| 631 | try testing.expect(!hasUniqueRepresentation(TestStruct5)); | |
| 632 | 632 | |
| 633 | 633 | const TestUnion1 = packed union { |
| 634 | 634 | a: u32, |
| 635 | 635 | b: u16, |
| 636 | 636 | }; |
| 637 | 637 | |
| 638 | testing.expect(!hasUniqueRepresentation(TestUnion1)); | |
| 638 | try testing.expect(!hasUniqueRepresentation(TestUnion1)); | |
| 639 | 639 | |
| 640 | 640 | const TestUnion2 = extern union { |
| 641 | 641 | a: u32, |
| 642 | 642 | b: u16, |
| 643 | 643 | }; |
| 644 | 644 | |
| 645 | testing.expect(!hasUniqueRepresentation(TestUnion2)); | |
| 645 | try testing.expect(!hasUniqueRepresentation(TestUnion2)); | |
| 646 | 646 | |
| 647 | 647 | const TestUnion3 = union { |
| 648 | 648 | a: u32, |
| 649 | 649 | b: u16, |
| 650 | 650 | }; |
| 651 | 651 | |
| 652 | testing.expect(!hasUniqueRepresentation(TestUnion3)); | |
| 652 | try testing.expect(!hasUniqueRepresentation(TestUnion3)); | |
| 653 | 653 | |
| 654 | 654 | const TestUnion4 = union(enum) { |
| 655 | 655 | a: u32, |
| 656 | 656 | b: u16, |
| 657 | 657 | }; |
| 658 | 658 | |
| 659 | testing.expect(!hasUniqueRepresentation(TestUnion4)); | |
| 659 | try testing.expect(!hasUniqueRepresentation(TestUnion4)); | |
| 660 | 660 | |
| 661 | 661 | inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| { |
| 662 | testing.expect(hasUniqueRepresentation(T)); | |
| 662 | try testing.expect(hasUniqueRepresentation(T)); | |
| 663 | 663 | } |
| 664 | 664 | inline for ([_]type{ i1, u9, i17, u33, i24 }) |T| { |
| 665 | testing.expect(!hasUniqueRepresentation(T)); | |
| 665 | try testing.expect(!hasUniqueRepresentation(T)); | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | testing.expect(!hasUniqueRepresentation([]u8)); | |
| 669 | testing.expect(!hasUniqueRepresentation([]const u8)); | |
| 668 | try testing.expect(!hasUniqueRepresentation([]u8)); | |
| 669 | try testing.expect(!hasUniqueRepresentation([]const u8)); | |
| 670 | 670 | } |
lib/std/multi_array_list.zig+57-57| ... | ... | @@ -303,7 +303,7 @@ test "basic usage" { |
| 303 | 303 | var list = MultiArrayList(Foo){}; |
| 304 | 304 | defer list.deinit(ally); |
| 305 | 305 | |
| 306 | testing.expectEqual(@as(usize, 0), list.items(.a).len); | |
| 306 | try testing.expectEqual(@as(usize, 0), list.items(.a).len); | |
| 307 | 307 | |
| 308 | 308 | try list.ensureCapacity(ally, 2); |
| 309 | 309 | |
| ... | ... | @@ -319,12 +319,12 @@ test "basic usage" { |
| 319 | 319 | .c = 'b', |
| 320 | 320 | }); |
| 321 | 321 | |
| 322 | testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 }); | |
| 323 | testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' }); | |
| 322 | try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2 }); | |
| 323 | try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b' }); | |
| 324 | 324 | |
| 325 | testing.expectEqual(@as(usize, 2), list.items(.b).len); | |
| 326 | testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 327 | testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 325 | try testing.expectEqual(@as(usize, 2), list.items(.b).len); | |
| 326 | try testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 327 | try testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 328 | 328 | |
| 329 | 329 | try list.append(ally, .{ |
| 330 | 330 | .a = 3, |
| ... | ... | @@ -332,13 +332,13 @@ test "basic usage" { |
| 332 | 332 | .c = 'c', |
| 333 | 333 | }); |
| 334 | 334 | |
| 335 | testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 }); | |
| 336 | testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' }); | |
| 335 | try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 }); | |
| 336 | try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' }); | |
| 337 | 337 | |
| 338 | testing.expectEqual(@as(usize, 3), list.items(.b).len); | |
| 339 | testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 340 | testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 341 | testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]); | |
| 338 | try testing.expectEqual(@as(usize, 3), list.items(.b).len); | |
| 339 | try testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 340 | try testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 341 | try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]); | |
| 342 | 342 | |
| 343 | 343 | // Add 6 more things to force a capacity increase. |
| 344 | 344 | var i: usize = 0; |
| ... | ... | @@ -350,12 +350,12 @@ test "basic usage" { |
| 350 | 350 | }); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | testing.expectEqualSlices( | |
| 353 | try testing.expectEqualSlices( | |
| 354 | 354 | u32, |
| 355 | 355 | &[_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, |
| 356 | 356 | list.items(.a), |
| 357 | 357 | ); |
| 358 | testing.expectEqualSlices( | |
| 358 | try testing.expectEqualSlices( | |
| 359 | 359 | u8, |
| 360 | 360 | &[_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' }, |
| 361 | 361 | list.items(.c), |
| ... | ... | @@ -363,13 +363,13 @@ test "basic usage" { |
| 363 | 363 | |
| 364 | 364 | list.shrinkAndFree(ally, 3); |
| 365 | 365 | |
| 366 | testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 }); | |
| 367 | testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' }); | |
| 366 | try testing.expectEqualSlices(u32, list.items(.a), &[_]u32{ 1, 2, 3 }); | |
| 367 | try testing.expectEqualSlices(u8, list.items(.c), &[_]u8{ 'a', 'b', 'c' }); | |
| 368 | 368 | |
| 369 | testing.expectEqual(@as(usize, 3), list.items(.b).len); | |
| 370 | testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 371 | testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 372 | testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]); | |
| 369 | try testing.expectEqual(@as(usize, 3), list.items(.b).len); | |
| 370 | try testing.expectEqualStrings("foobar", list.items(.b)[0]); | |
| 371 | try testing.expectEqualStrings("zigzag", list.items(.b)[1]); | |
| 372 | try testing.expectEqualStrings("fizzbuzz", list.items(.b)[2]); | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // This was observed to fail on aarch64 with LLVM 11, when the capacityInBytes |
| ... | ... | @@ -418,37 +418,37 @@ test "regression test for @reduce bug" { |
| 418 | 418 | try list.append(ally, .{ .tag = .eof, .start = 123 }); |
| 419 | 419 | |
| 420 | 420 | const tags = list.items(.tag); |
| 421 | testing.expectEqual(tags[1], .identifier); | |
| 422 | testing.expectEqual(tags[2], .equal); | |
| 423 | testing.expectEqual(tags[3], .builtin); | |
| 424 | testing.expectEqual(tags[4], .l_paren); | |
| 425 | testing.expectEqual(tags[5], .string_literal); | |
| 426 | testing.expectEqual(tags[6], .r_paren); | |
| 427 | testing.expectEqual(tags[7], .semicolon); | |
| 428 | testing.expectEqual(tags[8], .keyword_pub); | |
| 429 | testing.expectEqual(tags[9], .keyword_fn); | |
| 430 | testing.expectEqual(tags[10], .identifier); | |
| 431 | testing.expectEqual(tags[11], .l_paren); | |
| 432 | testing.expectEqual(tags[12], .r_paren); | |
| 433 | testing.expectEqual(tags[13], .identifier); | |
| 434 | testing.expectEqual(tags[14], .bang); | |
| 435 | testing.expectEqual(tags[15], .identifier); | |
| 436 | testing.expectEqual(tags[16], .l_brace); | |
| 437 | testing.expectEqual(tags[17], .identifier); | |
| 438 | testing.expectEqual(tags[18], .period); | |
| 439 | testing.expectEqual(tags[19], .identifier); | |
| 440 | testing.expectEqual(tags[20], .period); | |
| 441 | testing.expectEqual(tags[21], .identifier); | |
| 442 | testing.expectEqual(tags[22], .l_paren); | |
| 443 | testing.expectEqual(tags[23], .string_literal); | |
| 444 | testing.expectEqual(tags[24], .comma); | |
| 445 | testing.expectEqual(tags[25], .period); | |
| 446 | testing.expectEqual(tags[26], .l_brace); | |
| 447 | testing.expectEqual(tags[27], .r_brace); | |
| 448 | testing.expectEqual(tags[28], .r_paren); | |
| 449 | testing.expectEqual(tags[29], .semicolon); | |
| 450 | testing.expectEqual(tags[30], .r_brace); | |
| 451 | testing.expectEqual(tags[31], .eof); | |
| 421 | try testing.expectEqual(tags[1], .identifier); | |
| 422 | try testing.expectEqual(tags[2], .equal); | |
| 423 | try testing.expectEqual(tags[3], .builtin); | |
| 424 | try testing.expectEqual(tags[4], .l_paren); | |
| 425 | try testing.expectEqual(tags[5], .string_literal); | |
| 426 | try testing.expectEqual(tags[6], .r_paren); | |
| 427 | try testing.expectEqual(tags[7], .semicolon); | |
| 428 | try testing.expectEqual(tags[8], .keyword_pub); | |
| 429 | try testing.expectEqual(tags[9], .keyword_fn); | |
| 430 | try testing.expectEqual(tags[10], .identifier); | |
| 431 | try testing.expectEqual(tags[11], .l_paren); | |
| 432 | try testing.expectEqual(tags[12], .r_paren); | |
| 433 | try testing.expectEqual(tags[13], .identifier); | |
| 434 | try testing.expectEqual(tags[14], .bang); | |
| 435 | try testing.expectEqual(tags[15], .identifier); | |
| 436 | try testing.expectEqual(tags[16], .l_brace); | |
| 437 | try testing.expectEqual(tags[17], .identifier); | |
| 438 | try testing.expectEqual(tags[18], .period); | |
| 439 | try testing.expectEqual(tags[19], .identifier); | |
| 440 | try testing.expectEqual(tags[20], .period); | |
| 441 | try testing.expectEqual(tags[21], .identifier); | |
| 442 | try testing.expectEqual(tags[22], .l_paren); | |
| 443 | try testing.expectEqual(tags[23], .string_literal); | |
| 444 | try testing.expectEqual(tags[24], .comma); | |
| 445 | try testing.expectEqual(tags[25], .period); | |
| 446 | try testing.expectEqual(tags[26], .l_brace); | |
| 447 | try testing.expectEqual(tags[27], .r_brace); | |
| 448 | try testing.expectEqual(tags[28], .r_paren); | |
| 449 | try testing.expectEqual(tags[29], .semicolon); | |
| 450 | try testing.expectEqual(tags[30], .r_brace); | |
| 451 | try testing.expectEqual(tags[31], .eof); | |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | test "ensure capacity on empty list" { |
| ... | ... | @@ -466,15 +466,15 @@ test "ensure capacity on empty list" { |
| 466 | 466 | list.appendAssumeCapacity(.{ .a = 1, .b = 2 }); |
| 467 | 467 | list.appendAssumeCapacity(.{ .a = 3, .b = 4 }); |
| 468 | 468 | |
| 469 | testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a)); | |
| 470 | testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b)); | |
| 469 | try testing.expectEqualSlices(u32, &[_]u32{ 1, 3 }, list.items(.a)); | |
| 470 | try testing.expectEqualSlices(u8, &[_]u8{ 2, 4 }, list.items(.b)); | |
| 471 | 471 | |
| 472 | 472 | list.len = 0; |
| 473 | 473 | list.appendAssumeCapacity(.{ .a = 5, .b = 6 }); |
| 474 | 474 | list.appendAssumeCapacity(.{ .a = 7, .b = 8 }); |
| 475 | 475 | |
| 476 | testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a)); | |
| 477 | testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b)); | |
| 476 | try testing.expectEqualSlices(u32, &[_]u32{ 5, 7 }, list.items(.a)); | |
| 477 | try testing.expectEqualSlices(u8, &[_]u8{ 6, 8 }, list.items(.b)); | |
| 478 | 478 | |
| 479 | 479 | list.len = 0; |
| 480 | 480 | try list.ensureCapacity(ally, 16); |
| ... | ... | @@ -482,6 +482,6 @@ test "ensure capacity on empty list" { |
| 482 | 482 | list.appendAssumeCapacity(.{ .a = 9, .b = 10 }); |
| 483 | 483 | list.appendAssumeCapacity(.{ .a = 11, .b = 12 }); |
| 484 | 484 | |
| 485 | testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a)); | |
| 486 | testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b)); | |
| 485 | try testing.expectEqualSlices(u32, &[_]u32{ 9, 11 }, list.items(.a)); | |
| 486 | try testing.expectEqualSlices(u8, &[_]u8{ 10, 12 }, list.items(.b)); | |
| 487 | 487 | } |
lib/std/net/test.zig+24-24| ... | ... | @@ -38,26 +38,26 @@ test "parse and render IPv6 addresses" { |
| 38 | 38 | for (ips) |ip, i| { |
| 39 | 39 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; |
| 40 | 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])); | |
| 42 | 42 | |
| 43 | 43 | if (std.builtin.os.tag == .linux) { |
| 44 | 44 | var addr_via_resolve = net.Address.resolveIp6(ip, 0) catch unreachable; |
| 45 | 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 | } |
| 49 | 49 | |
| 50 | testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0)); | |
| 51 | testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0)); | |
| 52 | testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0)); | |
| 53 | testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0)); | |
| 54 | testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0)); | |
| 55 | testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0)); | |
| 50 | try testing.expectError(error.InvalidCharacter, net.Address.parseIp6(":::", 0)); | |
| 51 | try testing.expectError(error.Overflow, net.Address.parseIp6("FF001::FB", 0)); | |
| 52 | try testing.expectError(error.InvalidCharacter, net.Address.parseIp6("FF01::Fb:zig", 0)); | |
| 53 | try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0)); | |
| 54 | try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0)); | |
| 55 | try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0)); | |
| 56 | 56 | // TODO Make this test pass on other operating systems. |
| 57 | 57 | if (std.builtin.os.tag == .linux) { |
| 58 | testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0)); | |
| 59 | testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0)); | |
| 60 | testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0)); | |
| 58 | try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0)); | |
| 59 | try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%wlp3s0s0s0s0s0s0s0s0", 0)); | |
| 60 | try testing.expectError(error.Overflow, net.Address.resolveIp6("ff01::fb%12345678901234", 0)); | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -68,7 +68,7 @@ test "invalid but parseable IPv6 scope ids" { |
| 68 | 68 | return error.SkipZigTest; |
| 69 | 69 | } |
| 70 | 70 | |
| 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 | } |
| 73 | 73 | |
| 74 | 74 | test "parse and render IPv4 addresses" { |
| ... | ... | @@ -84,14 +84,14 @@ test "parse and render IPv4 addresses" { |
| 84 | 84 | }) |ip| { |
| 85 | 85 | var addr = net.Address.parseIp4(ip, 0) catch unreachable; |
| 86 | 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 | } |
| 89 | 89 | |
| 90 | testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0)); | |
| 91 | testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0)); | |
| 92 | testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0)); | |
| 93 | testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0)); | |
| 94 | testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0)); | |
| 90 | try testing.expectError(error.Overflow, net.Address.parseIp4("256.0.0.1", 0)); | |
| 91 | try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("x.0.0.1", 0)); | |
| 92 | try testing.expectError(error.InvalidEnd, net.Address.parseIp4("127.0.0.1.1", 0)); | |
| 93 | try testing.expectError(error.Incomplete, net.Address.parseIp4("127.0.0.", 0)); | |
| 94 | try testing.expectError(error.InvalidCharacter, net.Address.parseIp4("100..0.1", 0)); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | test "resolve DNS" { |
| ... | ... | @@ -169,8 +169,8 @@ test "listen on a port, send bytes, receive bytes" { |
| 169 | 169 | var buf: [16]u8 = undefined; |
| 170 | 170 | const n = try client.stream.reader().read(&buf); |
| 171 | 171 | |
| 172 | testing.expectEqual(@as(usize, 12), n); | |
| 173 | testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); | |
| 172 | try testing.expectEqual(@as(usize, 12), n); | |
| 173 | try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | test "listen on a port, send bytes, receive bytes" { |
| ... | ... | @@ -230,7 +230,7 @@ fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anye |
| 230 | 230 | var buf: [100]u8 = undefined; |
| 231 | 231 | const len = try connection.read(&buf); |
| 232 | 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 | } |
| 235 | 235 | |
| 236 | 236 | fn testClient(addr: net.Address) anyerror!void { |
| ... | ... | @@ -242,7 +242,7 @@ fn testClient(addr: net.Address) anyerror!void { |
| 242 | 242 | var buf: [100]u8 = undefined; |
| 243 | 243 | const len = try socket_file.read(&buf); |
| 244 | 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 | } |
| 247 | 247 | |
| 248 | 248 | fn testServer(server: *net.StreamServer) anyerror!void { |
| ... | ... | @@ -293,6 +293,6 @@ test "listen on a unix socket, send bytes, receive bytes" { |
| 293 | 293 | var buf: [16]u8 = undefined; |
| 294 | 294 | const n = try client.stream.reader().read(&buf); |
| 295 | 295 | |
| 296 | testing.expectEqual(@as(usize, 12), n); | |
| 297 | testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); | |
| 296 | try testing.expectEqual(@as(usize, 12), n); | |
| 297 | try testing.expectEqualSlices(u8, "Hello world!", buf[0..n]); | |
| 298 | 298 | } |
lib/std/once.zig+1-1| ... | ... | @@ -67,5 +67,5 @@ test "Once executes its function just once" { |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 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 | 737 | }; |
| 738 | 738 | |
| 739 | 739 | test "insn bitsize" { |
| 740 | expectEqual(@bitSizeOf(Insn), 64); | |
| 740 | try expectEqual(@bitSizeOf(Insn), 64); | |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | fn expect_opcode(code: u8, insn: Insn) void { | |
| 744 | expectEqual(code, insn.code); | |
| 743 | fn expect_opcode(code: u8, insn: Insn) !void { | |
| 744 | try expectEqual(code, insn.code); | |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | // The opcodes were grabbed from https://github.com/iovisor/bpf-docs/blob/master/eBPF.md |
| ... | ... | @@ -750,108 +750,108 @@ test "opcodes" { |
| 750 | 750 | // loading 64-bit immediates (imm is only 32 bits wide) |
| 751 | 751 | |
| 752 | 752 | // alu instructions |
| 753 | expect_opcode(0x07, Insn.add(.r1, 0)); | |
| 754 | expect_opcode(0x0f, Insn.add(.r1, .r2)); | |
| 755 | expect_opcode(0x17, Insn.sub(.r1, 0)); | |
| 756 | expect_opcode(0x1f, Insn.sub(.r1, .r2)); | |
| 757 | expect_opcode(0x27, Insn.mul(.r1, 0)); | |
| 758 | expect_opcode(0x2f, Insn.mul(.r1, .r2)); | |
| 759 | expect_opcode(0x37, Insn.div(.r1, 0)); | |
| 760 | expect_opcode(0x3f, Insn.div(.r1, .r2)); | |
| 761 | expect_opcode(0x47, Insn.alu_or(.r1, 0)); | |
| 762 | expect_opcode(0x4f, Insn.alu_or(.r1, .r2)); | |
| 763 | expect_opcode(0x57, Insn.alu_and(.r1, 0)); | |
| 764 | expect_opcode(0x5f, Insn.alu_and(.r1, .r2)); | |
| 765 | expect_opcode(0x67, Insn.lsh(.r1, 0)); | |
| 766 | expect_opcode(0x6f, Insn.lsh(.r1, .r2)); | |
| 767 | expect_opcode(0x77, Insn.rsh(.r1, 0)); | |
| 768 | expect_opcode(0x7f, Insn.rsh(.r1, .r2)); | |
| 769 | expect_opcode(0x87, Insn.neg(.r1)); | |
| 770 | expect_opcode(0x97, Insn.mod(.r1, 0)); | |
| 771 | expect_opcode(0x9f, Insn.mod(.r1, .r2)); | |
| 772 | expect_opcode(0xa7, Insn.xor(.r1, 0)); | |
| 773 | expect_opcode(0xaf, Insn.xor(.r1, .r2)); | |
| 774 | expect_opcode(0xb7, Insn.mov(.r1, 0)); | |
| 775 | expect_opcode(0xbf, Insn.mov(.r1, .r2)); | |
| 776 | expect_opcode(0xc7, Insn.arsh(.r1, 0)); | |
| 777 | expect_opcode(0xcf, Insn.arsh(.r1, .r2)); | |
| 753 | try expect_opcode(0x07, Insn.add(.r1, 0)); | |
| 754 | try expect_opcode(0x0f, Insn.add(.r1, .r2)); | |
| 755 | try expect_opcode(0x17, Insn.sub(.r1, 0)); | |
| 756 | try expect_opcode(0x1f, Insn.sub(.r1, .r2)); | |
| 757 | try expect_opcode(0x27, Insn.mul(.r1, 0)); | |
| 758 | try expect_opcode(0x2f, Insn.mul(.r1, .r2)); | |
| 759 | try expect_opcode(0x37, Insn.div(.r1, 0)); | |
| 760 | try expect_opcode(0x3f, Insn.div(.r1, .r2)); | |
| 761 | try expect_opcode(0x47, Insn.alu_or(.r1, 0)); | |
| 762 | try expect_opcode(0x4f, Insn.alu_or(.r1, .r2)); | |
| 763 | try expect_opcode(0x57, Insn.alu_and(.r1, 0)); | |
| 764 | try expect_opcode(0x5f, Insn.alu_and(.r1, .r2)); | |
| 765 | try expect_opcode(0x67, Insn.lsh(.r1, 0)); | |
| 766 | try expect_opcode(0x6f, Insn.lsh(.r1, .r2)); | |
| 767 | try expect_opcode(0x77, Insn.rsh(.r1, 0)); | |
| 768 | try expect_opcode(0x7f, Insn.rsh(.r1, .r2)); | |
| 769 | try expect_opcode(0x87, Insn.neg(.r1)); | |
| 770 | try expect_opcode(0x97, Insn.mod(.r1, 0)); | |
| 771 | try expect_opcode(0x9f, Insn.mod(.r1, .r2)); | |
| 772 | try expect_opcode(0xa7, Insn.xor(.r1, 0)); | |
| 773 | try expect_opcode(0xaf, Insn.xor(.r1, .r2)); | |
| 774 | try expect_opcode(0xb7, Insn.mov(.r1, 0)); | |
| 775 | try expect_opcode(0xbf, Insn.mov(.r1, .r2)); | |
| 776 | try expect_opcode(0xc7, Insn.arsh(.r1, 0)); | |
| 777 | try expect_opcode(0xcf, Insn.arsh(.r1, .r2)); | |
| 778 | 778 | |
| 779 | 779 | // 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)); | |
| 781 | 781 | |
| 782 | 782 | // TODO: byteswap instructions |
| 783 | expect_opcode(0xd4, Insn.le(.half_word, .r1)); | |
| 784 | expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm); | |
| 785 | expect_opcode(0xd4, Insn.le(.word, .r1)); | |
| 786 | expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm); | |
| 787 | expect_opcode(0xd4, Insn.le(.double_word, .r1)); | |
| 788 | expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm); | |
| 789 | expect_opcode(0xdc, Insn.be(.half_word, .r1)); | |
| 790 | expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm); | |
| 791 | expect_opcode(0xdc, Insn.be(.word, .r1)); | |
| 792 | expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm); | |
| 793 | expect_opcode(0xdc, Insn.be(.double_word, .r1)); | |
| 794 | expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm); | |
| 783 | try expect_opcode(0xd4, Insn.le(.half_word, .r1)); | |
| 784 | try expectEqual(@intCast(i32, 16), Insn.le(.half_word, .r1).imm); | |
| 785 | try expect_opcode(0xd4, Insn.le(.word, .r1)); | |
| 786 | try expectEqual(@intCast(i32, 32), Insn.le(.word, .r1).imm); | |
| 787 | try expect_opcode(0xd4, Insn.le(.double_word, .r1)); | |
| 788 | try expectEqual(@intCast(i32, 64), Insn.le(.double_word, .r1).imm); | |
| 789 | try expect_opcode(0xdc, Insn.be(.half_word, .r1)); | |
| 790 | try expectEqual(@intCast(i32, 16), Insn.be(.half_word, .r1).imm); | |
| 791 | try expect_opcode(0xdc, Insn.be(.word, .r1)); | |
| 792 | try expectEqual(@intCast(i32, 32), Insn.be(.word, .r1).imm); | |
| 793 | try expect_opcode(0xdc, Insn.be(.double_word, .r1)); | |
| 794 | try expectEqual(@intCast(i32, 64), Insn.be(.double_word, .r1).imm); | |
| 795 | 795 | |
| 796 | 796 | // memory instructions |
| 797 | expect_opcode(0x18, Insn.ld_dw1(.r1, 0)); | |
| 798 | expect_opcode(0x00, Insn.ld_dw2(0)); | |
| 797 | try expect_opcode(0x18, Insn.ld_dw1(.r1, 0)); | |
| 798 | try expect_opcode(0x00, Insn.ld_dw2(0)); | |
| 799 | 799 | |
| 800 | 800 | // loading a map fd |
| 801 | expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0)); | |
| 802 | expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src); | |
| 803 | expect_opcode(0x00, Insn.ld_map_fd2(0)); | |
| 804 | ||
| 805 | expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0)); | |
| 806 | expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0)); | |
| 807 | expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0)); | |
| 808 | expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0)); | |
| 809 | ||
| 810 | expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0)); | |
| 811 | expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0)); | |
| 812 | expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0)); | |
| 813 | expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0)); | |
| 814 | ||
| 815 | expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0)); | |
| 816 | expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0)); | |
| 817 | expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0)); | |
| 818 | expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0)); | |
| 819 | ||
| 820 | expect_opcode(0x62, Insn.st(.word, .r1, 0, 0)); | |
| 821 | expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0)); | |
| 822 | expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0)); | |
| 823 | ||
| 824 | expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2)); | |
| 825 | expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2)); | |
| 826 | expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2)); | |
| 827 | expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2)); | |
| 801 | try expect_opcode(0x18, Insn.ld_map_fd1(.r1, 0)); | |
| 802 | try expectEqual(@intCast(u4, PSEUDO_MAP_FD), Insn.ld_map_fd1(.r1, 0).src); | |
| 803 | try expect_opcode(0x00, Insn.ld_map_fd2(0)); | |
| 804 | ||
| 805 | try expect_opcode(0x38, Insn.ld_abs(.double_word, .r1, .r2, 0)); | |
| 806 | try expect_opcode(0x20, Insn.ld_abs(.word, .r1, .r2, 0)); | |
| 807 | try expect_opcode(0x28, Insn.ld_abs(.half_word, .r1, .r2, 0)); | |
| 808 | try expect_opcode(0x30, Insn.ld_abs(.byte, .r1, .r2, 0)); | |
| 809 | ||
| 810 | try expect_opcode(0x58, Insn.ld_ind(.double_word, .r1, .r2, 0)); | |
| 811 | try expect_opcode(0x40, Insn.ld_ind(.word, .r1, .r2, 0)); | |
| 812 | try expect_opcode(0x48, Insn.ld_ind(.half_word, .r1, .r2, 0)); | |
| 813 | try expect_opcode(0x50, Insn.ld_ind(.byte, .r1, .r2, 0)); | |
| 814 | ||
| 815 | try expect_opcode(0x79, Insn.ldx(.double_word, .r1, .r2, 0)); | |
| 816 | try expect_opcode(0x61, Insn.ldx(.word, .r1, .r2, 0)); | |
| 817 | try expect_opcode(0x69, Insn.ldx(.half_word, .r1, .r2, 0)); | |
| 818 | try expect_opcode(0x71, Insn.ldx(.byte, .r1, .r2, 0)); | |
| 819 | ||
| 820 | try expect_opcode(0x62, Insn.st(.word, .r1, 0, 0)); | |
| 821 | try expect_opcode(0x6a, Insn.st(.half_word, .r1, 0, 0)); | |
| 822 | try expect_opcode(0x72, Insn.st(.byte, .r1, 0, 0)); | |
| 823 | ||
| 824 | try expect_opcode(0x63, Insn.stx(.word, .r1, 0, .r2)); | |
| 825 | try expect_opcode(0x6b, Insn.stx(.half_word, .r1, 0, .r2)); | |
| 826 | try expect_opcode(0x73, Insn.stx(.byte, .r1, 0, .r2)); | |
| 827 | try expect_opcode(0x7b, Insn.stx(.double_word, .r1, 0, .r2)); | |
| 828 | 828 | |
| 829 | 829 | // branch instructions |
| 830 | expect_opcode(0x05, Insn.ja(0)); | |
| 831 | expect_opcode(0x15, Insn.jeq(.r1, 0, 0)); | |
| 832 | expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0)); | |
| 833 | expect_opcode(0x25, Insn.jgt(.r1, 0, 0)); | |
| 834 | expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0)); | |
| 835 | expect_opcode(0x35, Insn.jge(.r1, 0, 0)); | |
| 836 | expect_opcode(0x3d, Insn.jge(.r1, .r2, 0)); | |
| 837 | expect_opcode(0xa5, Insn.jlt(.r1, 0, 0)); | |
| 838 | expect_opcode(0xad, Insn.jlt(.r1, .r2, 0)); | |
| 839 | expect_opcode(0xb5, Insn.jle(.r1, 0, 0)); | |
| 840 | expect_opcode(0xbd, Insn.jle(.r1, .r2, 0)); | |
| 841 | expect_opcode(0x45, Insn.jset(.r1, 0, 0)); | |
| 842 | expect_opcode(0x4d, Insn.jset(.r1, .r2, 0)); | |
| 843 | expect_opcode(0x55, Insn.jne(.r1, 0, 0)); | |
| 844 | expect_opcode(0x5d, Insn.jne(.r1, .r2, 0)); | |
| 845 | expect_opcode(0x65, Insn.jsgt(.r1, 0, 0)); | |
| 846 | expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0)); | |
| 847 | expect_opcode(0x75, Insn.jsge(.r1, 0, 0)); | |
| 848 | expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0)); | |
| 849 | expect_opcode(0xc5, Insn.jslt(.r1, 0, 0)); | |
| 850 | expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0)); | |
| 851 | expect_opcode(0xd5, Insn.jsle(.r1, 0, 0)); | |
| 852 | expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0)); | |
| 853 | expect_opcode(0x85, Insn.call(.unspec)); | |
| 854 | expect_opcode(0x95, Insn.exit()); | |
| 830 | try expect_opcode(0x05, Insn.ja(0)); | |
| 831 | try expect_opcode(0x15, Insn.jeq(.r1, 0, 0)); | |
| 832 | try expect_opcode(0x1d, Insn.jeq(.r1, .r2, 0)); | |
| 833 | try expect_opcode(0x25, Insn.jgt(.r1, 0, 0)); | |
| 834 | try expect_opcode(0x2d, Insn.jgt(.r1, .r2, 0)); | |
| 835 | try expect_opcode(0x35, Insn.jge(.r1, 0, 0)); | |
| 836 | try expect_opcode(0x3d, Insn.jge(.r1, .r2, 0)); | |
| 837 | try expect_opcode(0xa5, Insn.jlt(.r1, 0, 0)); | |
| 838 | try expect_opcode(0xad, Insn.jlt(.r1, .r2, 0)); | |
| 839 | try expect_opcode(0xb5, Insn.jle(.r1, 0, 0)); | |
| 840 | try expect_opcode(0xbd, Insn.jle(.r1, .r2, 0)); | |
| 841 | try expect_opcode(0x45, Insn.jset(.r1, 0, 0)); | |
| 842 | try expect_opcode(0x4d, Insn.jset(.r1, .r2, 0)); | |
| 843 | try expect_opcode(0x55, Insn.jne(.r1, 0, 0)); | |
| 844 | try expect_opcode(0x5d, Insn.jne(.r1, .r2, 0)); | |
| 845 | try expect_opcode(0x65, Insn.jsgt(.r1, 0, 0)); | |
| 846 | try expect_opcode(0x6d, Insn.jsgt(.r1, .r2, 0)); | |
| 847 | try expect_opcode(0x75, Insn.jsge(.r1, 0, 0)); | |
| 848 | try expect_opcode(0x7d, Insn.jsge(.r1, .r2, 0)); | |
| 849 | try expect_opcode(0xc5, Insn.jslt(.r1, 0, 0)); | |
| 850 | try expect_opcode(0xcd, Insn.jslt(.r1, .r2, 0)); | |
| 851 | try expect_opcode(0xd5, Insn.jsle(.r1, 0, 0)); | |
| 852 | try expect_opcode(0xdd, Insn.jsle(.r1, .r2, 0)); | |
| 853 | try expect_opcode(0x85, Insn.call(.unspec)); | |
| 854 | try expect_opcode(0x95, Insn.exit()); | |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | pub const Cmd = extern enum(usize) { |
| ... | ... | @@ -1596,7 +1596,7 @@ test "map lookup, update, and delete" { |
| 1596 | 1596 | var value = std.mem.zeroes([value_size]u8); |
| 1597 | 1597 | |
| 1598 | 1598 | // 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)); | |
| 1600 | 1600 | |
| 1601 | 1601 | // succeed at updating and looking up element |
| 1602 | 1602 | try map_update_elem(map, &key, &value, 0); |
| ... | ... | @@ -1604,14 +1604,14 @@ test "map lookup, update, and delete" { |
| 1604 | 1604 | |
| 1605 | 1605 | // fails inserting more than max entries |
| 1606 | 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)); | |
| 1608 | 1608 | |
| 1609 | 1609 | // succeed at deleting an existing elem |
| 1610 | 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)); | |
| 1612 | 1612 | |
| 1613 | 1613 | // 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 | } |
| 1616 | 1616 | |
| 1617 | 1617 | pub fn prog_load( |
| ... | ... | @@ -1662,5 +1662,5 @@ test "prog_load" { |
| 1662 | 1662 | const prog = try prog_load(.socket_filter, &good_prog, null, "MIT", 0); |
| 1663 | 1663 | defer std.os.close(prog); |
| 1664 | 1664 | |
| 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 | 92 | }; |
| 93 | 93 | |
| 94 | 94 | test "IntInfo is 32 bits" { |
| 95 | std.testing.expectEqual(@bitSizeOf(IntInfo), 32); | |
| 95 | try std.testing.expectEqual(@bitSizeOf(IntInfo), 32); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /// 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 | 937 | test "structs/offsets/entries" { |
| 938 | 938 | if (builtin.os.tag != .linux) return error.SkipZigTest; |
| 939 | 939 | |
| 940 | testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params)); | |
| 941 | testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe)); | |
| 942 | testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe)); | |
| 940 | try testing.expectEqual(@as(usize, 120), @sizeOf(io_uring_params)); | |
| 941 | try testing.expectEqual(@as(usize, 64), @sizeOf(io_uring_sqe)); | |
| 942 | try testing.expectEqual(@as(usize, 16), @sizeOf(io_uring_cqe)); | |
| 943 | 943 | |
| 944 | testing.expectEqual(0, linux.IORING_OFF_SQ_RING); | |
| 945 | testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING); | |
| 946 | testing.expectEqual(0x10000000, linux.IORING_OFF_SQES); | |
| 944 | try testing.expectEqual(0, linux.IORING_OFF_SQ_RING); | |
| 945 | try testing.expectEqual(0x8000000, linux.IORING_OFF_CQ_RING); | |
| 946 | try testing.expectEqual(0x10000000, linux.IORING_OFF_SQES); | |
| 947 | 947 | |
| 948 | testing.expectError(error.EntriesZero, IO_Uring.init(0, 0)); | |
| 949 | testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0)); | |
| 948 | try testing.expectError(error.EntriesZero, IO_Uring.init(0, 0)); | |
| 949 | try testing.expectError(error.EntriesNotPowerOfTwo, IO_Uring.init(3, 0)); | |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | test "nop" { |
| ... | ... | @@ -959,11 +959,11 @@ test "nop" { |
| 959 | 959 | }; |
| 960 | 960 | defer { |
| 961 | 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 | } |
| 964 | 964 | |
| 965 | 965 | const sqe = try ring.nop(0xaaaaaaaa); |
| 966 | testing.expectEqual(io_uring_sqe{ | |
| 966 | try testing.expectEqual(io_uring_sqe{ | |
| 967 | 967 | .opcode = .NOP, |
| 968 | 968 | .flags = 0, |
| 969 | 969 | .ioprio = 0, |
| ... | ... | @@ -979,40 +979,40 @@ test "nop" { |
| 979 | 979 | .__pad2 = [2]u64{ 0, 0 }, |
| 980 | 980 | }, sqe.*); |
| 981 | 981 | |
| 982 | testing.expectEqual(@as(u32, 0), ring.sq.sqe_head); | |
| 983 | testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail); | |
| 984 | testing.expectEqual(@as(u32, 0), ring.sq.tail.*); | |
| 985 | testing.expectEqual(@as(u32, 0), ring.cq.head.*); | |
| 986 | testing.expectEqual(@as(u32, 1), ring.sq_ready()); | |
| 987 | testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 988 | ||
| 989 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 990 | testing.expectEqual(@as(u32, 1), ring.sq.sqe_head); | |
| 991 | testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail); | |
| 992 | testing.expectEqual(@as(u32, 1), ring.sq.tail.*); | |
| 993 | testing.expectEqual(@as(u32, 0), ring.cq.head.*); | |
| 994 | testing.expectEqual(@as(u32, 0), ring.sq_ready()); | |
| 995 | ||
| 996 | testing.expectEqual(io_uring_cqe{ | |
| 982 | try testing.expectEqual(@as(u32, 0), ring.sq.sqe_head); | |
| 983 | try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail); | |
| 984 | try testing.expectEqual(@as(u32, 0), ring.sq.tail.*); | |
| 985 | try testing.expectEqual(@as(u32, 0), ring.cq.head.*); | |
| 986 | try testing.expectEqual(@as(u32, 1), ring.sq_ready()); | |
| 987 | try testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 988 | ||
| 989 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 990 | try testing.expectEqual(@as(u32, 1), ring.sq.sqe_head); | |
| 991 | try testing.expectEqual(@as(u32, 1), ring.sq.sqe_tail); | |
| 992 | try testing.expectEqual(@as(u32, 1), ring.sq.tail.*); | |
| 993 | try testing.expectEqual(@as(u32, 0), ring.cq.head.*); | |
| 994 | try testing.expectEqual(@as(u32, 0), ring.sq_ready()); | |
| 995 | ||
| 996 | try testing.expectEqual(io_uring_cqe{ | |
| 997 | 997 | .user_data = 0xaaaaaaaa, |
| 998 | 998 | .res = 0, |
| 999 | 999 | .flags = 0, |
| 1000 | 1000 | }, try ring.copy_cqe()); |
| 1001 | testing.expectEqual(@as(u32, 1), ring.cq.head.*); | |
| 1002 | testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 1001 | try testing.expectEqual(@as(u32, 1), ring.cq.head.*); | |
| 1002 | try testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 1003 | 1003 | |
| 1004 | 1004 | const sqe_barrier = try ring.nop(0xbbbbbbbb); |
| 1005 | 1005 | sqe_barrier.flags |= linux.IOSQE_IO_DRAIN; |
| 1006 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1007 | testing.expectEqual(io_uring_cqe{ | |
| 1006 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1007 | try testing.expectEqual(io_uring_cqe{ | |
| 1008 | 1008 | .user_data = 0xbbbbbbbb, |
| 1009 | 1009 | .res = 0, |
| 1010 | 1010 | .flags = 0, |
| 1011 | 1011 | }, try ring.copy_cqe()); |
| 1012 | testing.expectEqual(@as(u32, 2), ring.sq.sqe_head); | |
| 1013 | testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail); | |
| 1014 | testing.expectEqual(@as(u32, 2), ring.sq.tail.*); | |
| 1015 | testing.expectEqual(@as(u32, 2), ring.cq.head.*); | |
| 1012 | try testing.expectEqual(@as(u32, 2), ring.sq.sqe_head); | |
| 1013 | try testing.expectEqual(@as(u32, 2), ring.sq.sqe_tail); | |
| 1014 | try testing.expectEqual(@as(u32, 2), ring.sq.tail.*); | |
| 1015 | try testing.expectEqual(@as(u32, 2), ring.cq.head.*); | |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | test "readv" { |
| ... | ... | @@ -1042,17 +1042,17 @@ test "readv" { |
| 1042 | 1042 | var buffer = [_]u8{42} ** 128; |
| 1043 | 1043 | var iovecs = [_]os.iovec{os.iovec{ .iov_base = &buffer, .iov_len = buffer.len }}; |
| 1044 | 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 | 1046 | sqe.flags |= linux.IOSQE_FIXED_FILE; |
| 1047 | 1047 | |
| 1048 | testing.expectError(error.SubmissionQueueFull, ring.nop(0)); | |
| 1049 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1050 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1048 | try testing.expectError(error.SubmissionQueueFull, ring.nop(0)); | |
| 1049 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1050 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1051 | 1051 | .user_data = 0xcccccccc, |
| 1052 | 1052 | .res = buffer.len, |
| 1053 | 1053 | .flags = 0, |
| 1054 | 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..]); | |
| 1056 | 1056 | |
| 1057 | 1057 | try ring.unregister_files(); |
| 1058 | 1058 | } |
| ... | ... | @@ -1083,46 +1083,46 @@ test "writev/fsync/readv" { |
| 1083 | 1083 | }; |
| 1084 | 1084 | |
| 1085 | 1085 | const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17); |
| 1086 | testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode); | |
| 1087 | testing.expectEqual(@as(u64, 17), sqe_writev.off); | |
| 1086 | try testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode); | |
| 1087 | try testing.expectEqual(@as(u64, 17), sqe_writev.off); | |
| 1088 | 1088 | sqe_writev.flags |= linux.IOSQE_IO_LINK; |
| 1089 | 1089 | |
| 1090 | 1090 | const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0); |
| 1091 | testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode); | |
| 1092 | testing.expectEqual(fd, sqe_fsync.fd); | |
| 1091 | try testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode); | |
| 1092 | try testing.expectEqual(fd, sqe_fsync.fd); | |
| 1093 | 1093 | sqe_fsync.flags |= linux.IOSQE_IO_LINK; |
| 1094 | 1094 | |
| 1095 | 1095 | const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17); |
| 1096 | testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode); | |
| 1097 | testing.expectEqual(@as(u64, 17), sqe_readv.off); | |
| 1096 | try testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode); | |
| 1097 | try testing.expectEqual(@as(u64, 17), sqe_readv.off); | |
| 1098 | 1098 | |
| 1099 | testing.expectEqual(@as(u32, 3), ring.sq_ready()); | |
| 1100 | testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3)); | |
| 1101 | testing.expectEqual(@as(u32, 0), ring.sq_ready()); | |
| 1102 | testing.expectEqual(@as(u32, 3), ring.cq_ready()); | |
| 1099 | try testing.expectEqual(@as(u32, 3), ring.sq_ready()); | |
| 1100 | try testing.expectEqual(@as(u32, 3), try ring.submit_and_wait(3)); | |
| 1101 | try testing.expectEqual(@as(u32, 0), ring.sq_ready()); | |
| 1102 | try testing.expectEqual(@as(u32, 3), ring.cq_ready()); | |
| 1103 | 1103 | |
| 1104 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1104 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1105 | 1105 | .user_data = 0xdddddddd, |
| 1106 | 1106 | .res = buffer_write.len, |
| 1107 | 1107 | .flags = 0, |
| 1108 | 1108 | }, try ring.copy_cqe()); |
| 1109 | testing.expectEqual(@as(u32, 2), ring.cq_ready()); | |
| 1109 | try testing.expectEqual(@as(u32, 2), ring.cq_ready()); | |
| 1110 | 1110 | |
| 1111 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1111 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1112 | 1112 | .user_data = 0xeeeeeeee, |
| 1113 | 1113 | .res = 0, |
| 1114 | 1114 | .flags = 0, |
| 1115 | 1115 | }, try ring.copy_cqe()); |
| 1116 | testing.expectEqual(@as(u32, 1), ring.cq_ready()); | |
| 1116 | try testing.expectEqual(@as(u32, 1), ring.cq_ready()); | |
| 1117 | 1117 | |
| 1118 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1118 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1119 | 1119 | .user_data = 0xffffffff, |
| 1120 | 1120 | .res = buffer_read.len, |
| 1121 | 1121 | .flags = 0, |
| 1122 | 1122 | }, try ring.copy_cqe()); |
| 1123 | testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 1123 | try testing.expectEqual(@as(u32, 0), ring.cq_ready()); | |
| 1124 | 1124 | |
| 1125 | testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]); | |
| 1125 | try testing.expectEqualSlices(u8, buffer_write[0..], buffer_read[0..]); | |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | test "write/read" { |
| ... | ... | @@ -1144,13 +1144,13 @@ test "write/read" { |
| 1144 | 1144 | const buffer_write = [_]u8{97} ** 20; |
| 1145 | 1145 | var buffer_read = [_]u8{98} ** 20; |
| 1146 | 1146 | const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10); |
| 1147 | testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); | |
| 1148 | testing.expectEqual(@as(u64, 10), sqe_write.off); | |
| 1147 | try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); | |
| 1148 | try testing.expectEqual(@as(u64, 10), sqe_write.off); | |
| 1149 | 1149 | sqe_write.flags |= linux.IOSQE_IO_LINK; |
| 1150 | 1150 | const sqe_read = try ring.read(0x22222222, fd, buffer_read[0..], 10); |
| 1151 | testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode); | |
| 1152 | testing.expectEqual(@as(u64, 10), sqe_read.off); | |
| 1153 | testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1151 | try testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode); | |
| 1152 | try testing.expectEqual(@as(u64, 10), sqe_read.off); | |
| 1153 | try testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1154 | 1154 | |
| 1155 | 1155 | const cqe_write = try ring.copy_cqe(); |
| 1156 | 1156 | const cqe_read = try ring.copy_cqe(); |
| ... | ... | @@ -1158,17 +1158,17 @@ test "write/read" { |
| 1158 | 1158 | // https://lwn.net/Articles/809820/ |
| 1159 | 1159 | if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest; |
| 1160 | 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 | 1162 | .user_data = 0x11111111, |
| 1163 | 1163 | .res = buffer_write.len, |
| 1164 | 1164 | .flags = 0, |
| 1165 | 1165 | }, cqe_write); |
| 1166 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1166 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1167 | 1167 | .user_data = 0x22222222, |
| 1168 | 1168 | .res = buffer_read.len, |
| 1169 | 1169 | .flags = 0, |
| 1170 | 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 | } |
| 1173 | 1173 | |
| 1174 | 1174 | test "openat" { |
| ... | ... | @@ -1187,7 +1187,7 @@ test "openat" { |
| 1187 | 1187 | const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; |
| 1188 | 1188 | const mode: os.mode_t = 0o666; |
| 1189 | 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 | 1191 | .opcode = .OPENAT, |
| 1192 | 1192 | .flags = 0, |
| 1193 | 1193 | .ioprio = 0, |
| ... | ... | @@ -1202,10 +1202,10 @@ test "openat" { |
| 1202 | 1202 | .splice_fd_in = 0, |
| 1203 | 1203 | .__pad2 = [2]u64{ 0, 0 }, |
| 1204 | 1204 | }, sqe_openat.*); |
| 1205 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1205 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1206 | 1206 | |
| 1207 | 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 | 1209 | if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest; |
| 1210 | 1210 | // AT_FDCWD is not fully supported before kernel 5.6: |
| 1211 | 1211 | // See https://lore.kernel.org/io-uring/20200207155039.12819-1-axboe@kernel.dk/T/ |
| ... | ... | @@ -1214,8 +1214,8 @@ test "openat" { |
| 1214 | 1214 | return error.SkipZigTest; |
| 1215 | 1215 | } |
| 1216 | 1216 | if (cqe_openat.res <= 0) std.debug.print("\ncqe_openat.res={}\n", .{cqe_openat.res}); |
| 1217 | testing.expect(cqe_openat.res > 0); | |
| 1218 | testing.expectEqual(@as(u32, 0), cqe_openat.flags); | |
| 1217 | try testing.expect(cqe_openat.res > 0); | |
| 1218 | try testing.expectEqual(@as(u32, 0), cqe_openat.flags); | |
| 1219 | 1219 | |
| 1220 | 1220 | os.close(cqe_openat.res); |
| 1221 | 1221 | } |
| ... | ... | @@ -1236,13 +1236,13 @@ test "close" { |
| 1236 | 1236 | defer std.fs.cwd().deleteFile(path) catch {}; |
| 1237 | 1237 | |
| 1238 | 1238 | const sqe_close = try ring.close(0x44444444, file.handle); |
| 1239 | testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode); | |
| 1240 | testing.expectEqual(file.handle, sqe_close.fd); | |
| 1241 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1239 | try testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode); | |
| 1240 | try testing.expectEqual(file.handle, sqe_close.fd); | |
| 1241 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1242 | 1242 | |
| 1243 | 1243 | const cqe_close = try ring.copy_cqe(); |
| 1244 | 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 | 1246 | .user_data = 0x44444444, |
| 1247 | 1247 | .res = 0, |
| 1248 | 1248 | .flags = 0, |
| ... | ... | @@ -1273,12 +1273,12 @@ test "accept/connect/send/recv" { |
| 1273 | 1273 | var accept_addr: os.sockaddr = undefined; |
| 1274 | 1274 | var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr)); |
| 1275 | 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()); | |
| 1277 | 1277 | |
| 1278 | 1278 | const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0); |
| 1279 | 1279 | defer os.close(client); |
| 1280 | 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()); | |
| 1282 | 1282 | |
| 1283 | 1283 | var cqe_accept = try ring.copy_cqe(); |
| 1284 | 1284 | if (cqe_accept.res == -linux.EINVAL) return error.SkipZigTest; |
| ... | ... | @@ -1293,11 +1293,11 @@ test "accept/connect/send/recv" { |
| 1293 | 1293 | cqe_connect = a; |
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data); | |
| 1296 | try testing.expectEqual(@as(u64, 0xaaaaaaaa), cqe_accept.user_data); | |
| 1297 | 1297 | if (cqe_accept.res <= 0) std.debug.print("\ncqe_accept.res={}\n", .{cqe_accept.res}); |
| 1298 | testing.expect(cqe_accept.res > 0); | |
| 1299 | testing.expectEqual(@as(u32, 0), cqe_accept.flags); | |
| 1300 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1298 | try testing.expect(cqe_accept.res > 0); | |
| 1299 | try testing.expectEqual(@as(u32, 0), cqe_accept.flags); | |
| 1300 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1301 | 1301 | .user_data = 0xcccccccc, |
| 1302 | 1302 | .res = 0, |
| 1303 | 1303 | .flags = 0, |
| ... | ... | @@ -1306,11 +1306,11 @@ test "accept/connect/send/recv" { |
| 1306 | 1306 | const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0); |
| 1307 | 1307 | send.flags |= linux.IOSQE_IO_LINK; |
| 1308 | 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()); | |
| 1310 | 1310 | |
| 1311 | 1311 | const cqe_send = try ring.copy_cqe(); |
| 1312 | 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 | 1314 | .user_data = 0xeeeeeeee, |
| 1315 | 1315 | .res = buffer_send.len, |
| 1316 | 1316 | .flags = 0, |
| ... | ... | @@ -1318,13 +1318,13 @@ test "accept/connect/send/recv" { |
| 1318 | 1318 | |
| 1319 | 1319 | const cqe_recv = try ring.copy_cqe(); |
| 1320 | 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 | 1322 | .user_data = 0xffffffff, |
| 1323 | 1323 | .res = buffer_recv.len, |
| 1324 | 1324 | .flags = 0, |
| 1325 | 1325 | }, cqe_recv); |
| 1326 | 1326 | |
| 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 | } |
| 1329 | 1329 | |
| 1330 | 1330 | test "timeout (after a relative time)" { |
| ... | ... | @@ -1343,12 +1343,12 @@ test "timeout (after a relative time)" { |
| 1343 | 1343 | |
| 1344 | 1344 | const started = std.time.milliTimestamp(); |
| 1345 | 1345 | const sqe = try ring.timeout(0x55555555, &ts, 0, 0); |
| 1346 | testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode); | |
| 1347 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1346 | try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe.opcode); | |
| 1347 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1348 | 1348 | const cqe = try ring.copy_cqe(); |
| 1349 | 1349 | const stopped = std.time.milliTimestamp(); |
| 1350 | 1350 | |
| 1351 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1351 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1352 | 1352 | .user_data = 0x55555555, |
| 1353 | 1353 | .res = -linux.ETIME, |
| 1354 | 1354 | .flags = 0, |
| ... | ... | @@ -1371,20 +1371,20 @@ test "timeout (after a number of completions)" { |
| 1371 | 1371 | const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; |
| 1372 | 1372 | const count_completions: u64 = 1; |
| 1373 | 1373 | const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0); |
| 1374 | testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); | |
| 1375 | testing.expectEqual(count_completions, sqe_timeout.off); | |
| 1374 | try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); | |
| 1375 | try testing.expectEqual(count_completions, sqe_timeout.off); | |
| 1376 | 1376 | _ = try ring.nop(0x77777777); |
| 1377 | testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1377 | try testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1378 | 1378 | |
| 1379 | 1379 | const cqe_nop = try ring.copy_cqe(); |
| 1380 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1380 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1381 | 1381 | .user_data = 0x77777777, |
| 1382 | 1382 | .res = 0, |
| 1383 | 1383 | .flags = 0, |
| 1384 | 1384 | }, cqe_nop); |
| 1385 | 1385 | |
| 1386 | 1386 | const cqe_timeout = try ring.copy_cqe(); |
| 1387 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1387 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1388 | 1388 | .user_data = 0x66666666, |
| 1389 | 1389 | .res = 0, |
| 1390 | 1390 | .flags = 0, |
| ... | ... | @@ -1403,15 +1403,15 @@ test "timeout_remove" { |
| 1403 | 1403 | |
| 1404 | 1404 | const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 }; |
| 1405 | 1405 | const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0); |
| 1406 | testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); | |
| 1407 | testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data); | |
| 1406 | try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode); | |
| 1407 | try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data); | |
| 1408 | 1408 | |
| 1409 | 1409 | const sqe_timeout_remove = try ring.timeout_remove(0x99999999, 0x88888888, 0); |
| 1410 | testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode); | |
| 1411 | testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr); | |
| 1412 | testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data); | |
| 1410 | try testing.expectEqual(linux.IORING_OP.TIMEOUT_REMOVE, sqe_timeout_remove.opcode); | |
| 1411 | try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout_remove.addr); | |
| 1412 | try testing.expectEqual(@as(u64, 0x99999999), sqe_timeout_remove.user_data); | |
| 1413 | 1413 | |
| 1414 | testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1414 | try testing.expectEqual(@as(u32, 2), try ring.submit()); | |
| 1415 | 1415 | |
| 1416 | 1416 | const cqe_timeout = try ring.copy_cqe(); |
| 1417 | 1417 | // IORING_OP_TIMEOUT_REMOVE is not supported by this kernel version: |
| ... | ... | @@ -1424,14 +1424,14 @@ test "timeout_remove" { |
| 1424 | 1424 | { |
| 1425 | 1425 | return error.SkipZigTest; |
| 1426 | 1426 | } |
| 1427 | testing.expectEqual(linux.io_uring_cqe{ | |
| 1427 | try testing.expectEqual(linux.io_uring_cqe{ | |
| 1428 | 1428 | .user_data = 0x88888888, |
| 1429 | 1429 | .res = -linux.ECANCELED, |
| 1430 | 1430 | .flags = 0, |
| 1431 | 1431 | }, cqe_timeout); |
| 1432 | 1432 | |
| 1433 | 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 | 1435 | .user_data = 0x99999999, |
| 1436 | 1436 | .res = 0, |
| 1437 | 1437 | .flags = 0, |
| ... | ... | @@ -1453,13 +1453,13 @@ test "fallocate" { |
| 1453 | 1453 | defer file.close(); |
| 1454 | 1454 | defer std.fs.cwd().deleteFile(path) catch {}; |
| 1455 | 1455 | |
| 1456 | testing.expectEqual(@as(u64, 0), (try file.stat()).size); | |
| 1456 | try testing.expectEqual(@as(u64, 0), (try file.stat()).size); | |
| 1457 | 1457 | |
| 1458 | 1458 | const len: u64 = 65536; |
| 1459 | 1459 | const sqe = try ring.fallocate(0xaaaaaaaa, file.handle, 0, 0, len); |
| 1460 | testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode); | |
| 1461 | testing.expectEqual(file.handle, sqe.fd); | |
| 1462 | testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1460 | try testing.expectEqual(linux.IORING_OP.FALLOCATE, sqe.opcode); | |
| 1461 | try testing.expectEqual(file.handle, sqe.fd); | |
| 1462 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | |
| 1463 | 1463 | |
| 1464 | 1464 | const cqe = try ring.copy_cqe(); |
| 1465 | 1465 | switch (-cqe.res) { |
| ... | ... | @@ -1473,11 +1473,11 @@ test "fallocate" { |
| 1473 | 1473 | linux.EOPNOTSUPP => return error.SkipZigTest, |
| 1474 | 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 | 1477 | .user_data = 0xaaaaaaaa, |
| 1478 | 1478 | .res = 0, |
| 1479 | 1479 | .flags = 0, |
| 1480 | 1480 | }, cqe); |
| 1481 | 1481 | |
| 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 | 18 | defer file.close(); |
| 19 | 19 | defer fs.cwd().deleteFile(path) catch {}; |
| 20 | 20 | |
| 21 | expect((try file.stat()).size == 0); | |
| 21 | try expect((try file.stat()).size == 0); | |
| 22 | 22 | |
| 23 | 23 | const len: u64 = 65536; |
| 24 | 24 | switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) { |
| ... | ... | @@ -28,20 +28,20 @@ test "fallocate" { |
| 28 | 28 | else => |errno| std.debug.panic("unhandled errno: {}", .{errno}), |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | expect((try file.stat()).size == len); | |
| 31 | try expect((try file.stat()).size == len); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "getpid" { |
| 35 | expect(linux.getpid() != 0); | |
| 35 | try expect(linux.getpid() != 0); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "timer" { |
| 39 | 39 | const epoll_fd = linux.epoll_create(); |
| 40 | 40 | var err: usize = linux.getErrno(epoll_fd); |
| 41 | expect(err == 0); | |
| 41 | try expect(err == 0); | |
| 42 | 42 | |
| 43 | 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); | |
| 45 | 45 | |
| 46 | 46 | const time_interval = linux.timespec{ |
| 47 | 47 | .tv_sec = 0, |
| ... | ... | @@ -54,7 +54,7 @@ test "timer" { |
| 54 | 54 | }; |
| 55 | 55 | |
| 56 | 56 | err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null); |
| 57 | expect(err == 0); | |
| 57 | try expect(err == 0); | |
| 58 | 58 | |
| 59 | 59 | var event = linux.epoll_event{ |
| 60 | 60 | .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, |
| ... | ... | @@ -62,7 +62,7 @@ test "timer" { |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | 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); | |
| 66 | 66 | |
| 67 | 67 | const events_one: linux.epoll_event = undefined; |
| 68 | 68 | var events = [_]linux.epoll_event{events_one} ** 8; |
| ... | ... | @@ -93,18 +93,18 @@ test "statx" { |
| 93 | 93 | else => unreachable, |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | expect(stat_buf.mode == statx_buf.mode); | |
| 97 | expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); | |
| 98 | expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); | |
| 99 | expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size); | |
| 100 | expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize); | |
| 101 | expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks); | |
| 96 | try expect(stat_buf.mode == statx_buf.mode); | |
| 97 | try expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid); | |
| 98 | try expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid); | |
| 99 | try expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size); | |
| 100 | try expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize); | |
| 101 | try expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | test "user and group ids" { |
| 105 | 105 | if (builtin.link_libc) return error.SkipZigTest; |
| 106 | expectEqual(linux.getauxval(elf.AT_UID), linux.getuid()); | |
| 107 | expectEqual(linux.getauxval(elf.AT_GID), linux.getgid()); | |
| 108 | expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid()); | |
| 109 | expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid()); | |
| 106 | try expectEqual(linux.getauxval(elf.AT_UID), linux.getuid()); | |
| 107 | try expectEqual(linux.getauxval(elf.AT_GID), linux.getgid()); | |
| 108 | try expectEqual(linux.getauxval(elf.AT_EUID), linux.geteuid()); | |
| 109 | try expectEqual(linux.getauxval(elf.AT_EGID), linux.getegid()); | |
| 110 | 110 | } |
lib/std/os/test.zig+51-51| ... | ... | @@ -37,7 +37,7 @@ test "chdir smoke test" { |
| 37 | 37 | try os.chdir(old_cwd); |
| 38 | 38 | var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 39 | 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 | 43 | // Next, change current working directory to one level above |
| ... | ... | @@ -47,7 +47,7 @@ test "chdir smoke test" { |
| 47 | 47 | defer os.chdir(old_cwd) catch unreachable; |
| 48 | 48 | var new_cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 49 | 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 | } |
| 53 | 53 | |
| ... | ... | @@ -79,7 +79,7 @@ test "open smoke test" { |
| 79 | 79 | |
| 80 | 80 | // Try this again with the same flags. This op should fail with error.PathAlreadyExists. |
| 81 | 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)); | |
| 83 | 83 | |
| 84 | 84 | // Try opening without `O_EXCL` flag. |
| 85 | 85 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" }); |
| ... | ... | @@ -88,7 +88,7 @@ test "open smoke test" { |
| 88 | 88 | |
| 89 | 89 | // Try opening as a directory which should fail. |
| 90 | 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)); | |
| 92 | 92 | |
| 93 | 93 | // Create some directory |
| 94 | 94 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" }); |
| ... | ... | @@ -101,7 +101,7 @@ test "open smoke test" { |
| 101 | 101 | |
| 102 | 102 | // Try opening as file which should fail. |
| 103 | 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 | } |
| 106 | 106 | |
| 107 | 107 | test "openat smoke test" { |
| ... | ... | @@ -120,14 +120,14 @@ test "openat smoke test" { |
| 120 | 120 | os.close(fd); |
| 121 | 121 | |
| 122 | 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)); | |
| 124 | 124 | |
| 125 | 125 | // Try opening without `O_EXCL` flag. |
| 126 | 126 | fd = try os.openat(tmp.dir.fd, "some_file", os.O_RDWR | os.O_CREAT, mode); |
| 127 | 127 | os.close(fd); |
| 128 | 128 | |
| 129 | 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)); | |
| 131 | 131 | |
| 132 | 132 | // Create some directory |
| 133 | 133 | try os.mkdirat(tmp.dir.fd, "some_dir", mode); |
| ... | ... | @@ -137,7 +137,7 @@ test "openat smoke test" { |
| 137 | 137 | os.close(fd); |
| 138 | 138 | |
| 139 | 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 | } |
| 142 | 142 | |
| 143 | 143 | test "symlink with relative paths" { |
| ... | ... | @@ -171,7 +171,7 @@ test "symlink with relative paths" { |
| 171 | 171 | |
| 172 | 172 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 173 | 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)); | |
| 175 | 175 | |
| 176 | 176 | try cwd.deleteFile("file.txt"); |
| 177 | 177 | try cwd.deleteFile("symlinked"); |
| ... | ... | @@ -188,7 +188,7 @@ test "readlink on Windows" { |
| 188 | 188 | fn testReadlink(target_path: []const u8, symlink_path: []const u8) !void { |
| 189 | 189 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 190 | 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 | } |
| 193 | 193 | |
| 194 | 194 | test "link with relative paths" { |
| ... | ... | @@ -211,15 +211,15 @@ test "link with relative paths" { |
| 211 | 211 | const estat = try os.fstat(efd.handle); |
| 212 | 212 | const nstat = try os.fstat(nfd.handle); |
| 213 | 213 | |
| 214 | testing.expectEqual(estat.ino, nstat.ino); | |
| 215 | testing.expectEqual(@as(usize, 2), nstat.nlink); | |
| 214 | try testing.expectEqual(estat.ino, nstat.ino); | |
| 215 | try testing.expectEqual(@as(usize, 2), nstat.nlink); | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | try os.unlink("new.txt"); |
| 219 | 219 | |
| 220 | 220 | { |
| 221 | 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 | } |
| 224 | 224 | |
| 225 | 225 | try cwd.deleteFile("example.txt"); |
| ... | ... | @@ -246,15 +246,15 @@ test "linkat with different directories" { |
| 246 | 246 | const estat = try os.fstat(efd.handle); |
| 247 | 247 | const nstat = try os.fstat(nfd.handle); |
| 248 | 248 | |
| 249 | testing.expectEqual(estat.ino, nstat.ino); | |
| 250 | testing.expectEqual(@as(usize, 2), nstat.nlink); | |
| 249 | try testing.expectEqual(estat.ino, nstat.ino); | |
| 250 | try testing.expectEqual(@as(usize, 2), nstat.nlink); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | try os.unlinkat(tmp.dir.fd, "new.txt", 0); |
| 254 | 254 | |
| 255 | 255 | { |
| 256 | 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 | } |
| 259 | 259 | |
| 260 | 260 | try cwd.deleteFile("example.txt"); |
| ... | ... | @@ -283,7 +283,7 @@ test "fstatat" { |
| 283 | 283 | // now repeat but using `fstatat` instead |
| 284 | 284 | const flags = if (builtin.os.tag == .wasi) 0x0 else os.AT_SYMLINK_NOFOLLOW; |
| 285 | 285 | const statat = try os.fstatat(tmp.dir.fd, "file.txt", flags); |
| 286 | expectEqual(stat, statat); | |
| 286 | try expectEqual(stat, statat); | |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | test "readlinkat" { |
| ... | ... | @@ -312,7 +312,7 @@ test "readlinkat" { |
| 312 | 312 | // read the link |
| 313 | 313 | var buffer: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 314 | 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 | } |
| 317 | 317 | |
| 318 | 318 | fn testThreadIdFn(thread_id: *Thread.Id) void { |
| ... | ... | @@ -327,13 +327,13 @@ test "std.Thread.getCurrentId" { |
| 327 | 327 | const thread_id = thread.handle(); |
| 328 | 328 | thread.wait(); |
| 329 | 329 | if (Thread.use_pthreads) { |
| 330 | expect(thread_current_id == thread_id); | |
| 330 | try expect(thread_current_id == thread_id); | |
| 331 | 331 | } else if (builtin.os.tag == .windows) { |
| 332 | expect(Thread.getCurrentId() != thread_current_id); | |
| 332 | try expect(Thread.getCurrentId() != thread_current_id); | |
| 333 | 333 | } else { |
| 334 | 334 | // If the thread completes very quickly, then thread_id can be 0. See the |
| 335 | 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 | } |
| 339 | 339 | |
| ... | ... | @@ -352,7 +352,7 @@ test "spawn threads" { |
| 352 | 352 | thread3.wait(); |
| 353 | 353 | thread4.wait(); |
| 354 | 354 | |
| 355 | expect(shared_ctx == 4); | |
| 355 | try expect(shared_ctx == 4); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | fn start1(ctx: void) u8 { |
| ... | ... | @@ -368,23 +368,23 @@ test "cpu count" { |
| 368 | 368 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 369 | 369 | |
| 370 | 370 | const cpu_count = try Thread.cpuCount(); |
| 371 | expect(cpu_count >= 1); | |
| 371 | try expect(cpu_count >= 1); | |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | test "thread local storage" { |
| 375 | 375 | if (builtin.single_threaded) return error.SkipZigTest; |
| 376 | 376 | const thread1 = try Thread.spawn(testTls, {}); |
| 377 | 377 | const thread2 = try Thread.spawn(testTls, {}); |
| 378 | testTls({}); | |
| 378 | try testTls({}); | |
| 379 | 379 | thread1.wait(); |
| 380 | 380 | thread2.wait(); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | threadlocal var x: i32 = 1234; |
| 384 | fn testTls(context: void) void { | |
| 385 | if (x != 1234) @panic("bad start value"); | |
| 384 | fn testTls(context: void) !void { | |
| 385 | if (x != 1234) return error.TlsBadStartValue; | |
| 386 | 386 | x += 1; |
| 387 | if (x != 1235) @panic("bad end value"); | |
| 387 | if (x != 1235) return error.TlsBadEndValue; | |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | test "getrandom" { |
| ... | ... | @@ -394,7 +394,7 @@ test "getrandom" { |
| 394 | 394 | try os.getrandom(&buf_b); |
| 395 | 395 | // If this test fails the chance is significantly higher that there is a bug than |
| 396 | 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 | } |
| 399 | 399 | |
| 400 | 400 | test "getcwd" { |
| ... | ... | @@ -413,7 +413,7 @@ test "sigaltstack" { |
| 413 | 413 | // Setting a stack size less than MINSIGSTKSZ returns ENOMEM |
| 414 | 414 | st.ss_flags = 0; |
| 415 | 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 | } |
| 418 | 418 | |
| 419 | 419 | // 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 | 464 | |
| 465 | 465 | var counter: usize = 0; |
| 466 | 466 | try os.dl_iterate_phdr(&counter, IterFnError, iter_fn); |
| 467 | expect(counter != 0); | |
| 467 | try expect(counter != 0); | |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | test "gethostname" { |
| ... | ... | @@ -473,7 +473,7 @@ test "gethostname" { |
| 473 | 473 | |
| 474 | 474 | var buf: [os.HOST_NAME_MAX]u8 = undefined; |
| 475 | 475 | const hostname = try os.gethostname(&buf); |
| 476 | expect(hostname.len != 0); | |
| 476 | try expect(hostname.len != 0); | |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | test "pipe" { |
| ... | ... | @@ -481,10 +481,10 @@ test "pipe" { |
| 481 | 481 | return error.SkipZigTest; |
| 482 | 482 | |
| 483 | 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 | 485 | var buf: [16]u8 = undefined; |
| 486 | expect((try os.read(fds[0], buf[0..])) == 5); | |
| 487 | testing.expectEqualSlices(u8, buf[0..5], "hello"); | |
| 486 | try expect((try os.read(fds[0], buf[0..])) == 5); | |
| 487 | try testing.expectEqualSlices(u8, buf[0..5], "hello"); | |
| 488 | 488 | os.close(fds[1]); |
| 489 | 489 | os.close(fds[0]); |
| 490 | 490 | } |
| ... | ... | @@ -503,13 +503,13 @@ test "memfd_create" { |
| 503 | 503 | else => |e| return e, |
| 504 | 504 | }; |
| 505 | 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 | 507 | try std.os.lseek_SET(fd, 0); |
| 508 | 508 | |
| 509 | 509 | var buf: [10]u8 = undefined; |
| 510 | 510 | const bytes_read = try std.os.read(fd, &buf); |
| 511 | expect(bytes_read == 4); | |
| 512 | expect(mem.eql(u8, buf[0..4], "test")); | |
| 511 | try expect(bytes_read == 4); | |
| 512 | try expect(mem.eql(u8, buf[0..4], "test")); | |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | test "mmap" { |
| ... | ... | @@ -531,14 +531,14 @@ test "mmap" { |
| 531 | 531 | ); |
| 532 | 532 | defer os.munmap(data); |
| 533 | 533 | |
| 534 | testing.expectEqual(@as(usize, 1234), data.len); | |
| 534 | try testing.expectEqual(@as(usize, 1234), data.len); | |
| 535 | 535 | |
| 536 | 536 | // 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)); | |
| 538 | 538 | |
| 539 | 539 | // Make sure the memory is writeable as requested |
| 540 | 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 | } |
| 543 | 543 | |
| 544 | 544 | const test_out_file = "os_tmp_test"; |
| ... | ... | @@ -578,7 +578,7 @@ test "mmap" { |
| 578 | 578 | |
| 579 | 579 | var i: u32 = 0; |
| 580 | 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 | } |
| 584 | 584 | |
| ... | ... | @@ -602,7 +602,7 @@ test "mmap" { |
| 602 | 602 | |
| 603 | 603 | var i: u32 = alloc_size / 2 / @sizeOf(u32); |
| 604 | 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 | } |
| 608 | 608 | |
| ... | ... | @@ -611,9 +611,9 @@ test "mmap" { |
| 611 | 611 | |
| 612 | 612 | test "getenv" { |
| 613 | 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 | 615 | } else { |
| 616 | expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null); | |
| 616 | try expect(os.getenvZ("BOGUSDOESNOTEXISTENVVAR") == null); | |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| ... | ... | @@ -635,17 +635,17 @@ test "fcntl" { |
| 635 | 635 | // Note: The test assumes createFile opens the file with O_CLOEXEC |
| 636 | 636 | { |
| 637 | 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 | 641 | _ = try os.fcntl(file.handle, os.F_SETFD, 0); |
| 642 | 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 | 646 | _ = try os.fcntl(file.handle, os.F_SETFD, os.FD_CLOEXEC); |
| 647 | 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 | } |
| 651 | 651 | |
| ... | ... | @@ -750,12 +750,12 @@ test "sigaction" { |
| 750 | 750 | os.sigaction(os.SIGUSR1, &sa, null); |
| 751 | 751 | // Check that we can read it back correctly. |
| 752 | 752 | os.sigaction(os.SIGUSR1, null, &old_sa); |
| 753 | testing.expectEqual(S.handler, old_sa.handler.sigaction.?); | |
| 754 | testing.expect((old_sa.flags & os.SA_SIGINFO) != 0); | |
| 753 | try testing.expectEqual(S.handler, old_sa.handler.sigaction.?); | |
| 754 | try testing.expect((old_sa.flags & os.SA_SIGINFO) != 0); | |
| 755 | 755 | // Invoke the handler. |
| 756 | 756 | try os.raise(os.SIGUSR1); |
| 757 | testing.expect(signal_test_failed == false); | |
| 757 | try testing.expect(signal_test_failed == false); | |
| 758 | 758 | // Check if the handler has been correctly reset to SIG_DFL |
| 759 | 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 | 997 | var result_path = try QueryObjectName(handle, &out_buffer); |
| 998 | 998 | const required_len_in_u16 = result_path.len + @divExact(@ptrToInt(result_path.ptr) - @ptrToInt(&out_buffer), 2) + 1; |
| 999 | 999 | //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 | 1001 | //exactly-sufficient size |
| 1002 | 1002 | _ = try QueryObjectName(handle, out_buffer[0..required_len_in_u16]); |
| 1003 | 1003 | } |
| ... | ... | @@ -1155,8 +1155,8 @@ test "GetFinalPathNameByHandle" { |
| 1155 | 1155 | |
| 1156 | 1156 | const required_len_in_u16 = nt_path.len + @divExact(@ptrToInt(nt_path.ptr) - @ptrToInt(&buffer), 2) + 1; |
| 1157 | 1157 | //check with insufficient size |
| 1158 | std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1])); | |
| 1159 | std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1])); | |
| 1158 | try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0 .. required_len_in_u16 - 1])); | |
| 1159 | try std.testing.expectError(error.NameTooLong, GetFinalPathNameByHandle(handle, .{ .volume_name = .Dos }, buffer[0 .. required_len_in_u16 - 1])); | |
| 1160 | 1160 | |
| 1161 | 1161 | //check with exactly-sufficient size |
| 1162 | 1162 | _ = try GetFinalPathNameByHandle(handle, .{ .volume_name = .Nt }, buffer[0..required_len_in_u16]); |
lib/std/packed_int_array.zig+49-49| ... | ... | @@ -353,7 +353,7 @@ test "PackedIntArray" { |
| 353 | 353 | |
| 354 | 354 | const PackedArray = PackedIntArray(I, int_count); |
| 355 | 355 | const expected_bytes = ((bits * int_count) + 7) / 8; |
| 356 | testing.expect(@sizeOf(PackedArray) == expected_bytes); | |
| 356 | try testing.expect(@sizeOf(PackedArray) == expected_bytes); | |
| 357 | 357 | |
| 358 | 358 | var data = @as(PackedArray, undefined); |
| 359 | 359 | |
| ... | ... | @@ -370,7 +370,7 @@ test "PackedIntArray" { |
| 370 | 370 | count = 0; |
| 371 | 371 | while (i < data.len()) : (i += 1) { |
| 372 | 372 | const val = data.get(i); |
| 373 | testing.expect(val == count); | |
| 373 | try testing.expect(val == count); | |
| 374 | 374 | if (bits > 0) count +%= 1; |
| 375 | 375 | } |
| 376 | 376 | } |
| ... | ... | @@ -427,7 +427,7 @@ test "PackedIntSlice" { |
| 427 | 427 | count = 0; |
| 428 | 428 | while (i < data.len()) : (i += 1) { |
| 429 | 429 | const val = data.get(i); |
| 430 | testing.expect(val == count); | |
| 430 | try testing.expect(val == count); | |
| 431 | 431 | if (bits > 0) count +%= 1; |
| 432 | 432 | } |
| 433 | 433 | } |
| ... | ... | @@ -454,48 +454,48 @@ test "PackedIntSlice of PackedInt(Array/Slice)" { |
| 454 | 454 | |
| 455 | 455 | //slice of array |
| 456 | 456 | var packed_slice = packed_array.slice(2, 5); |
| 457 | testing.expect(packed_slice.len() == 3); | |
| 457 | try testing.expect(packed_slice.len() == 3); | |
| 458 | 458 | const ps_bit_count = (bits * packed_slice.len()) + packed_slice.bit_offset; |
| 459 | 459 | const ps_expected_bytes = (ps_bit_count + 7) / 8; |
| 460 | testing.expect(packed_slice.bytes.len == ps_expected_bytes); | |
| 461 | testing.expect(packed_slice.get(0) == 2 % limit); | |
| 462 | testing.expect(packed_slice.get(1) == 3 % limit); | |
| 463 | testing.expect(packed_slice.get(2) == 4 % limit); | |
| 460 | try testing.expect(packed_slice.bytes.len == ps_expected_bytes); | |
| 461 | try testing.expect(packed_slice.get(0) == 2 % limit); | |
| 462 | try testing.expect(packed_slice.get(1) == 3 % limit); | |
| 463 | try testing.expect(packed_slice.get(2) == 4 % limit); | |
| 464 | 464 | packed_slice.set(1, 7 % limit); |
| 465 | testing.expect(packed_slice.get(1) == 7 % limit); | |
| 465 | try testing.expect(packed_slice.get(1) == 7 % limit); | |
| 466 | 466 | |
| 467 | 467 | //write through slice |
| 468 | testing.expect(packed_array.get(3) == 7 % limit); | |
| 468 | try testing.expect(packed_array.get(3) == 7 % limit); | |
| 469 | 469 | |
| 470 | 470 | //slice of a slice |
| 471 | 471 | const packed_slice_two = packed_slice.slice(0, 3); |
| 472 | testing.expect(packed_slice_two.len() == 3); | |
| 472 | try testing.expect(packed_slice_two.len() == 3); | |
| 473 | 473 | const ps2_bit_count = (bits * packed_slice_two.len()) + packed_slice_two.bit_offset; |
| 474 | 474 | const ps2_expected_bytes = (ps2_bit_count + 7) / 8; |
| 475 | testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes); | |
| 476 | testing.expect(packed_slice_two.get(1) == 7 % limit); | |
| 477 | testing.expect(packed_slice_two.get(2) == 4 % limit); | |
| 475 | try testing.expect(packed_slice_two.bytes.len == ps2_expected_bytes); | |
| 476 | try testing.expect(packed_slice_two.get(1) == 7 % limit); | |
| 477 | try testing.expect(packed_slice_two.get(2) == 4 % limit); | |
| 478 | 478 | |
| 479 | 479 | //size one case |
| 480 | 480 | const packed_slice_three = packed_slice_two.slice(1, 2); |
| 481 | testing.expect(packed_slice_three.len() == 1); | |
| 481 | try testing.expect(packed_slice_three.len() == 1); | |
| 482 | 482 | const ps3_bit_count = (bits * packed_slice_three.len()) + packed_slice_three.bit_offset; |
| 483 | 483 | const ps3_expected_bytes = (ps3_bit_count + 7) / 8; |
| 484 | testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes); | |
| 485 | testing.expect(packed_slice_three.get(0) == 7 % limit); | |
| 484 | try testing.expect(packed_slice_three.bytes.len == ps3_expected_bytes); | |
| 485 | try testing.expect(packed_slice_three.get(0) == 7 % limit); | |
| 486 | 486 | |
| 487 | 487 | //empty slice case |
| 488 | 488 | const packed_slice_empty = packed_slice.slice(0, 0); |
| 489 | testing.expect(packed_slice_empty.len() == 0); | |
| 490 | testing.expect(packed_slice_empty.bytes.len == 0); | |
| 489 | try testing.expect(packed_slice_empty.len() == 0); | |
| 490 | try testing.expect(packed_slice_empty.bytes.len == 0); | |
| 491 | 491 | |
| 492 | 492 | //slicing at byte boundaries |
| 493 | 493 | const packed_slice_edge = packed_array.slice(8, 16); |
| 494 | testing.expect(packed_slice_edge.len() == 8); | |
| 494 | try testing.expect(packed_slice_edge.len() == 8); | |
| 495 | 495 | const pse_bit_count = (bits * packed_slice_edge.len()) + packed_slice_edge.bit_offset; |
| 496 | 496 | const pse_expected_bytes = (pse_bit_count + 7) / 8; |
| 497 | testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes); | |
| 498 | testing.expect(packed_slice_edge.bit_offset == 0); | |
| 497 | try testing.expect(packed_slice_edge.bytes.len == pse_expected_bytes); | |
| 498 | try testing.expect(packed_slice_edge.bit_offset == 0); | |
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | |
| ... | ... | @@ -543,7 +543,7 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 543 | 543 | .Big => 0b01, |
| 544 | 544 | .Little => 0b10, |
| 545 | 545 | }; |
| 546 | testing.expect(packed_slice_cast_2.get(i) == val); | |
| 546 | try testing.expect(packed_slice_cast_2.get(i) == val); | |
| 547 | 547 | } |
| 548 | 548 | i = 0; |
| 549 | 549 | while (i < packed_slice_cast_4.len()) : (i += 1) { |
| ... | ... | @@ -551,12 +551,12 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 551 | 551 | .Big => 0b0101, |
| 552 | 552 | .Little => 0b1010, |
| 553 | 553 | }; |
| 554 | testing.expect(packed_slice_cast_4.get(i) == val); | |
| 554 | try testing.expect(packed_slice_cast_4.get(i) == val); | |
| 555 | 555 | } |
| 556 | 556 | i = 0; |
| 557 | 557 | while (i < packed_slice_cast_9.len()) : (i += 1) { |
| 558 | 558 | const val = 0b010101010; |
| 559 | testing.expect(packed_slice_cast_9.get(i) == val); | |
| 559 | try testing.expect(packed_slice_cast_9.get(i) == val); | |
| 560 | 560 | packed_slice_cast_9.set(i, 0b111000111); |
| 561 | 561 | } |
| 562 | 562 | i = 0; |
| ... | ... | @@ -565,7 +565,7 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 565 | 565 | .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 566 | 566 | .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 567 | 567 | }; |
| 568 | testing.expect(packed_slice_cast_3.get(i) == val); | |
| 568 | try testing.expect(packed_slice_cast_3.get(i) == val); | |
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
| ... | ... | @@ -575,58 +575,58 @@ test "PackedInt(Array/Slice)Endian" { |
| 575 | 575 | { |
| 576 | 576 | const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8); |
| 577 | 577 | var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 578 | testing.expect(packed_array_be.bytes[0] == 0b00000001); | |
| 579 | testing.expect(packed_array_be.bytes[1] == 0b00100011); | |
| 578 | try testing.expect(packed_array_be.bytes[0] == 0b00000001); | |
| 579 | try testing.expect(packed_array_be.bytes[1] == 0b00100011); | |
| 580 | 580 | |
| 581 | 581 | var i = @as(usize, 0); |
| 582 | 582 | while (i < packed_array_be.len()) : (i += 1) { |
| 583 | testing.expect(packed_array_be.get(i) == i); | |
| 583 | try testing.expect(packed_array_be.get(i) == i); | |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little); |
| 587 | 587 | i = 0; |
| 588 | 588 | while (i < packed_slice_le.len()) : (i += 1) { |
| 589 | 589 | const val = if (i % 2 == 0) i + 1 else i - 1; |
| 590 | testing.expect(packed_slice_le.get(i) == val); | |
| 590 | try testing.expect(packed_slice_le.get(i) == val); | |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little); |
| 594 | 594 | i = 0; |
| 595 | 595 | while (i < packed_slice_le_shift.len()) : (i += 1) { |
| 596 | 596 | const val = if (i % 2 == 0) i else i + 2; |
| 597 | testing.expect(packed_slice_le_shift.get(i) == val); | |
| 597 | try testing.expect(packed_slice_le_shift.get(i) == val); | |
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | { |
| 602 | 602 | const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8); |
| 603 | 603 | var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 604 | testing.expect(packed_array_be.bytes[0] == 0b00000000); | |
| 605 | testing.expect(packed_array_be.bytes[1] == 0b00000000); | |
| 606 | testing.expect(packed_array_be.bytes[2] == 0b00000100); | |
| 607 | testing.expect(packed_array_be.bytes[3] == 0b00000001); | |
| 608 | testing.expect(packed_array_be.bytes[4] == 0b00000000); | |
| 604 | try testing.expect(packed_array_be.bytes[0] == 0b00000000); | |
| 605 | try testing.expect(packed_array_be.bytes[1] == 0b00000000); | |
| 606 | try testing.expect(packed_array_be.bytes[2] == 0b00000100); | |
| 607 | try testing.expect(packed_array_be.bytes[3] == 0b00000001); | |
| 608 | try testing.expect(packed_array_be.bytes[4] == 0b00000000); | |
| 609 | 609 | |
| 610 | 610 | var i = @as(usize, 0); |
| 611 | 611 | while (i < packed_array_be.len()) : (i += 1) { |
| 612 | testing.expect(packed_array_be.get(i) == i); | |
| 612 | try testing.expect(packed_array_be.get(i) == i); | |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little); |
| 616 | testing.expect(packed_slice_le.get(0) == 0b00000000000); | |
| 617 | testing.expect(packed_slice_le.get(1) == 0b00010000000); | |
| 618 | testing.expect(packed_slice_le.get(2) == 0b00000000100); | |
| 619 | testing.expect(packed_slice_le.get(3) == 0b00000000000); | |
| 620 | testing.expect(packed_slice_le.get(4) == 0b00010000011); | |
| 621 | testing.expect(packed_slice_le.get(5) == 0b00000000010); | |
| 622 | testing.expect(packed_slice_le.get(6) == 0b10000010000); | |
| 623 | testing.expect(packed_slice_le.get(7) == 0b00000111001); | |
| 616 | try testing.expect(packed_slice_le.get(0) == 0b00000000000); | |
| 617 | try testing.expect(packed_slice_le.get(1) == 0b00010000000); | |
| 618 | try testing.expect(packed_slice_le.get(2) == 0b00000000100); | |
| 619 | try testing.expect(packed_slice_le.get(3) == 0b00000000000); | |
| 620 | try testing.expect(packed_slice_le.get(4) == 0b00010000011); | |
| 621 | try testing.expect(packed_slice_le.get(5) == 0b00000000010); | |
| 622 | try testing.expect(packed_slice_le.get(6) == 0b10000010000); | |
| 623 | try testing.expect(packed_slice_le.get(7) == 0b00000111001); | |
| 624 | 624 | |
| 625 | 625 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little); |
| 626 | testing.expect(packed_slice_le_shift.get(0) == 0b00010000000); | |
| 627 | testing.expect(packed_slice_le_shift.get(1) == 0b00000000100); | |
| 628 | testing.expect(packed_slice_le_shift.get(2) == 0b00000000000); | |
| 629 | testing.expect(packed_slice_le_shift.get(3) == 0b00010000011); | |
| 626 | try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000); | |
| 627 | try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100); | |
| 628 | try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000); | |
| 629 | try testing.expect(packed_slice_le_shift.get(3) == 0b00010000011); | |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 |
lib/std/priority_dequeue.zig+89-89| ... | ... | @@ -482,12 +482,12 @@ test "std.PriorityDequeue: add and remove min" { |
| 482 | 482 | try queue.add(25); |
| 483 | 483 | try queue.add(13); |
| 484 | 484 | |
| 485 | expectEqual(@as(u32, 7), queue.removeMin()); | |
| 486 | expectEqual(@as(u32, 12), queue.removeMin()); | |
| 487 | expectEqual(@as(u32, 13), queue.removeMin()); | |
| 488 | expectEqual(@as(u32, 23), queue.removeMin()); | |
| 489 | expectEqual(@as(u32, 25), queue.removeMin()); | |
| 490 | expectEqual(@as(u32, 54), queue.removeMin()); | |
| 485 | try expectEqual(@as(u32, 7), queue.removeMin()); | |
| 486 | try expectEqual(@as(u32, 12), queue.removeMin()); | |
| 487 | try expectEqual(@as(u32, 13), queue.removeMin()); | |
| 488 | try expectEqual(@as(u32, 23), queue.removeMin()); | |
| 489 | try expectEqual(@as(u32, 25), queue.removeMin()); | |
| 490 | try expectEqual(@as(u32, 54), queue.removeMin()); | |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | test "std.PriorityDequeue: add and remove min structs" { |
| ... | ... | @@ -508,12 +508,12 @@ test "std.PriorityDequeue: add and remove min structs" { |
| 508 | 508 | try queue.add(.{ .size = 25 }); |
| 509 | 509 | try queue.add(.{ .size = 13 }); |
| 510 | 510 | |
| 511 | expectEqual(@as(u32, 7), queue.removeMin().size); | |
| 512 | expectEqual(@as(u32, 12), queue.removeMin().size); | |
| 513 | expectEqual(@as(u32, 13), queue.removeMin().size); | |
| 514 | expectEqual(@as(u32, 23), queue.removeMin().size); | |
| 515 | expectEqual(@as(u32, 25), queue.removeMin().size); | |
| 516 | expectEqual(@as(u32, 54), queue.removeMin().size); | |
| 511 | try expectEqual(@as(u32, 7), queue.removeMin().size); | |
| 512 | try expectEqual(@as(u32, 12), queue.removeMin().size); | |
| 513 | try expectEqual(@as(u32, 13), queue.removeMin().size); | |
| 514 | try expectEqual(@as(u32, 23), queue.removeMin().size); | |
| 515 | try expectEqual(@as(u32, 25), queue.removeMin().size); | |
| 516 | try expectEqual(@as(u32, 54), queue.removeMin().size); | |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | test "std.PriorityDequeue: add and remove max" { |
| ... | ... | @@ -527,12 +527,12 @@ test "std.PriorityDequeue: add and remove max" { |
| 527 | 527 | try queue.add(25); |
| 528 | 528 | try queue.add(13); |
| 529 | 529 | |
| 530 | expectEqual(@as(u32, 54), queue.removeMax()); | |
| 531 | expectEqual(@as(u32, 25), queue.removeMax()); | |
| 532 | expectEqual(@as(u32, 23), queue.removeMax()); | |
| 533 | expectEqual(@as(u32, 13), queue.removeMax()); | |
| 534 | expectEqual(@as(u32, 12), queue.removeMax()); | |
| 535 | expectEqual(@as(u32, 7), queue.removeMax()); | |
| 530 | try expectEqual(@as(u32, 54), queue.removeMax()); | |
| 531 | try expectEqual(@as(u32, 25), queue.removeMax()); | |
| 532 | try expectEqual(@as(u32, 23), queue.removeMax()); | |
| 533 | try expectEqual(@as(u32, 13), queue.removeMax()); | |
| 534 | try expectEqual(@as(u32, 12), queue.removeMax()); | |
| 535 | try expectEqual(@as(u32, 7), queue.removeMax()); | |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | test "std.PriorityDequeue: add and remove same min" { |
| ... | ... | @@ -546,12 +546,12 @@ test "std.PriorityDequeue: add and remove same min" { |
| 546 | 546 | try queue.add(1); |
| 547 | 547 | try queue.add(1); |
| 548 | 548 | |
| 549 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 550 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 551 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 552 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 553 | expectEqual(@as(u32, 2), queue.removeMin()); | |
| 554 | expectEqual(@as(u32, 2), queue.removeMin()); | |
| 549 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 550 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 551 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 552 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 553 | try expectEqual(@as(u32, 2), queue.removeMin()); | |
| 554 | try expectEqual(@as(u32, 2), queue.removeMin()); | |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | test "std.PriorityDequeue: add and remove same max" { |
| ... | ... | @@ -565,20 +565,20 @@ test "std.PriorityDequeue: add and remove same max" { |
| 565 | 565 | try queue.add(1); |
| 566 | 566 | try queue.add(1); |
| 567 | 567 | |
| 568 | expectEqual(@as(u32, 2), queue.removeMax()); | |
| 569 | expectEqual(@as(u32, 2), queue.removeMax()); | |
| 570 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 571 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 572 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 573 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 568 | try expectEqual(@as(u32, 2), queue.removeMax()); | |
| 569 | try expectEqual(@as(u32, 2), queue.removeMax()); | |
| 570 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 571 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 572 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 573 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | test "std.PriorityDequeue: removeOrNull empty" { |
| 577 | 577 | var queue = PDQ.init(testing.allocator, lessThanComparison); |
| 578 | 578 | defer queue.deinit(); |
| 579 | 579 | |
| 580 | expect(queue.removeMinOrNull() == null); | |
| 581 | expect(queue.removeMaxOrNull() == null); | |
| 580 | try expect(queue.removeMinOrNull() == null); | |
| 581 | try expect(queue.removeMaxOrNull() == null); | |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | test "std.PriorityDequeue: edge case 3 elements" { |
| ... | ... | @@ -589,9 +589,9 @@ test "std.PriorityDequeue: edge case 3 elements" { |
| 589 | 589 | try queue.add(3); |
| 590 | 590 | try queue.add(2); |
| 591 | 591 | |
| 592 | expectEqual(@as(u32, 2), queue.removeMin()); | |
| 593 | expectEqual(@as(u32, 3), queue.removeMin()); | |
| 594 | expectEqual(@as(u32, 9), queue.removeMin()); | |
| 592 | try expectEqual(@as(u32, 2), queue.removeMin()); | |
| 593 | try expectEqual(@as(u32, 3), queue.removeMin()); | |
| 594 | try expectEqual(@as(u32, 9), queue.removeMin()); | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | test "std.PriorityDequeue: edge case 3 elements max" { |
| ... | ... | @@ -602,37 +602,37 @@ test "std.PriorityDequeue: edge case 3 elements max" { |
| 602 | 602 | try queue.add(3); |
| 603 | 603 | try queue.add(2); |
| 604 | 604 | |
| 605 | expectEqual(@as(u32, 9), queue.removeMax()); | |
| 606 | expectEqual(@as(u32, 3), queue.removeMax()); | |
| 607 | expectEqual(@as(u32, 2), queue.removeMax()); | |
| 605 | try expectEqual(@as(u32, 9), queue.removeMax()); | |
| 606 | try expectEqual(@as(u32, 3), queue.removeMax()); | |
| 607 | try expectEqual(@as(u32, 2), queue.removeMax()); | |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | test "std.PriorityDequeue: peekMin" { |
| 611 | 611 | var queue = PDQ.init(testing.allocator, lessThanComparison); |
| 612 | 612 | defer queue.deinit(); |
| 613 | 613 | |
| 614 | expect(queue.peekMin() == null); | |
| 614 | try expect(queue.peekMin() == null); | |
| 615 | 615 | |
| 616 | 616 | try queue.add(9); |
| 617 | 617 | try queue.add(3); |
| 618 | 618 | try queue.add(2); |
| 619 | 619 | |
| 620 | expect(queue.peekMin().? == 2); | |
| 621 | expect(queue.peekMin().? == 2); | |
| 620 | try expect(queue.peekMin().? == 2); | |
| 621 | try expect(queue.peekMin().? == 2); | |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | test "std.PriorityDequeue: peekMax" { |
| 625 | 625 | var queue = PDQ.init(testing.allocator, lessThanComparison); |
| 626 | 626 | defer queue.deinit(); |
| 627 | 627 | |
| 628 | expect(queue.peekMin() == null); | |
| 628 | try expect(queue.peekMin() == null); | |
| 629 | 629 | |
| 630 | 630 | try queue.add(9); |
| 631 | 631 | try queue.add(3); |
| 632 | 632 | try queue.add(2); |
| 633 | 633 | |
| 634 | expect(queue.peekMax().? == 9); | |
| 635 | expect(queue.peekMax().? == 9); | |
| 634 | try expect(queue.peekMax().? == 9); | |
| 635 | try expect(queue.peekMax().? == 9); | |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | test "std.PriorityDequeue: sift up with odd indices" { |
| ... | ... | @@ -645,7 +645,7 @@ test "std.PriorityDequeue: sift up with odd indices" { |
| 645 | 645 | |
| 646 | 646 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 647 | 647 | for (sorted_items) |e| { |
| 648 | expectEqual(e, queue.removeMin()); | |
| 648 | try expectEqual(e, queue.removeMin()); | |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| ... | ... | @@ -659,7 +659,7 @@ test "std.PriorityDequeue: sift up with odd indices" { |
| 659 | 659 | |
| 660 | 660 | const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 }; |
| 661 | 661 | for (sorted_items) |e| { |
| 662 | expectEqual(e, queue.removeMax()); | |
| 662 | try expectEqual(e, queue.removeMax()); | |
| 663 | 663 | } |
| 664 | 664 | } |
| 665 | 665 | |
| ... | ... | @@ -671,7 +671,7 @@ test "std.PriorityDequeue: addSlice min" { |
| 671 | 671 | |
| 672 | 672 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 673 | 673 | for (sorted_items) |e| { |
| 674 | expectEqual(e, queue.removeMin()); | |
| 674 | try expectEqual(e, queue.removeMin()); | |
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | |
| ... | ... | @@ -683,7 +683,7 @@ test "std.PriorityDequeue: addSlice max" { |
| 683 | 683 | |
| 684 | 684 | const sorted_items = [_]u32{ 25, 24, 24, 22, 21, 16, 15, 15, 14, 13, 12, 11, 7, 7, 6, 5, 2, 1 }; |
| 685 | 685 | for (sorted_items) |e| { |
| 686 | expectEqual(e, queue.removeMax()); | |
| 686 | try expectEqual(e, queue.removeMax()); | |
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
| ... | ... | @@ -692,8 +692,8 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 0" { |
| 692 | 692 | const queue_items = try testing.allocator.dupe(u32, &items); |
| 693 | 693 | var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]); |
| 694 | 694 | defer queue.deinit(); |
| 695 | expectEqual(@as(usize, 0), queue.len); | |
| 696 | expect(queue.removeMinOrNull() == null); | |
| 695 | try expectEqual(@as(usize, 0), queue.len); | |
| 696 | try expect(queue.removeMinOrNull() == null); | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | test "std.PriorityDequeue: fromOwnedSlice trivial case 1" { |
| ... | ... | @@ -702,9 +702,9 @@ test "std.PriorityDequeue: fromOwnedSlice trivial case 1" { |
| 702 | 702 | var queue = PDQ.fromOwnedSlice(testing.allocator, lessThanComparison, queue_items[0..]); |
| 703 | 703 | defer queue.deinit(); |
| 704 | 704 | |
| 705 | expectEqual(@as(usize, 1), queue.len); | |
| 706 | expectEqual(items[0], queue.removeMin()); | |
| 707 | expect(queue.removeMinOrNull() == null); | |
| 705 | try expectEqual(@as(usize, 1), queue.len); | |
| 706 | try expectEqual(items[0], queue.removeMin()); | |
| 707 | try expect(queue.removeMinOrNull() == null); | |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | test "std.PriorityDequeue: fromOwnedSlice" { |
| ... | ... | @@ -715,7 +715,7 @@ test "std.PriorityDequeue: fromOwnedSlice" { |
| 715 | 715 | |
| 716 | 716 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 717 | 717 | for (sorted_items) |e| { |
| 718 | expectEqual(e, queue.removeMin()); | |
| 718 | try expectEqual(e, queue.removeMin()); | |
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | |
| ... | ... | @@ -729,9 +729,9 @@ test "std.PriorityDequeue: update min queue" { |
| 729 | 729 | try queue.update(55, 5); |
| 730 | 730 | try queue.update(44, 4); |
| 731 | 731 | try queue.update(11, 1); |
| 732 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 733 | expectEqual(@as(u32, 4), queue.removeMin()); | |
| 734 | expectEqual(@as(u32, 5), queue.removeMin()); | |
| 732 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 733 | try expectEqual(@as(u32, 4), queue.removeMin()); | |
| 734 | try expectEqual(@as(u32, 5), queue.removeMin()); | |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | test "std.PriorityDequeue: update same min queue" { |
| ... | ... | @@ -744,10 +744,10 @@ test "std.PriorityDequeue: update same min queue" { |
| 744 | 744 | try queue.add(2); |
| 745 | 745 | try queue.update(1, 5); |
| 746 | 746 | try queue.update(2, 4); |
| 747 | expectEqual(@as(u32, 1), queue.removeMin()); | |
| 748 | expectEqual(@as(u32, 2), queue.removeMin()); | |
| 749 | expectEqual(@as(u32, 4), queue.removeMin()); | |
| 750 | expectEqual(@as(u32, 5), queue.removeMin()); | |
| 747 | try expectEqual(@as(u32, 1), queue.removeMin()); | |
| 748 | try expectEqual(@as(u32, 2), queue.removeMin()); | |
| 749 | try expectEqual(@as(u32, 4), queue.removeMin()); | |
| 750 | try expectEqual(@as(u32, 5), queue.removeMin()); | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | test "std.PriorityDequeue: update max queue" { |
| ... | ... | @@ -761,9 +761,9 @@ test "std.PriorityDequeue: update max queue" { |
| 761 | 761 | try queue.update(44, 1); |
| 762 | 762 | try queue.update(11, 4); |
| 763 | 763 | |
| 764 | expectEqual(@as(u32, 5), queue.removeMax()); | |
| 765 | expectEqual(@as(u32, 4), queue.removeMax()); | |
| 766 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 764 | try expectEqual(@as(u32, 5), queue.removeMax()); | |
| 765 | try expectEqual(@as(u32, 4), queue.removeMax()); | |
| 766 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | test "std.PriorityDequeue: update same max queue" { |
| ... | ... | @@ -776,10 +776,10 @@ test "std.PriorityDequeue: update same max queue" { |
| 776 | 776 | try queue.add(2); |
| 777 | 777 | try queue.update(1, 5); |
| 778 | 778 | try queue.update(2, 4); |
| 779 | expectEqual(@as(u32, 5), queue.removeMax()); | |
| 780 | expectEqual(@as(u32, 4), queue.removeMax()); | |
| 781 | expectEqual(@as(u32, 2), queue.removeMax()); | |
| 782 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 779 | try expectEqual(@as(u32, 5), queue.removeMax()); | |
| 780 | try expectEqual(@as(u32, 4), queue.removeMax()); | |
| 781 | try expectEqual(@as(u32, 2), queue.removeMax()); | |
| 782 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | test "std.PriorityDequeue: iterator" { |
| ... | ... | @@ -801,7 +801,7 @@ test "std.PriorityDequeue: iterator" { |
| 801 | 801 | _ = map.remove(e); |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | expectEqual(@as(usize, 0), map.count()); | |
| 804 | try expectEqual(@as(usize, 0), map.count()); | |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | test "std.PriorityDequeue: remove at index" { |
| ... | ... | @@ -821,10 +821,10 @@ test "std.PriorityDequeue: remove at index" { |
| 821 | 821 | idx += 1; |
| 822 | 822 | } else unreachable; |
| 823 | 823 | |
| 824 | expectEqual(queue.removeIndex(two_idx), 2); | |
| 825 | expectEqual(queue.removeMin(), 1); | |
| 826 | expectEqual(queue.removeMin(), 3); | |
| 827 | expectEqual(queue.removeMinOrNull(), null); | |
| 824 | try expectEqual(queue.removeIndex(two_idx), 2); | |
| 825 | try expectEqual(queue.removeMin(), 1); | |
| 826 | try expectEqual(queue.removeMin(), 3); | |
| 827 | try expectEqual(queue.removeMinOrNull(), null); | |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | test "std.PriorityDequeue: iterator while empty" { |
| ... | ... | @@ -833,7 +833,7 @@ test "std.PriorityDequeue: iterator while empty" { |
| 833 | 833 | |
| 834 | 834 | var it = queue.iterator(); |
| 835 | 835 | |
| 836 | expectEqual(it.next(), null); | |
| 836 | try expectEqual(it.next(), null); | |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" { |
| ... | ... | @@ -841,26 +841,26 @@ test "std.PriorityDequeue: shrinkRetainingCapacity and shrinkAndFree" { |
| 841 | 841 | defer queue.deinit(); |
| 842 | 842 | |
| 843 | 843 | try queue.ensureCapacity(4); |
| 844 | expect(queue.capacity() >= 4); | |
| 844 | try expect(queue.capacity() >= 4); | |
| 845 | 845 | |
| 846 | 846 | try queue.add(1); |
| 847 | 847 | try queue.add(2); |
| 848 | 848 | try queue.add(3); |
| 849 | expect(queue.capacity() >= 4); | |
| 850 | expectEqual(@as(usize, 3), queue.len); | |
| 849 | try expect(queue.capacity() >= 4); | |
| 850 | try expectEqual(@as(usize, 3), queue.len); | |
| 851 | 851 | |
| 852 | 852 | queue.shrinkRetainingCapacity(3); |
| 853 | expect(queue.capacity() >= 4); | |
| 854 | expectEqual(@as(usize, 3), queue.len); | |
| 853 | try expect(queue.capacity() >= 4); | |
| 854 | try expectEqual(@as(usize, 3), queue.len); | |
| 855 | 855 | |
| 856 | 856 | queue.shrinkAndFree(3); |
| 857 | expectEqual(@as(usize, 3), queue.capacity()); | |
| 858 | expectEqual(@as(usize, 3), queue.len); | |
| 857 | try expectEqual(@as(usize, 3), queue.capacity()); | |
| 858 | try expectEqual(@as(usize, 3), queue.len); | |
| 859 | 859 | |
| 860 | expectEqual(@as(u32, 3), queue.removeMax()); | |
| 861 | expectEqual(@as(u32, 2), queue.removeMax()); | |
| 862 | expectEqual(@as(u32, 1), queue.removeMax()); | |
| 863 | expect(queue.removeMaxOrNull() == null); | |
| 860 | try expectEqual(@as(u32, 3), queue.removeMax()); | |
| 861 | try expectEqual(@as(u32, 2), queue.removeMax()); | |
| 862 | try expectEqual(@as(u32, 1), queue.removeMax()); | |
| 863 | try expect(queue.removeMaxOrNull() == null); | |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | test "std.PriorityDequeue: fuzz testing min" { |
| ... | ... | @@ -885,7 +885,7 @@ fn fuzzTestMin(rng: *std.rand.Random, comptime queue_size: usize) !void { |
| 885 | 885 | var last_removed: ?u32 = null; |
| 886 | 886 | while (queue.removeMinOrNull()) |next| { |
| 887 | 887 | if (last_removed) |last| { |
| 888 | expect(last <= next); | |
| 888 | try expect(last <= next); | |
| 889 | 889 | } |
| 890 | 890 | last_removed = next; |
| 891 | 891 | } |
| ... | ... | @@ -913,7 +913,7 @@ fn fuzzTestMax(rng: *std.rand.Random, queue_size: usize) !void { |
| 913 | 913 | var last_removed: ?u32 = null; |
| 914 | 914 | while (queue.removeMaxOrNull()) |next| { |
| 915 | 915 | if (last_removed) |last| { |
| 916 | expect(last >= next); | |
| 916 | try expect(last >= next); | |
| 917 | 917 | } |
| 918 | 918 | last_removed = next; |
| 919 | 919 | } |
| ... | ... | @@ -945,13 +945,13 @@ fn fuzzTestMinMax(rng: *std.rand.Random, queue_size: usize) !void { |
| 945 | 945 | if (i % 2 == 0) { |
| 946 | 946 | const next = queue.removeMin(); |
| 947 | 947 | if (last_min) |last| { |
| 948 | expect(last <= next); | |
| 948 | try expect(last <= next); | |
| 949 | 949 | } |
| 950 | 950 | last_min = next; |
| 951 | 951 | } else { |
| 952 | 952 | const next = queue.removeMax(); |
| 953 | 953 | if (last_max) |last| { |
| 954 | expect(last >= next); | |
| 954 | try expect(last >= next); | |
| 955 | 955 | } |
| 956 | 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 | 290 | try queue.add(23); |
| 291 | 291 | try queue.add(25); |
| 292 | 292 | try queue.add(13); |
| 293 | expectEqual(@as(u32, 7), queue.remove()); | |
| 294 | expectEqual(@as(u32, 12), queue.remove()); | |
| 295 | expectEqual(@as(u32, 13), queue.remove()); | |
| 296 | expectEqual(@as(u32, 23), queue.remove()); | |
| 297 | expectEqual(@as(u32, 25), queue.remove()); | |
| 298 | expectEqual(@as(u32, 54), queue.remove()); | |
| 293 | try expectEqual(@as(u32, 7), queue.remove()); | |
| 294 | try expectEqual(@as(u32, 12), queue.remove()); | |
| 295 | try expectEqual(@as(u32, 13), queue.remove()); | |
| 296 | try expectEqual(@as(u32, 23), queue.remove()); | |
| 297 | try expectEqual(@as(u32, 25), queue.remove()); | |
| 298 | try expectEqual(@as(u32, 54), queue.remove()); | |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | test "std.PriorityQueue: add and remove same min heap" { |
| ... | ... | @@ -308,19 +308,19 @@ test "std.PriorityQueue: add and remove same min heap" { |
| 308 | 308 | try queue.add(2); |
| 309 | 309 | try queue.add(1); |
| 310 | 310 | try queue.add(1); |
| 311 | expectEqual(@as(u32, 1), queue.remove()); | |
| 312 | expectEqual(@as(u32, 1), queue.remove()); | |
| 313 | expectEqual(@as(u32, 1), queue.remove()); | |
| 314 | expectEqual(@as(u32, 1), queue.remove()); | |
| 315 | expectEqual(@as(u32, 2), queue.remove()); | |
| 316 | expectEqual(@as(u32, 2), queue.remove()); | |
| 311 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 312 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 313 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 314 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 315 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 316 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | test "std.PriorityQueue: removeOrNull on empty" { |
| 320 | 320 | var queue = PQ.init(testing.allocator, lessThan); |
| 321 | 321 | defer queue.deinit(); |
| 322 | 322 | |
| 323 | expect(queue.removeOrNull() == null); | |
| 323 | try expect(queue.removeOrNull() == null); | |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | test "std.PriorityQueue: edge case 3 elements" { |
| ... | ... | @@ -330,21 +330,21 @@ test "std.PriorityQueue: edge case 3 elements" { |
| 330 | 330 | try queue.add(9); |
| 331 | 331 | try queue.add(3); |
| 332 | 332 | try queue.add(2); |
| 333 | expectEqual(@as(u32, 2), queue.remove()); | |
| 334 | expectEqual(@as(u32, 3), queue.remove()); | |
| 335 | expectEqual(@as(u32, 9), queue.remove()); | |
| 333 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 334 | try expectEqual(@as(u32, 3), queue.remove()); | |
| 335 | try expectEqual(@as(u32, 9), queue.remove()); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | test "std.PriorityQueue: peek" { |
| 339 | 339 | var queue = PQ.init(testing.allocator, lessThan); |
| 340 | 340 | defer queue.deinit(); |
| 341 | 341 | |
| 342 | expect(queue.peek() == null); | |
| 342 | try expect(queue.peek() == null); | |
| 343 | 343 | try queue.add(9); |
| 344 | 344 | try queue.add(3); |
| 345 | 345 | try queue.add(2); |
| 346 | expectEqual(@as(u32, 2), queue.peek().?); | |
| 347 | expectEqual(@as(u32, 2), queue.peek().?); | |
| 346 | try expectEqual(@as(u32, 2), queue.peek().?); | |
| 347 | try expectEqual(@as(u32, 2), queue.peek().?); | |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | test "std.PriorityQueue: sift up with odd indices" { |
| ... | ... | @@ -357,7 +357,7 @@ test "std.PriorityQueue: sift up with odd indices" { |
| 357 | 357 | |
| 358 | 358 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 359 | 359 | for (sorted_items) |e| { |
| 360 | expectEqual(e, queue.remove()); | |
| 360 | try expectEqual(e, queue.remove()); | |
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | |
| ... | ... | @@ -369,7 +369,7 @@ test "std.PriorityQueue: addSlice" { |
| 369 | 369 | |
| 370 | 370 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 371 | 371 | for (sorted_items) |e| { |
| 372 | expectEqual(e, queue.remove()); | |
| 372 | try expectEqual(e, queue.remove()); | |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| ... | ... | @@ -378,8 +378,8 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 0" { |
| 378 | 378 | const queue_items = try testing.allocator.dupe(u32, &items); |
| 379 | 379 | var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]); |
| 380 | 380 | defer queue.deinit(); |
| 381 | expectEqual(@as(usize, 0), queue.len); | |
| 382 | expect(queue.removeOrNull() == null); | |
| 381 | try expectEqual(@as(usize, 0), queue.len); | |
| 382 | try expect(queue.removeOrNull() == null); | |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | test "std.PriorityQueue: fromOwnedSlice trivial case 1" { |
| ... | ... | @@ -388,9 +388,9 @@ test "std.PriorityQueue: fromOwnedSlice trivial case 1" { |
| 388 | 388 | var queue = PQ.fromOwnedSlice(testing.allocator, lessThan, queue_items[0..]); |
| 389 | 389 | defer queue.deinit(); |
| 390 | 390 | |
| 391 | expectEqual(@as(usize, 1), queue.len); | |
| 392 | expectEqual(items[0], queue.remove()); | |
| 393 | expect(queue.removeOrNull() == null); | |
| 391 | try expectEqual(@as(usize, 1), queue.len); | |
| 392 | try expectEqual(items[0], queue.remove()); | |
| 393 | try expect(queue.removeOrNull() == null); | |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | test "std.PriorityQueue: fromOwnedSlice" { |
| ... | ... | @@ -401,7 +401,7 @@ test "std.PriorityQueue: fromOwnedSlice" { |
| 401 | 401 | |
| 402 | 402 | const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 }; |
| 403 | 403 | for (sorted_items) |e| { |
| 404 | expectEqual(e, queue.remove()); | |
| 404 | try expectEqual(e, queue.remove()); | |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| ... | ... | @@ -415,12 +415,12 @@ test "std.PriorityQueue: add and remove max heap" { |
| 415 | 415 | try queue.add(23); |
| 416 | 416 | try queue.add(25); |
| 417 | 417 | try queue.add(13); |
| 418 | expectEqual(@as(u32, 54), queue.remove()); | |
| 419 | expectEqual(@as(u32, 25), queue.remove()); | |
| 420 | expectEqual(@as(u32, 23), queue.remove()); | |
| 421 | expectEqual(@as(u32, 13), queue.remove()); | |
| 422 | expectEqual(@as(u32, 12), queue.remove()); | |
| 423 | expectEqual(@as(u32, 7), queue.remove()); | |
| 418 | try expectEqual(@as(u32, 54), queue.remove()); | |
| 419 | try expectEqual(@as(u32, 25), queue.remove()); | |
| 420 | try expectEqual(@as(u32, 23), queue.remove()); | |
| 421 | try expectEqual(@as(u32, 13), queue.remove()); | |
| 422 | try expectEqual(@as(u32, 12), queue.remove()); | |
| 423 | try expectEqual(@as(u32, 7), queue.remove()); | |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | test "std.PriorityQueue: add and remove same max heap" { |
| ... | ... | @@ -433,12 +433,12 @@ test "std.PriorityQueue: add and remove same max heap" { |
| 433 | 433 | try queue.add(2); |
| 434 | 434 | try queue.add(1); |
| 435 | 435 | try queue.add(1); |
| 436 | expectEqual(@as(u32, 2), queue.remove()); | |
| 437 | expectEqual(@as(u32, 2), queue.remove()); | |
| 438 | expectEqual(@as(u32, 1), queue.remove()); | |
| 439 | expectEqual(@as(u32, 1), queue.remove()); | |
| 440 | expectEqual(@as(u32, 1), queue.remove()); | |
| 441 | expectEqual(@as(u32, 1), queue.remove()); | |
| 436 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 437 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 438 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 439 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 440 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 441 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | test "std.PriorityQueue: iterator" { |
| ... | ... | @@ -460,7 +460,7 @@ test "std.PriorityQueue: iterator" { |
| 460 | 460 | _ = map.remove(e); |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | expectEqual(@as(usize, 0), map.count()); | |
| 463 | try expectEqual(@as(usize, 0), map.count()); | |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | test "std.PriorityQueue: remove at index" { |
| ... | ... | @@ -480,10 +480,10 @@ test "std.PriorityQueue: remove at index" { |
| 480 | 480 | idx += 1; |
| 481 | 481 | } else unreachable; |
| 482 | 482 | |
| 483 | expectEqual(queue.removeIndex(two_idx), 2); | |
| 484 | expectEqual(queue.remove(), 1); | |
| 485 | expectEqual(queue.remove(), 3); | |
| 486 | expectEqual(queue.removeOrNull(), null); | |
| 483 | try expectEqual(queue.removeIndex(two_idx), 2); | |
| 484 | try expectEqual(queue.remove(), 1); | |
| 485 | try expectEqual(queue.remove(), 3); | |
| 486 | try expectEqual(queue.removeOrNull(), null); | |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | test "std.PriorityQueue: iterator while empty" { |
| ... | ... | @@ -492,7 +492,7 @@ test "std.PriorityQueue: iterator while empty" { |
| 492 | 492 | |
| 493 | 493 | var it = queue.iterator(); |
| 494 | 494 | |
| 495 | expectEqual(it.next(), null); | |
| 495 | try expectEqual(it.next(), null); | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" { |
| ... | ... | @@ -500,26 +500,26 @@ test "std.PriorityQueue: shrinkRetainingCapacity and shrinkAndFree" { |
| 500 | 500 | defer queue.deinit(); |
| 501 | 501 | |
| 502 | 502 | try queue.ensureCapacity(4); |
| 503 | expect(queue.capacity() >= 4); | |
| 503 | try expect(queue.capacity() >= 4); | |
| 504 | 504 | |
| 505 | 505 | try queue.add(1); |
| 506 | 506 | try queue.add(2); |
| 507 | 507 | try queue.add(3); |
| 508 | expect(queue.capacity() >= 4); | |
| 509 | expectEqual(@as(usize, 3), queue.len); | |
| 508 | try expect(queue.capacity() >= 4); | |
| 509 | try expectEqual(@as(usize, 3), queue.len); | |
| 510 | 510 | |
| 511 | 511 | queue.shrinkRetainingCapacity(3); |
| 512 | expect(queue.capacity() >= 4); | |
| 513 | expectEqual(@as(usize, 3), queue.len); | |
| 512 | try expect(queue.capacity() >= 4); | |
| 513 | try expectEqual(@as(usize, 3), queue.len); | |
| 514 | 514 | |
| 515 | 515 | queue.shrinkAndFree(3); |
| 516 | expectEqual(@as(usize, 3), queue.capacity()); | |
| 517 | expectEqual(@as(usize, 3), queue.len); | |
| 516 | try expectEqual(@as(usize, 3), queue.capacity()); | |
| 517 | try expectEqual(@as(usize, 3), queue.len); | |
| 518 | 518 | |
| 519 | expectEqual(@as(u32, 1), queue.remove()); | |
| 520 | expectEqual(@as(u32, 2), queue.remove()); | |
| 521 | expectEqual(@as(u32, 3), queue.remove()); | |
| 522 | expect(queue.removeOrNull() == null); | |
| 519 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 520 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 521 | try expectEqual(@as(u32, 3), queue.remove()); | |
| 522 | try expect(queue.removeOrNull() == null); | |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | test "std.PriorityQueue: update min heap" { |
| ... | ... | @@ -532,9 +532,9 @@ test "std.PriorityQueue: update min heap" { |
| 532 | 532 | try queue.update(55, 5); |
| 533 | 533 | try queue.update(44, 4); |
| 534 | 534 | try queue.update(11, 1); |
| 535 | expectEqual(@as(u32, 1), queue.remove()); | |
| 536 | expectEqual(@as(u32, 4), queue.remove()); | |
| 537 | expectEqual(@as(u32, 5), queue.remove()); | |
| 535 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 536 | try expectEqual(@as(u32, 4), queue.remove()); | |
| 537 | try expectEqual(@as(u32, 5), queue.remove()); | |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | test "std.PriorityQueue: update same min heap" { |
| ... | ... | @@ -547,10 +547,10 @@ test "std.PriorityQueue: update same min heap" { |
| 547 | 547 | try queue.add(2); |
| 548 | 548 | try queue.update(1, 5); |
| 549 | 549 | try queue.update(2, 4); |
| 550 | expectEqual(@as(u32, 1), queue.remove()); | |
| 551 | expectEqual(@as(u32, 2), queue.remove()); | |
| 552 | expectEqual(@as(u32, 4), queue.remove()); | |
| 553 | expectEqual(@as(u32, 5), queue.remove()); | |
| 550 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 551 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 552 | try expectEqual(@as(u32, 4), queue.remove()); | |
| 553 | try expectEqual(@as(u32, 5), queue.remove()); | |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | test "std.PriorityQueue: update max heap" { |
| ... | ... | @@ -563,9 +563,9 @@ test "std.PriorityQueue: update max heap" { |
| 563 | 563 | try queue.update(55, 5); |
| 564 | 564 | try queue.update(44, 1); |
| 565 | 565 | try queue.update(11, 4); |
| 566 | expectEqual(@as(u32, 5), queue.remove()); | |
| 567 | expectEqual(@as(u32, 4), queue.remove()); | |
| 568 | expectEqual(@as(u32, 1), queue.remove()); | |
| 566 | try expectEqual(@as(u32, 5), queue.remove()); | |
| 567 | try expectEqual(@as(u32, 4), queue.remove()); | |
| 568 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | test "std.PriorityQueue: update same max heap" { |
| ... | ... | @@ -578,8 +578,8 @@ test "std.PriorityQueue: update same max heap" { |
| 578 | 578 | try queue.add(2); |
| 579 | 579 | try queue.update(1, 5); |
| 580 | 580 | try queue.update(2, 4); |
| 581 | expectEqual(@as(u32, 5), queue.remove()); | |
| 582 | expectEqual(@as(u32, 4), queue.remove()); | |
| 583 | expectEqual(@as(u32, 2), queue.remove()); | |
| 584 | expectEqual(@as(u32, 1), queue.remove()); | |
| 581 | try expectEqual(@as(u32, 5), queue.remove()); | |
| 582 | try expectEqual(@as(u32, 4), queue.remove()); | |
| 583 | try expectEqual(@as(u32, 2), queue.remove()); | |
| 584 | try expectEqual(@as(u32, 1), queue.remove()); | |
| 585 | 585 | } |
lib/std/process.zig+16-16| ... | ... | @@ -181,7 +181,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned |
| 181 | 181 | |
| 182 | 182 | test "os.getEnvVarOwned" { |
| 183 | 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 | } |
| 186 | 186 | |
| 187 | 187 | pub const ArgIteratorPosix = struct { |
| ... | ... | @@ -516,10 +516,10 @@ test "args iterator" { |
| 516 | 516 | }; |
| 517 | 517 | const given_suffix = std.fs.path.basename(prog_name); |
| 518 | 518 | |
| 519 | testing.expect(mem.eql(u8, expected_suffix, given_suffix)); | |
| 520 | testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner | |
| 521 | testing.expect(it.next(ga) == null); | |
| 522 | testing.expect(!it.skip()); | |
| 519 | try testing.expect(mem.eql(u8, expected_suffix, given_suffix)); | |
| 520 | try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner | |
| 521 | try testing.expect(it.next(ga) == null); | |
| 522 | try testing.expect(!it.skip()); | |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /// Caller must call argsFree on result. |
| ... | ... | @@ -575,14 +575,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void { |
| 575 | 575 | |
| 576 | 576 | test "windows arg parsing" { |
| 577 | 577 | const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral; |
| 578 | testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" }); | |
| 579 | testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" }); | |
| 580 | testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); | |
| 581 | testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" }); | |
| 582 | testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" }); | |
| 583 | testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" }); | |
| 584 | ||
| 585 | testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{ | |
| 578 | try testWindowsCmdLine(utf16Literal("a b\tc d"), &[_][]const u8{ "a", "b", "c", "d" }); | |
| 579 | try testWindowsCmdLine(utf16Literal("\"abc\" d e"), &[_][]const u8{ "abc", "d", "e" }); | |
| 580 | try testWindowsCmdLine(utf16Literal("a\\\\\\b d\"e f\"g h"), &[_][]const u8{ "a\\\\\\b", "de fg", "h" }); | |
| 581 | try testWindowsCmdLine(utf16Literal("a\\\\\\\"b c d"), &[_][]const u8{ "a\\\"b", "c", "d" }); | |
| 582 | try testWindowsCmdLine(utf16Literal("a\\\\\\\\\"b c\" d e"), &[_][]const u8{ "a\\\\b c", "d", "e" }); | |
| 583 | try testWindowsCmdLine(utf16Literal("a b\tc \"d f"), &[_][]const u8{ "a", "b", "c", "d f" }); | |
| 584 | ||
| 585 | try testWindowsCmdLine(utf16Literal("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\""), &[_][]const u8{ | |
| 586 | 586 | ".\\..\\zig-cache\\build", |
| 587 | 587 | "bin\\zig.exe", |
| 588 | 588 | ".\\..", |
| ... | ... | @@ -591,14 +591,14 @@ test "windows arg parsing" { |
| 591 | 591 | }); |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) void { | |
| 594 | fn testWindowsCmdLine(input_cmd_line: [*]const u16, expected_args: []const []const u8) !void { | |
| 595 | 595 | var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line); |
| 596 | 596 | for (expected_args) |expected_arg| { |
| 597 | 597 | const arg = it.next(std.testing.allocator).? catch unreachable; |
| 598 | 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 | } |
| 603 | 603 | |
| 604 | 604 | pub const UserInfo = struct { |
lib/std/rand.zig+96-96| ... | ... | @@ -319,139 +319,139 @@ const SequentialPrng = struct { |
| 319 | 319 | }; |
| 320 | 320 | |
| 321 | 321 | test "Random int" { |
| 322 | testRandomInt(); | |
| 323 | comptime testRandomInt(); | |
| 322 | try testRandomInt(); | |
| 323 | comptime try testRandomInt(); | |
| 324 | 324 | } |
| 325 | fn testRandomInt() void { | |
| 325 | fn testRandomInt() !void { | |
| 326 | 326 | var r = SequentialPrng.init(); |
| 327 | 327 | |
| 328 | expect(r.random.int(u0) == 0); | |
| 328 | try expect(r.random.int(u0) == 0); | |
| 329 | 329 | |
| 330 | 330 | r.next_value = 0; |
| 331 | expect(r.random.int(u1) == 0); | |
| 332 | expect(r.random.int(u1) == 1); | |
| 333 | expect(r.random.int(u2) == 2); | |
| 334 | expect(r.random.int(u2) == 3); | |
| 335 | expect(r.random.int(u2) == 0); | |
| 331 | try expect(r.random.int(u1) == 0); | |
| 332 | try expect(r.random.int(u1) == 1); | |
| 333 | try expect(r.random.int(u2) == 2); | |
| 334 | try expect(r.random.int(u2) == 3); | |
| 335 | try expect(r.random.int(u2) == 0); | |
| 336 | 336 | |
| 337 | 337 | r.next_value = 0xff; |
| 338 | expect(r.random.int(u8) == 0xff); | |
| 338 | try expect(r.random.int(u8) == 0xff); | |
| 339 | 339 | r.next_value = 0x11; |
| 340 | expect(r.random.int(u8) == 0x11); | |
| 340 | try expect(r.random.int(u8) == 0x11); | |
| 341 | 341 | |
| 342 | 342 | r.next_value = 0xff; |
| 343 | expect(r.random.int(u32) == 0xffffffff); | |
| 343 | try expect(r.random.int(u32) == 0xffffffff); | |
| 344 | 344 | r.next_value = 0x11; |
| 345 | expect(r.random.int(u32) == 0x11111111); | |
| 345 | try expect(r.random.int(u32) == 0x11111111); | |
| 346 | 346 | |
| 347 | 347 | r.next_value = 0xff; |
| 348 | expect(r.random.int(i32) == -1); | |
| 348 | try expect(r.random.int(i32) == -1); | |
| 349 | 349 | r.next_value = 0x11; |
| 350 | expect(r.random.int(i32) == 0x11111111); | |
| 350 | try expect(r.random.int(i32) == 0x11111111); | |
| 351 | 351 | |
| 352 | 352 | r.next_value = 0xff; |
| 353 | expect(r.random.int(i8) == -1); | |
| 353 | try expect(r.random.int(i8) == -1); | |
| 354 | 354 | r.next_value = 0x11; |
| 355 | expect(r.random.int(i8) == 0x11); | |
| 355 | try expect(r.random.int(i8) == 0x11); | |
| 356 | 356 | |
| 357 | 357 | r.next_value = 0xff; |
| 358 | expect(r.random.int(u33) == 0x1ffffffff); | |
| 358 | try expect(r.random.int(u33) == 0x1ffffffff); | |
| 359 | 359 | r.next_value = 0xff; |
| 360 | expect(r.random.int(i1) == -1); | |
| 360 | try expect(r.random.int(i1) == -1); | |
| 361 | 361 | r.next_value = 0xff; |
| 362 | expect(r.random.int(i2) == -1); | |
| 362 | try expect(r.random.int(i2) == -1); | |
| 363 | 363 | r.next_value = 0xff; |
| 364 | expect(r.random.int(i33) == -1); | |
| 364 | try expect(r.random.int(i33) == -1); | |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | test "Random boolean" { |
| 368 | testRandomBoolean(); | |
| 369 | comptime testRandomBoolean(); | |
| 368 | try testRandomBoolean(); | |
| 369 | comptime try testRandomBoolean(); | |
| 370 | 370 | } |
| 371 | fn testRandomBoolean() void { | |
| 371 | fn testRandomBoolean() !void { | |
| 372 | 372 | var r = SequentialPrng.init(); |
| 373 | expect(r.random.boolean() == false); | |
| 374 | expect(r.random.boolean() == true); | |
| 375 | expect(r.random.boolean() == false); | |
| 376 | expect(r.random.boolean() == true); | |
| 373 | try expect(r.random.boolean() == false); | |
| 374 | try expect(r.random.boolean() == true); | |
| 375 | try expect(r.random.boolean() == false); | |
| 376 | try expect(r.random.boolean() == true); | |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | test "Random intLessThan" { |
| 380 | 380 | @setEvalBranchQuota(10000); |
| 381 | testRandomIntLessThan(); | |
| 382 | comptime testRandomIntLessThan(); | |
| 381 | try testRandomIntLessThan(); | |
| 382 | comptime try testRandomIntLessThan(); | |
| 383 | 383 | } |
| 384 | fn testRandomIntLessThan() void { | |
| 384 | fn testRandomIntLessThan() !void { | |
| 385 | 385 | var r = SequentialPrng.init(); |
| 386 | 386 | r.next_value = 0xff; |
| 387 | expect(r.random.uintLessThan(u8, 4) == 3); | |
| 388 | expect(r.next_value == 0); | |
| 389 | expect(r.random.uintLessThan(u8, 4) == 0); | |
| 390 | expect(r.next_value == 1); | |
| 387 | try expect(r.random.uintLessThan(u8, 4) == 3); | |
| 388 | try expect(r.next_value == 0); | |
| 389 | try expect(r.random.uintLessThan(u8, 4) == 0); | |
| 390 | try expect(r.next_value == 1); | |
| 391 | 391 | |
| 392 | 392 | r.next_value = 0; |
| 393 | expect(r.random.uintLessThan(u64, 32) == 0); | |
| 393 | try expect(r.random.uintLessThan(u64, 32) == 0); | |
| 394 | 394 | |
| 395 | 395 | // trigger the bias rejection code path |
| 396 | 396 | r.next_value = 0; |
| 397 | expect(r.random.uintLessThan(u8, 3) == 0); | |
| 397 | try expect(r.random.uintLessThan(u8, 3) == 0); | |
| 398 | 398 | // verify we incremented twice |
| 399 | expect(r.next_value == 2); | |
| 399 | try expect(r.next_value == 2); | |
| 400 | 400 | |
| 401 | 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 | 403 | r.next_value = 0xff; |
| 404 | expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe); | |
| 404 | try expect(r.random.intRangeLessThan(u8, 0x7f, 0xff) == 0xfe); | |
| 405 | 405 | |
| 406 | 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 | 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 | 410 | r.next_value = 0xff; |
| 411 | expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1); | |
| 411 | try expect(r.random.intRangeLessThan(i8, -0x80, 0) == -1); | |
| 412 | 412 | |
| 413 | 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 | 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 | } |
| 418 | 418 | |
| 419 | 419 | test "Random intAtMost" { |
| 420 | 420 | @setEvalBranchQuota(10000); |
| 421 | testRandomIntAtMost(); | |
| 422 | comptime testRandomIntAtMost(); | |
| 421 | try testRandomIntAtMost(); | |
| 422 | comptime try testRandomIntAtMost(); | |
| 423 | 423 | } |
| 424 | fn testRandomIntAtMost() void { | |
| 424 | fn testRandomIntAtMost() !void { | |
| 425 | 425 | var r = SequentialPrng.init(); |
| 426 | 426 | r.next_value = 0xff; |
| 427 | expect(r.random.uintAtMost(u8, 3) == 3); | |
| 428 | expect(r.next_value == 0); | |
| 429 | expect(r.random.uintAtMost(u8, 3) == 0); | |
| 427 | try expect(r.random.uintAtMost(u8, 3) == 3); | |
| 428 | try expect(r.next_value == 0); | |
| 429 | try expect(r.random.uintAtMost(u8, 3) == 0); | |
| 430 | 430 | |
| 431 | 431 | // trigger the bias rejection code path |
| 432 | 432 | r.next_value = 0; |
| 433 | expect(r.random.uintAtMost(u8, 2) == 0); | |
| 433 | try expect(r.random.uintAtMost(u8, 2) == 0); | |
| 434 | 434 | // verify we incremented twice |
| 435 | expect(r.next_value == 2); | |
| 435 | try expect(r.next_value == 2); | |
| 436 | 436 | |
| 437 | 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 | 439 | r.next_value = 0xff; |
| 440 | expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe); | |
| 440 | try expect(r.random.intRangeAtMost(u8, 0x7f, 0xfe) == 0xfe); | |
| 441 | 441 | |
| 442 | 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 | 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 | 446 | r.next_value = 0xff; |
| 447 | expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1); | |
| 447 | try expect(r.random.intRangeAtMost(i8, -0x80, -1) == -1); | |
| 448 | 448 | |
| 449 | 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 | 451 | r.next_value = 0xff; |
| 452 | expect(r.random.intRangeAtMost(i3, -2, 1) == 1); | |
| 452 | try expect(r.random.intRangeAtMost(i3, -2, 1) == 1); | |
| 453 | 453 | |
| 454 | expect(r.random.uintAtMost(u0, 0) == 0); | |
| 454 | try expect(r.random.uintAtMost(u0, 0) == 0); | |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | test "Random Biased" { |
| ... | ... | @@ -459,30 +459,30 @@ test "Random Biased" { |
| 459 | 459 | // Not thoroughly checking the logic here. |
| 460 | 460 | // Just want to execute all the paths with different types. |
| 461 | 461 | |
| 462 | expect(r.random.uintLessThanBiased(u1, 1) == 0); | |
| 463 | expect(r.random.uintLessThanBiased(u32, 10) < 10); | |
| 464 | expect(r.random.uintLessThanBiased(u64, 20) < 20); | |
| 462 | try expect(r.random.uintLessThanBiased(u1, 1) == 0); | |
| 463 | try expect(r.random.uintLessThanBiased(u32, 10) < 10); | |
| 464 | try expect(r.random.uintLessThanBiased(u64, 20) < 20); | |
| 465 | 465 | |
| 466 | expect(r.random.uintAtMostBiased(u0, 0) == 0); | |
| 467 | expect(r.random.uintAtMostBiased(u1, 0) <= 0); | |
| 468 | expect(r.random.uintAtMostBiased(u32, 10) <= 10); | |
| 469 | expect(r.random.uintAtMostBiased(u64, 20) <= 20); | |
| 466 | try expect(r.random.uintAtMostBiased(u0, 0) == 0); | |
| 467 | try expect(r.random.uintAtMostBiased(u1, 0) <= 0); | |
| 468 | try expect(r.random.uintAtMostBiased(u32, 10) <= 10); | |
| 469 | try expect(r.random.uintAtMostBiased(u64, 20) <= 20); | |
| 470 | 470 | |
| 471 | expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0); | |
| 472 | expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1); | |
| 473 | expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10); | |
| 474 | expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10); | |
| 475 | expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20); | |
| 476 | expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20); | |
| 471 | try expect(r.random.intRangeLessThanBiased(u1, 0, 1) == 0); | |
| 472 | try expect(r.random.intRangeLessThanBiased(i1, -1, 0) == -1); | |
| 473 | try expect(r.random.intRangeLessThanBiased(u32, 10, 20) >= 10); | |
| 474 | try expect(r.random.intRangeLessThanBiased(i32, 10, 20) >= 10); | |
| 475 | try expect(r.random.intRangeLessThanBiased(u64, 20, 40) >= 20); | |
| 476 | try expect(r.random.intRangeLessThanBiased(i64, 20, 40) >= 20); | |
| 477 | 477 | |
| 478 | 478 | // uncomment for broken module error: |
| 479 | 479 | //expect(r.random.intRangeAtMostBiased(u0, 0, 0) == 0); |
| 480 | expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0); | |
| 481 | expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1); | |
| 482 | expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10); | |
| 483 | expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10); | |
| 484 | expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20); | |
| 485 | expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20); | |
| 480 | try expect(r.random.intRangeAtMostBiased(u1, 0, 1) >= 0); | |
| 481 | try expect(r.random.intRangeAtMostBiased(i1, -1, 0) >= -1); | |
| 482 | try expect(r.random.intRangeAtMostBiased(u32, 10, 20) >= 10); | |
| 483 | try expect(r.random.intRangeAtMostBiased(i32, 10, 20) >= 10); | |
| 484 | try expect(r.random.intRangeAtMostBiased(u64, 20, 40) >= 20); | |
| 485 | try expect(r.random.intRangeAtMostBiased(i64, 20, 40) >= 20); | |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | // Generator to extend 64-bit seed values into longer sequences. |
| ... | ... | @@ -519,7 +519,7 @@ test "splitmix64 sequence" { |
| 519 | 519 | }; |
| 520 | 520 | |
| 521 | 521 | for (seq) |s| { |
| 522 | expect(s == r.next()); | |
| 522 | try expect(s == r.next()); | |
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | 525 | |
| ... | ... | @@ -530,12 +530,12 @@ test "Random float" { |
| 530 | 530 | var i: usize = 0; |
| 531 | 531 | while (i < 1000) : (i += 1) { |
| 532 | 532 | const val1 = prng.random.float(f32); |
| 533 | expect(val1 >= 0.0); | |
| 534 | expect(val1 < 1.0); | |
| 533 | try expect(val1 >= 0.0); | |
| 534 | try expect(val1 < 1.0); | |
| 535 | 535 | |
| 536 | 536 | const val2 = prng.random.float(f64); |
| 537 | expect(val2 >= 0.0); | |
| 538 | expect(val2 < 1.0); | |
| 537 | try expect(val2 >= 0.0); | |
| 538 | try expect(val2 < 1.0); | |
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
| ... | ... | @@ -549,12 +549,12 @@ test "Random shuffle" { |
| 549 | 549 | while (i < 1000) : (i += 1) { |
| 550 | 550 | prng.random.shuffle(u8, seq[0..]); |
| 551 | 551 | seen[seq[0]] = true; |
| 552 | expect(sumArray(seq[0..]) == 10); | |
| 552 | try expect(sumArray(seq[0..]) == 10); | |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // we should see every entry at the head at least once |
| 556 | 556 | for (seen) |e| { |
| 557 | expect(e == true); | |
| 557 | try expect(e == true); | |
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| ... | ... | @@ -567,17 +567,17 @@ fn sumArray(s: []const u8) u32 { |
| 567 | 567 | |
| 568 | 568 | test "Random range" { |
| 569 | 569 | var prng = DefaultPrng.init(0); |
| 570 | testRange(&prng.random, -4, 3); | |
| 571 | testRange(&prng.random, -4, -1); | |
| 572 | testRange(&prng.random, 10, 14); | |
| 573 | testRange(&prng.random, -0x80, 0x7f); | |
| 570 | try testRange(&prng.random, -4, 3); | |
| 571 | try testRange(&prng.random, -4, -1); | |
| 572 | try testRange(&prng.random, 10, 14); | |
| 573 | try testRange(&prng.random, -0x80, 0x7f); | |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | fn testRange(r: *Random, start: i8, end: i8) void { | |
| 577 | testRangeBias(r, start, end, true); | |
| 578 | testRangeBias(r, start, end, false); | |
| 576 | fn testRange(r: *Random, start: i8, end: i8) !void { | |
| 577 | try testRangeBias(r, start, end, true); | |
| 578 | try testRangeBias(r, start, end, false); | |
| 579 | 579 | } |
| 580 | fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { | |
| 580 | fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) !void { | |
| 581 | 581 | const count = @intCast(usize, @as(i32, end) - @as(i32, start)); |
| 582 | 582 | var values_buffer = [_]bool{false} ** 0x100; |
| 583 | 583 | const values = values_buffer[0..count]; |
| ... | ... | @@ -599,7 +599,7 @@ test "CSPRNG" { |
| 599 | 599 | const a = csprng.random.int(u64); |
| 600 | 600 | const b = csprng.random.int(u64); |
| 601 | 601 | const c = csprng.random.int(u64); |
| 602 | expect(a ^ b ^ c != 0); | |
| 602 | try expect(a ^ b ^ c != 0); | |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | test { |
lib/std/rand/Isaac64.zig+2-2| ... | ... | @@ -205,7 +205,7 @@ test "isaac64 sequence" { |
| 205 | 205 | }; |
| 206 | 206 | |
| 207 | 207 | for (seq) |s| { |
| 208 | std.testing.expect(s == r.next()); | |
| 208 | try std.testing.expect(s == r.next()); | |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| ... | ... | @@ -237,6 +237,6 @@ test "isaac64 fill" { |
| 237 | 237 | var buf1: [7]u8 = undefined; |
| 238 | 238 | std.mem.writeIntLittle(u64, &buf0, s); |
| 239 | 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 | 96 | }; |
| 97 | 97 | |
| 98 | 98 | for (seq) |s| { |
| 99 | std.testing.expect(s == r.next()); | |
| 99 | try std.testing.expect(s == r.next()); | |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| ... | ... | @@ -120,6 +120,6 @@ test "pcg fill" { |
| 120 | 120 | var buf1: [3]u8 = undefined; |
| 121 | 121 | std.mem.writeIntLittle(u32, &buf0, s); |
| 122 | 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 | 103 | }; |
| 104 | 104 | |
| 105 | 105 | for (seq) |s| { |
| 106 | std.testing.expectEqual(s, r.next()); | |
| 106 | try std.testing.expectEqual(s, r.next()); | |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| ... | ... | @@ -135,6 +135,6 @@ test "Sfc64 fill" { |
| 135 | 135 | var buf1: [7]u8 = undefined; |
| 136 | 136 | std.mem.writeIntLittle(u64, &buf0, s); |
| 137 | 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 | 113 | }; |
| 114 | 114 | |
| 115 | 115 | for (seq1) |s| { |
| 116 | std.testing.expect(s == r.next()); | |
| 116 | try std.testing.expect(s == r.next()); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | r.jump(); |
| ... | ... | @@ -128,7 +128,7 @@ test "xoroshiro sequence" { |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | 130 | for (seq2) |s| { |
| 131 | std.testing.expect(s == r.next()); | |
| 131 | try std.testing.expect(s == r.next()); | |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| ... | ... | @@ -151,6 +151,6 @@ test "xoroshiro fill" { |
| 151 | 151 | var buf1: [7]u8 = undefined; |
| 152 | 152 | std.mem.writeIntLittle(u64, &buf0, s); |
| 153 | 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 | 43 | return math.order(lhs, rhs); |
| 44 | 44 | } |
| 45 | 45 | }; |
| 46 | testing.expectEqual( | |
| 46 | try testing.expectEqual( | |
| 47 | 47 | @as(?usize, null), |
| 48 | 48 | binarySearch(u32, 1, &[_]u32{}, {}, S.order_u32), |
| 49 | 49 | ); |
| 50 | testing.expectEqual( | |
| 50 | try testing.expectEqual( | |
| 51 | 51 | @as(?usize, 0), |
| 52 | 52 | binarySearch(u32, 1, &[_]u32{1}, {}, S.order_u32), |
| 53 | 53 | ); |
| 54 | testing.expectEqual( | |
| 54 | try testing.expectEqual( | |
| 55 | 55 | @as(?usize, null), |
| 56 | 56 | binarySearch(u32, 1, &[_]u32{0}, {}, S.order_u32), |
| 57 | 57 | ); |
| 58 | testing.expectEqual( | |
| 58 | try testing.expectEqual( | |
| 59 | 59 | @as(?usize, null), |
| 60 | 60 | binarySearch(u32, 0, &[_]u32{1}, {}, S.order_u32), |
| 61 | 61 | ); |
| 62 | testing.expectEqual( | |
| 62 | try testing.expectEqual( | |
| 63 | 63 | @as(?usize, 4), |
| 64 | 64 | binarySearch(u32, 5, &[_]u32{ 1, 2, 3, 4, 5 }, {}, S.order_u32), |
| 65 | 65 | ); |
| 66 | testing.expectEqual( | |
| 66 | try testing.expectEqual( | |
| 67 | 67 | @as(?usize, 0), |
| 68 | 68 | binarySearch(u32, 2, &[_]u32{ 2, 4, 8, 16, 32, 64 }, {}, S.order_u32), |
| 69 | 69 | ); |
| 70 | testing.expectEqual( | |
| 70 | try testing.expectEqual( | |
| 71 | 71 | @as(?usize, 1), |
| 72 | 72 | binarySearch(i32, -4, &[_]i32{ -7, -4, 0, 9, 10 }, {}, S.order_i32), |
| 73 | 73 | ); |
| 74 | testing.expectEqual( | |
| 74 | try testing.expectEqual( | |
| 75 | 75 | @as(?usize, 3), |
| 76 | 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 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | test "stable sort" { |
| 1155 | testStableSort(); | |
| 1156 | comptime testStableSort(); | |
| 1155 | try testStableSort(); | |
| 1156 | comptime try testStableSort(); | |
| 1157 | 1157 | } |
| 1158 | fn testStableSort() void { | |
| 1158 | fn testStableSort() !void { | |
| 1159 | 1159 | var expected = [_]IdAndValue{ |
| 1160 | 1160 | IdAndValue{ .id = 0, .value = 0 }, |
| 1161 | 1161 | IdAndValue{ .id = 1, .value = 0 }, |
| ... | ... | @@ -1194,8 +1194,8 @@ fn testStableSort() void { |
| 1194 | 1194 | for (cases) |*case| { |
| 1195 | 1195 | insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue); |
| 1196 | 1196 | for (case.*) |item, i| { |
| 1197 | testing.expect(item.id == expected[i].id); | |
| 1198 | testing.expect(item.value == expected[i].value); | |
| 1197 | try testing.expect(item.id == expected[i].id); | |
| 1198 | try testing.expect(item.value == expected[i].value); | |
| 1199 | 1199 | } |
| 1200 | 1200 | } |
| 1201 | 1201 | } |
| ... | ... | @@ -1245,7 +1245,7 @@ test "sort" { |
| 1245 | 1245 | const slice = buf[0..case[0].len]; |
| 1246 | 1246 | mem.copy(u8, slice, case[0]); |
| 1247 | 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 | } |
| 1250 | 1250 | |
| 1251 | 1251 | const i32cases = [_][]const []const i32{ |
| ... | ... | @@ -1280,7 +1280,7 @@ test "sort" { |
| 1280 | 1280 | const slice = buf[0..case[0].len]; |
| 1281 | 1281 | mem.copy(i32, slice, case[0]); |
| 1282 | 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 | } |
| 1286 | 1286 | |
| ... | ... | @@ -1317,7 +1317,7 @@ test "sort descending" { |
| 1317 | 1317 | const slice = buf[0..case[0].len]; |
| 1318 | 1318 | mem.copy(i32, slice, case[0]); |
| 1319 | 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 | } |
| 1323 | 1323 | |
| ... | ... | @@ -1325,7 +1325,7 @@ test "another sort case" { |
| 1325 | 1325 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; |
| 1326 | 1326 | sort(i32, arr[0..], {}, asc_i32); |
| 1327 | 1327 | |
| 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 | } |
| 1330 | 1330 | |
| 1331 | 1331 | test "sort fuzz testing" { |
| ... | ... | @@ -1353,9 +1353,9 @@ fn fuzzTest(rng: *std.rand.Random) !void { |
| 1353 | 1353 | var index: usize = 1; |
| 1354 | 1354 | while (index < array.len) : (index += 1) { |
| 1355 | 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 | 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 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | test "argMin" { |
| 1386 | testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32)); | |
| 1387 | testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1388 | testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1389 | testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1390 | testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1391 | testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1392 | testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1386 | try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32)); | |
| 1387 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1388 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1389 | try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1390 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1391 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1392 | try testing.expectEqual(@as(?usize, 3), argMin(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | 1395 | pub fn min( |
| ... | ... | @@ -1403,13 +1403,13 @@ pub fn min( |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | test "min" { |
| 1406 | testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32)); | |
| 1407 | testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1408 | testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1409 | testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1410 | testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1411 | testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1412 | testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1406 | try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32)); | |
| 1407 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1408 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1409 | try testing.expectEqual(@as(?i32, 2), min(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1410 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1411 | try testing.expectEqual(@as(?i32, -10), min(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1412 | try testing.expectEqual(@as(?i32, 7), min(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | pub fn argMax( |
| ... | ... | @@ -1435,13 +1435,13 @@ pub fn argMax( |
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | test "argMax" { |
| 1438 | testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32)); | |
| 1439 | testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1440 | testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1441 | testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1442 | testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1443 | testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1444 | testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1438 | try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32)); | |
| 1439 | try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1440 | try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1441 | try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1442 | try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1443 | try testing.expectEqual(@as(?usize, 2), argMax(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1444 | try testing.expectEqual(@as(?usize, 1), argMax(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | pub fn max( |
| ... | ... | @@ -1455,13 +1455,13 @@ pub fn max( |
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | test "max" { |
| 1458 | testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32)); | |
| 1459 | testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1460 | testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1461 | testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1462 | testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1463 | testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1464 | testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1458 | try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32)); | |
| 1459 | try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32)); | |
| 1460 | try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1461 | try testing.expectEqual(@as(?i32, 9), max(i32, &[_]i32{ 9, 3, 8, 2, 5 }, {}, asc_i32)); | |
| 1462 | try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1463 | try testing.expectEqual(@as(?i32, 10), max(i32, &[_]i32{ -10, 1, 10 }, {}, asc_i32)); | |
| 1464 | try testing.expectEqual(@as(?i32, 3), max(i32, &[_]i32{ 6, 3, 5, 7, 6 }, {}, desc_i32)); | |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | pub fn isSorted( |
| ... | ... | @@ -1481,28 +1481,28 @@ pub fn isSorted( |
| 1481 | 1481 | } |
| 1482 | 1482 | |
| 1483 | 1483 | test "isSorted" { |
| 1484 | testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32)); | |
| 1485 | testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32)); | |
| 1486 | testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1487 | testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32)); | |
| 1484 | try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32)); | |
| 1485 | try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32)); | |
| 1486 | try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | |
| 1487 | try testing.expect(isSorted(i32, &[_]i32{ -10, 1, 1, 1, 10 }, {}, asc_i32)); | |
| 1488 | 1488 | |
| 1489 | testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32)); | |
| 1490 | testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32)); | |
| 1491 | testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32)); | |
| 1492 | testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32)); | |
| 1489 | try testing.expect(isSorted(i32, &[_]i32{}, {}, desc_i32)); | |
| 1490 | try testing.expect(isSorted(i32, &[_]i32{-20}, {}, desc_i32)); | |
| 1491 | try testing.expect(isSorted(i32, &[_]i32{ 3, 2, 1, 0, -1 }, {}, desc_i32)); | |
| 1492 | try testing.expect(isSorted(i32, &[_]i32{ 10, -10 }, {}, desc_i32)); | |
| 1493 | 1493 | |
| 1494 | testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1495 | testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32)); | |
| 1494 | try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, asc_i32)); | |
| 1495 | try testing.expect(isSorted(i32, &[_]i32{ 1, 1, 1, 1, 1 }, {}, desc_i32)); | |
| 1496 | 1496 | |
| 1497 | testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32)); | |
| 1498 | testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32)); | |
| 1497 | try testing.expectEqual(false, isSorted(i32, &[_]i32{ 5, 4, 3, 2, 1 }, {}, asc_i32)); | |
| 1498 | try testing.expectEqual(false, isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, desc_i32)); | |
| 1499 | 1499 | |
| 1500 | testing.expect(isSorted(u8, "abcd", {}, asc_u8)); | |
| 1501 | testing.expect(isSorted(u8, "zyxw", {}, desc_u8)); | |
| 1500 | try testing.expect(isSorted(u8, "abcd", {}, asc_u8)); | |
| 1501 | try testing.expect(isSorted(u8, "zyxw", {}, desc_u8)); | |
| 1502 | 1502 | |
| 1503 | testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8)); | |
| 1504 | testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8)); | |
| 1503 | try testing.expectEqual(false, isSorted(u8, "abcd", {}, desc_u8)); | |
| 1504 | try testing.expectEqual(false, isSorted(u8, "zyxw", {}, asc_u8)); | |
| 1505 | 1505 | |
| 1506 | testing.expect(isSorted(u8, "ffff", {}, asc_u8)); | |
| 1507 | testing.expect(isSorted(u8, "ffff", {}, desc_u8)); | |
| 1506 | try testing.expect(isSorted(u8, "ffff", {}, asc_u8)); | |
| 1507 | try testing.expect(isSorted(u8, "ffff", {}, desc_u8)); | |
| 1508 | 1508 | } |
lib/std/special/c.zig+47-47| ... | ... | @@ -66,7 +66,7 @@ test "strcpy" { |
| 66 | 66 | |
| 67 | 67 | s1[0] = 0; |
| 68 | 68 | _ = strcpy(&s1, "foobarbaz"); |
| 69 | std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 69 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -86,7 +86,7 @@ test "strncpy" { |
| 86 | 86 | |
| 87 | 87 | s1[0] = 0; |
| 88 | 88 | _ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1))); |
| 89 | std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 89 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -109,7 +109,7 @@ test "strcat" { |
| 109 | 109 | _ = strcat(&s1, "foo"); |
| 110 | 110 | _ = strcat(&s1, "bar"); |
| 111 | 111 | _ = strcat(&s1, "baz"); |
| 112 | std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 112 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 { |
| ... | ... | @@ -132,7 +132,7 @@ test "strncat" { |
| 132 | 132 | _ = strncat(&s1, "foo1111", 3); |
| 133 | 133 | _ = strncat(&s1, "bar1111", 3); |
| 134 | 134 | _ = strncat(&s1, "baz1111", 3); |
| 135 | std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 135 | try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.spanZ(&s1)); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int { |
| ... | ... | @@ -161,10 +161,10 @@ fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 { |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | test "strncmp" { |
| 164 | std.testing.expect(strncmp("a", "b", 1) == -1); | |
| 165 | std.testing.expect(strncmp("a", "c", 1) == -2); | |
| 166 | std.testing.expect(strncmp("b", "a", 1) == 1); | |
| 167 | std.testing.expect(strncmp("\xff", "\x02", 1) == 253); | |
| 164 | try std.testing.expect(strncmp("a", "b", 1) == -1); | |
| 165 | try std.testing.expect(strncmp("a", "c", 1) == -2); | |
| 166 | try std.testing.expect(strncmp("b", "a", 1) == 1); | |
| 167 | try std.testing.expect(strncmp("\xff", "\x02", 1) == 253); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Avoid dragging in the runtime safety mechanisms into this .o file, |
| ... | ... | @@ -245,9 +245,9 @@ test "memcmp" { |
| 245 | 245 | const arr2 = &[_]u8{ 1, 0, 1 }; |
| 246 | 246 | const arr3 = &[_]u8{ 1, 2, 1 }; |
| 247 | 247 | |
| 248 | std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | |
| 249 | std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0); | |
| 250 | std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0); | |
| 248 | try std.testing.expect(memcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | |
| 249 | try std.testing.expect(memcmp(base_arr[0..], arr2[0..], base_arr.len) > 0); | |
| 250 | try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize { |
| ... | ... | @@ -269,9 +269,9 @@ test "bcmp" { |
| 269 | 269 | const arr2 = &[_]u8{ 1, 0, 1 }; |
| 270 | 270 | const arr3 = &[_]u8{ 1, 2, 1 }; |
| 271 | 271 | |
| 272 | std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | |
| 273 | std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0); | |
| 274 | std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0); | |
| 272 | try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); | |
| 273 | try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0); | |
| 274 | try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | comptime { |
| ... | ... | @@ -865,19 +865,19 @@ test "fmod, fmodf" { |
| 865 | 865 | const nan_val = math.nan(T); |
| 866 | 866 | const inf_val = math.inf(T); |
| 867 | 867 | |
| 868 | std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0))); | |
| 869 | std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val))); | |
| 870 | std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0))); | |
| 871 | std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0))); | |
| 872 | std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0))); | |
| 868 | try std.testing.expect(isNan(generic_fmod(T, nan_val, 1.0))); | |
| 869 | try std.testing.expect(isNan(generic_fmod(T, 1.0, nan_val))); | |
| 870 | try std.testing.expect(isNan(generic_fmod(T, inf_val, 1.0))); | |
| 871 | try std.testing.expect(isNan(generic_fmod(T, 0.0, 0.0))); | |
| 872 | try std.testing.expect(isNan(generic_fmod(T, 1.0, 0.0))); | |
| 873 | 873 | |
| 874 | std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0)); | |
| 875 | std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0)); | |
| 874 | try std.testing.expectEqual(@as(T, 0.0), generic_fmod(T, 0.0, 2.0)); | |
| 875 | try std.testing.expectEqual(@as(T, -0.0), generic_fmod(T, -0.0, 2.0)); | |
| 876 | 876 | |
| 877 | std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0)); | |
| 878 | std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0)); | |
| 879 | std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, 10.0)); | |
| 880 | std.testing.expectEqual(@as(T, 2.0), generic_fmod(T, 32.0, -10.0)); | |
| 877 | try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, 10.0)); | |
| 878 | try std.testing.expectEqual(@as(T, -2.0), generic_fmod(T, -32.0, -10.0)); | |
| 879 | try 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 | 881 | } |
| 882 | 882 | } |
| 883 | 883 | |
| ... | ... | @@ -901,12 +901,12 @@ test "fmin, fminf" { |
| 901 | 901 | inline for ([_]type{ f32, f64 }) |T| { |
| 902 | 902 | const nan_val = math.nan(T); |
| 903 | 903 | |
| 904 | std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val))); | |
| 905 | std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0)); | |
| 906 | std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val)); | |
| 904 | try std.testing.expect(isNan(generic_fmin(T, nan_val, nan_val))); | |
| 905 | try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, nan_val, 1.0)); | |
| 906 | try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, nan_val)); | |
| 907 | 907 | |
| 908 | std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0)); | |
| 909 | std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0)); | |
| 908 | try std.testing.expectEqual(@as(T, 1.0), generic_fmin(T, 1.0, 10.0)); | |
| 909 | try std.testing.expectEqual(@as(T, -1.0), generic_fmin(T, 1.0, -1.0)); | |
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | 912 | |
| ... | ... | @@ -930,12 +930,12 @@ test "fmax, fmaxf" { |
| 930 | 930 | inline for ([_]type{ f32, f64 }) |T| { |
| 931 | 931 | const nan_val = math.nan(T); |
| 932 | 932 | |
| 933 | std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val))); | |
| 934 | std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0)); | |
| 935 | std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val)); | |
| 933 | try std.testing.expect(isNan(generic_fmax(T, nan_val, nan_val))); | |
| 934 | try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, nan_val, 1.0)); | |
| 935 | try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, nan_val)); | |
| 936 | 936 | |
| 937 | std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0)); | |
| 938 | std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0)); | |
| 937 | try std.testing.expectEqual(@as(T, 10.0), generic_fmax(T, 1.0, 10.0)); | |
| 938 | try std.testing.expectEqual(@as(T, 1.0), generic_fmax(T, 1.0, -1.0)); | |
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | 941 | |
| ... | ... | @@ -1090,15 +1090,15 @@ test "sqrt" { |
| 1090 | 1090 | // Note that @sqrt will either generate the sqrt opcode (if supported by the |
| 1091 | 1091 | // target ISA) or a call to `sqrtf` otherwise. |
| 1092 | 1092 | for (V) |val| |
| 1093 | std.testing.expectEqual(@sqrt(val), sqrt(val)); | |
| 1093 | try std.testing.expectEqual(@sqrt(val), sqrt(val)); | |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | test "sqrt special" { |
| 1097 | std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64)))); | |
| 1098 | std.testing.expect(sqrt(0.0) == 0.0); | |
| 1099 | std.testing.expect(sqrt(-0.0) == -0.0); | |
| 1100 | std.testing.expect(isNan(sqrt(-1.0))); | |
| 1101 | std.testing.expect(isNan(sqrt(std.math.nan(f64)))); | |
| 1097 | try std.testing.expect(std.math.isPositiveInf(sqrt(std.math.inf(f64)))); | |
| 1098 | try std.testing.expect(sqrt(0.0) == 0.0); | |
| 1099 | try std.testing.expect(sqrt(-0.0) == -0.0); | |
| 1100 | try std.testing.expect(isNan(sqrt(-1.0))); | |
| 1101 | try std.testing.expect(isNan(sqrt(std.math.nan(f64)))); | |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | export fn sqrtf(x: f32) f32 { |
| ... | ... | @@ -1195,13 +1195,13 @@ test "sqrtf" { |
| 1195 | 1195 | // Note that @sqrt will either generate the sqrt opcode (if supported by the |
| 1196 | 1196 | // target ISA) or a call to `sqrtf` otherwise. |
| 1197 | 1197 | for (V) |val| |
| 1198 | std.testing.expectEqual(@sqrt(val), sqrtf(val)); | |
| 1198 | try std.testing.expectEqual(@sqrt(val), sqrtf(val)); | |
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | test "sqrtf special" { |
| 1202 | std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32)))); | |
| 1203 | std.testing.expect(sqrtf(0.0) == 0.0); | |
| 1204 | std.testing.expect(sqrtf(-0.0) == -0.0); | |
| 1205 | std.testing.expect(isNan(sqrtf(-1.0))); | |
| 1206 | std.testing.expect(isNan(sqrtf(std.math.nan(f32)))); | |
| 1202 | try std.testing.expect(std.math.isPositiveInf(sqrtf(std.math.inf(f32)))); | |
| 1203 | try std.testing.expect(sqrtf(0.0) == 0.0); | |
| 1204 | try std.testing.expect(sqrtf(-0.0) == -0.0); | |
| 1205 | try std.testing.expect(isNan(sqrtf(-1.0))); | |
| 1206 | try std.testing.expect(isNan(sqrtf(std.math.nan(f32)))); | |
| 1207 | 1207 | } |
lib/std/special/compiler_rt/addXf3_test.zig+13-13| ... | ... | @@ -13,7 +13,7 @@ const inf128 = @bitCast(f128, @as(u128, 0x7fff000000000000) << 64); |
| 13 | 13 | |
| 14 | 14 | const __addtf3 = @import("addXf3.zig").__addtf3; |
| 15 | 15 | |
| 16 | fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { | |
| 16 | fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { | |
| 17 | 17 | const x = __addtf3(a, b); |
| 18 | 18 | |
| 19 | 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 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | @panic("__addtf3 test failure"); | |
| 35 | return error.TestFailed; | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "addtf3" { |
| 39 | test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 39 | try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 40 | 40 | |
| 41 | 41 | // 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); | |
| 43 | 43 | |
| 44 | 44 | // inf + inf = inf |
| 45 | test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); | |
| 45 | try test__addtf3(inf128, inf128, 0x7fff000000000000, 0x0); | |
| 46 | 46 | |
| 47 | 47 | // inf + any = inf |
| 48 | test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0); | |
| 48 | try test__addtf3(inf128, 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0); | |
| 49 | 49 | |
| 50 | 50 | // 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 | } |
| 53 | 53 | |
| 54 | 54 | const __subtf3 = @import("addXf3.zig").__subtf3; |
| 55 | 55 | |
| 56 | fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { | |
| 56 | fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { | |
| 57 | 57 | const x = __subtf3(a, b); |
| 58 | 58 | |
| 59 | 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 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | @panic("__subtf3 test failure"); | |
| 75 | return error.TestFailed; | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "subtf3" { |
| 79 | 79 | // qNaN - any = qNaN |
| 80 | test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 80 | try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 81 | 81 | |
| 82 | 82 | // 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); | |
| 84 | 84 | |
| 85 | 85 | // inf - any = inf |
| 86 | test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); | |
| 86 | try test__subtf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); | |
| 87 | 87 | |
| 88 | 88 | // 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 | 6 | const __ashldi3 = @import("shift.zig").__ashldi3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__ashldi3(a: i64, b: i32, expected: u64) void { | |
| 9 | fn test__ashldi3(a: i64, b: i32, expected: u64) !void { | |
| 10 | 10 | const x = __ashldi3(a, b); |
| 11 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 11 | try testing.expectEqual(@bitCast(i64, expected), x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "ashldi3" { |
| 15 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE); | |
| 17 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC); | |
| 18 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78); | |
| 19 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0); | |
| 15 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE); | |
| 17 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC); | |
| 18 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78); | |
| 19 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0); | |
| 20 | 20 | |
| 21 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000); | |
| 22 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000); | |
| 23 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000); | |
| 24 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000); | |
| 21 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000); | |
| 22 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000); | |
| 23 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000); | |
| 24 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000); | |
| 25 | 25 | |
| 26 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000); | |
| 26 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000); | |
| 27 | 27 | |
| 28 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000); | |
| 29 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000); | |
| 30 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000); | |
| 31 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000); | |
| 28 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000); | |
| 29 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000); | |
| 30 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000); | |
| 31 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000); | |
| 32 | 32 | |
| 33 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000); | |
| 34 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000); | |
| 35 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000); | |
| 36 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000); | |
| 33 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000); | |
| 34 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000); | |
| 35 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000); | |
| 36 | try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000); | |
| 37 | 37 | } |
lib/std/special/compiler_rt/ashlti3_test.zig+38-38| ... | ... | @@ -6,46 +6,46 @@ |
| 6 | 6 | const __ashlti3 = @import("shift.zig").__ashlti3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__ashlti3(a: i128, b: i32, expected: i128) void { | |
| 9 | fn test__ashlti3(a: i128, b: i32, expected: i128) !void { | |
| 10 | 10 | const x = __ashlti3(a, b); |
| 11 | testing.expectEqual(expected, x); | |
| 11 | try testing.expectEqual(expected, x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "ashlti3" { |
| 15 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A))); | |
| 17 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854))); | |
| 18 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8))); | |
| 19 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150))); | |
| 20 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000))); | |
| 21 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000))); | |
| 22 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000))); | |
| 23 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000))); | |
| 24 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000))); | |
| 25 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000))); | |
| 26 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000))); | |
| 27 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000))); | |
| 28 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000))); | |
| 29 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000))); | |
| 30 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000))); | |
| 31 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000))); | |
| 32 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000))); | |
| 33 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000))); | |
| 34 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000))); | |
| 35 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000))); | |
| 36 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000))); | |
| 37 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000))); | |
| 38 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000))); | |
| 39 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000))); | |
| 40 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000))); | |
| 41 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000))); | |
| 42 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000))); | |
| 43 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000))); | |
| 44 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000))); | |
| 45 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000))); | |
| 46 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000))); | |
| 47 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000))); | |
| 48 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000))); | |
| 49 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000))); | |
| 50 | test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000))); | |
| 15 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A))); | |
| 17 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854))); | |
| 18 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8))); | |
| 19 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150))); | |
| 20 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000))); | |
| 21 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000))); | |
| 22 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000))); | |
| 23 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000))); | |
| 24 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000))); | |
| 25 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000))); | |
| 26 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000))); | |
| 27 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000))); | |
| 28 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000))); | |
| 29 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000))); | |
| 30 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000))); | |
| 31 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000))); | |
| 32 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000))); | |
| 33 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000))); | |
| 34 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000))); | |
| 35 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000))); | |
| 36 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000))); | |
| 37 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000))); | |
| 38 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000))); | |
| 39 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000))); | |
| 40 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000))); | |
| 41 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000))); | |
| 42 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000))); | |
| 43 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000))); | |
| 44 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000))); | |
| 45 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000))); | |
| 46 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000))); | |
| 47 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000))); | |
| 48 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000))); | |
| 49 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000))); | |
| 50 | try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000))); | |
| 51 | 51 | } |
lib/std/special/compiler_rt/ashrdi3_test.zig+47-47| ... | ... | @@ -6,55 +6,55 @@ |
| 6 | 6 | const __ashrdi3 = @import("shift.zig").__ashrdi3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__ashrdi3(a: i64, b: i32, expected: u64) void { | |
| 9 | fn test__ashrdi3(a: i64, b: i32, expected: u64) !void { | |
| 10 | 10 | const x = __ashrdi3(a, b); |
| 11 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 11 | try testing.expectEqual(@bitCast(i64, expected), x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "ashrdi3" { |
| 15 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 17 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 18 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 19 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 20 | ||
| 21 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 22 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 23 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 24 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 25 | ||
| 26 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 27 | ||
| 28 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 29 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 30 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 31 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 32 | ||
| 33 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 34 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 35 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 36 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 37 | ||
| 38 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 39 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908); | |
| 40 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84); | |
| 41 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642); | |
| 42 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321); | |
| 43 | ||
| 44 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987); | |
| 45 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3); | |
| 46 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61); | |
| 47 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530); | |
| 48 | ||
| 49 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98); | |
| 50 | ||
| 51 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C); | |
| 52 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6); | |
| 53 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753); | |
| 54 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9); | |
| 55 | ||
| 56 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA); | |
| 57 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD); | |
| 58 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE); | |
| 59 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF); | |
| 15 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 17 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 18 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 19 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 20 | ||
| 21 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 22 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 23 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 24 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 25 | ||
| 26 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 27 | ||
| 28 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 29 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 30 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 31 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 32 | ||
| 33 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 34 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 35 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 36 | try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 37 | ||
| 38 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 39 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908); | |
| 40 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84); | |
| 41 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642); | |
| 42 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321); | |
| 43 | ||
| 44 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987); | |
| 45 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3); | |
| 46 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61); | |
| 47 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530); | |
| 48 | ||
| 49 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98); | |
| 50 | ||
| 51 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C); | |
| 52 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6); | |
| 53 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753); | |
| 54 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9); | |
| 55 | ||
| 56 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA); | |
| 57 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD); | |
| 58 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE); | |
| 59 | try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF); | |
| 60 | 60 | } |
lib/std/special/compiler_rt/ashrti3_test.zig+48-48| ... | ... | @@ -6,56 +6,56 @@ |
| 6 | 6 | const __ashrti3 = @import("shift.zig").__ashrti3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__ashrti3(a: i128, b: i32, expected: i128) void { | |
| 9 | fn test__ashrti3(a: i128, b: i32, expected: i128) !void { | |
| 10 | 10 | const x = __ashrti3(a, b); |
| 11 | testing.expectEqual(expected, x); | |
| 11 | try testing.expectEqual(expected, x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "ashrti3" { |
| 15 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A))); | |
| 17 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85))); | |
| 18 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642))); | |
| 19 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321))); | |
| 20 | ||
| 21 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987))); | |
| 22 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3))); | |
| 23 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61))); | |
| 24 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530))); | |
| 25 | ||
| 26 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98))); | |
| 27 | ||
| 28 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C))); | |
| 29 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6))); | |
| 30 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753))); | |
| 31 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9))); | |
| 32 | ||
| 33 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F))); | |
| 34 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF))); | |
| 35 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857))); | |
| 36 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B))); | |
| 37 | ||
| 38 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215))); | |
| 39 | ||
| 40 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A))); | |
| 41 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85))); | |
| 42 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642))); | |
| 43 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321))); | |
| 44 | ||
| 45 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987))); | |
| 46 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3))); | |
| 47 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61))); | |
| 48 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530))); | |
| 49 | ||
| 50 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98))); | |
| 51 | ||
| 52 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C))); | |
| 53 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6))); | |
| 54 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753))); | |
| 55 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9))); | |
| 56 | ||
| 57 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 58 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 59 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 60 | test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 15 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A))); | |
| 17 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85))); | |
| 18 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642))); | |
| 19 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321))); | |
| 20 | ||
| 21 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987))); | |
| 22 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3))); | |
| 23 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61))); | |
| 24 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530))); | |
| 25 | ||
| 26 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98))); | |
| 27 | ||
| 28 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C))); | |
| 29 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6))); | |
| 30 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753))); | |
| 31 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9))); | |
| 32 | ||
| 33 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F))); | |
| 34 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF))); | |
| 35 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857))); | |
| 36 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B))); | |
| 37 | ||
| 38 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215))); | |
| 39 | ||
| 40 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A))); | |
| 41 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85))); | |
| 42 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642))); | |
| 43 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321))); | |
| 44 | ||
| 45 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987))); | |
| 46 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3))); | |
| 47 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61))); | |
| 48 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530))); | |
| 49 | ||
| 50 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98))); | |
| 51 | ||
| 52 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C))); | |
| 53 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6))); | |
| 54 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753))); | |
| 55 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9))); | |
| 56 | ||
| 57 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 58 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 59 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 60 | try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))); | |
| 61 | 61 | } |
lib/std/special/compiler_rt/clzsi2_test.zig+281-281| ... | ... | @@ -6,294 +6,294 @@ |
| 6 | 6 | const clzsi2 = @import("clzsi2.zig"); |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__clzsi2(a: u32, expected: i32) void { | |
| 9 | fn test__clzsi2(a: u32, expected: i32) !void { | |
| 10 | 10 | // XXX At high optimization levels this test may be horribly miscompiled if |
| 11 | 11 | // one of the naked implementations is selected. |
| 12 | 12 | var nakedClzsi2 = clzsi2.__clzsi2; |
| 13 | 13 | var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2); |
| 14 | 14 | var x = @bitCast(i32, a); |
| 15 | 15 | var result = actualClzsi2(x); |
| 16 | testing.expectEqual(expected, result); | |
| 16 | try testing.expectEqual(expected, result); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "clzsi2" { |
| 20 | test__clzsi2(0x00800000, 8); | |
| 21 | test__clzsi2(0x01000000, 7); | |
| 22 | test__clzsi2(0x02000000, 6); | |
| 23 | test__clzsi2(0x03000000, 6); | |
| 24 | test__clzsi2(0x04000000, 5); | |
| 25 | test__clzsi2(0x05000000, 5); | |
| 26 | test__clzsi2(0x06000000, 5); | |
| 27 | test__clzsi2(0x07000000, 5); | |
| 28 | test__clzsi2(0x08000000, 4); | |
| 29 | test__clzsi2(0x09000000, 4); | |
| 30 | test__clzsi2(0x0A000000, 4); | |
| 31 | test__clzsi2(0x0B000000, 4); | |
| 32 | test__clzsi2(0x0C000000, 4); | |
| 33 | test__clzsi2(0x0D000000, 4); | |
| 34 | test__clzsi2(0x0E000000, 4); | |
| 35 | test__clzsi2(0x0F000000, 4); | |
| 36 | test__clzsi2(0x10000000, 3); | |
| 37 | test__clzsi2(0x11000000, 3); | |
| 38 | test__clzsi2(0x12000000, 3); | |
| 39 | test__clzsi2(0x13000000, 3); | |
| 40 | test__clzsi2(0x14000000, 3); | |
| 41 | test__clzsi2(0x15000000, 3); | |
| 42 | test__clzsi2(0x16000000, 3); | |
| 43 | test__clzsi2(0x17000000, 3); | |
| 44 | test__clzsi2(0x18000000, 3); | |
| 45 | test__clzsi2(0x19000000, 3); | |
| 46 | test__clzsi2(0x1A000000, 3); | |
| 47 | test__clzsi2(0x1B000000, 3); | |
| 48 | test__clzsi2(0x1C000000, 3); | |
| 49 | test__clzsi2(0x1D000000, 3); | |
| 50 | test__clzsi2(0x1E000000, 3); | |
| 51 | test__clzsi2(0x1F000000, 3); | |
| 52 | test__clzsi2(0x20000000, 2); | |
| 53 | test__clzsi2(0x21000000, 2); | |
| 54 | test__clzsi2(0x22000000, 2); | |
| 55 | test__clzsi2(0x23000000, 2); | |
| 56 | test__clzsi2(0x24000000, 2); | |
| 57 | test__clzsi2(0x25000000, 2); | |
| 58 | test__clzsi2(0x26000000, 2); | |
| 59 | test__clzsi2(0x27000000, 2); | |
| 60 | test__clzsi2(0x28000000, 2); | |
| 61 | test__clzsi2(0x29000000, 2); | |
| 62 | test__clzsi2(0x2A000000, 2); | |
| 63 | test__clzsi2(0x2B000000, 2); | |
| 64 | test__clzsi2(0x2C000000, 2); | |
| 65 | test__clzsi2(0x2D000000, 2); | |
| 66 | test__clzsi2(0x2E000000, 2); | |
| 67 | test__clzsi2(0x2F000000, 2); | |
| 68 | test__clzsi2(0x30000000, 2); | |
| 69 | test__clzsi2(0x31000000, 2); | |
| 70 | test__clzsi2(0x32000000, 2); | |
| 71 | test__clzsi2(0x33000000, 2); | |
| 72 | test__clzsi2(0x34000000, 2); | |
| 73 | test__clzsi2(0x35000000, 2); | |
| 74 | test__clzsi2(0x36000000, 2); | |
| 75 | test__clzsi2(0x37000000, 2); | |
| 76 | test__clzsi2(0x38000000, 2); | |
| 77 | test__clzsi2(0x39000000, 2); | |
| 78 | test__clzsi2(0x3A000000, 2); | |
| 79 | test__clzsi2(0x3B000000, 2); | |
| 80 | test__clzsi2(0x3C000000, 2); | |
| 81 | test__clzsi2(0x3D000000, 2); | |
| 82 | test__clzsi2(0x3E000000, 2); | |
| 83 | test__clzsi2(0x3F000000, 2); | |
| 84 | test__clzsi2(0x40000000, 1); | |
| 85 | test__clzsi2(0x41000000, 1); | |
| 86 | test__clzsi2(0x42000000, 1); | |
| 87 | test__clzsi2(0x43000000, 1); | |
| 88 | test__clzsi2(0x44000000, 1); | |
| 89 | test__clzsi2(0x45000000, 1); | |
| 90 | test__clzsi2(0x46000000, 1); | |
| 91 | test__clzsi2(0x47000000, 1); | |
| 92 | test__clzsi2(0x48000000, 1); | |
| 93 | test__clzsi2(0x49000000, 1); | |
| 94 | test__clzsi2(0x4A000000, 1); | |
| 95 | test__clzsi2(0x4B000000, 1); | |
| 96 | test__clzsi2(0x4C000000, 1); | |
| 97 | test__clzsi2(0x4D000000, 1); | |
| 98 | test__clzsi2(0x4E000000, 1); | |
| 99 | test__clzsi2(0x4F000000, 1); | |
| 100 | test__clzsi2(0x50000000, 1); | |
| 101 | test__clzsi2(0x51000000, 1); | |
| 102 | test__clzsi2(0x52000000, 1); | |
| 103 | test__clzsi2(0x53000000, 1); | |
| 104 | test__clzsi2(0x54000000, 1); | |
| 105 | test__clzsi2(0x55000000, 1); | |
| 106 | test__clzsi2(0x56000000, 1); | |
| 107 | test__clzsi2(0x57000000, 1); | |
| 108 | test__clzsi2(0x58000000, 1); | |
| 109 | test__clzsi2(0x59000000, 1); | |
| 110 | test__clzsi2(0x5A000000, 1); | |
| 111 | test__clzsi2(0x5B000000, 1); | |
| 112 | test__clzsi2(0x5C000000, 1); | |
| 113 | test__clzsi2(0x5D000000, 1); | |
| 114 | test__clzsi2(0x5E000000, 1); | |
| 115 | test__clzsi2(0x5F000000, 1); | |
| 116 | test__clzsi2(0x60000000, 1); | |
| 117 | test__clzsi2(0x61000000, 1); | |
| 118 | test__clzsi2(0x62000000, 1); | |
| 119 | test__clzsi2(0x63000000, 1); | |
| 120 | test__clzsi2(0x64000000, 1); | |
| 121 | test__clzsi2(0x65000000, 1); | |
| 122 | test__clzsi2(0x66000000, 1); | |
| 123 | test__clzsi2(0x67000000, 1); | |
| 124 | test__clzsi2(0x68000000, 1); | |
| 125 | test__clzsi2(0x69000000, 1); | |
| 126 | test__clzsi2(0x6A000000, 1); | |
| 127 | test__clzsi2(0x6B000000, 1); | |
| 128 | test__clzsi2(0x6C000000, 1); | |
| 129 | test__clzsi2(0x6D000000, 1); | |
| 130 | test__clzsi2(0x6E000000, 1); | |
| 131 | test__clzsi2(0x6F000000, 1); | |
| 132 | test__clzsi2(0x70000000, 1); | |
| 133 | test__clzsi2(0x71000000, 1); | |
| 134 | test__clzsi2(0x72000000, 1); | |
| 135 | test__clzsi2(0x73000000, 1); | |
| 136 | test__clzsi2(0x74000000, 1); | |
| 137 | test__clzsi2(0x75000000, 1); | |
| 138 | test__clzsi2(0x76000000, 1); | |
| 139 | test__clzsi2(0x77000000, 1); | |
| 140 | test__clzsi2(0x78000000, 1); | |
| 141 | test__clzsi2(0x79000000, 1); | |
| 142 | test__clzsi2(0x7A000000, 1); | |
| 143 | test__clzsi2(0x7B000000, 1); | |
| 144 | test__clzsi2(0x7C000000, 1); | |
| 145 | test__clzsi2(0x7D000000, 1); | |
| 146 | test__clzsi2(0x7E000000, 1); | |
| 147 | test__clzsi2(0x7F000000, 1); | |
| 148 | test__clzsi2(0x80000000, 0); | |
| 149 | test__clzsi2(0x81000000, 0); | |
| 150 | test__clzsi2(0x82000000, 0); | |
| 151 | test__clzsi2(0x83000000, 0); | |
| 152 | test__clzsi2(0x84000000, 0); | |
| 153 | test__clzsi2(0x85000000, 0); | |
| 154 | test__clzsi2(0x86000000, 0); | |
| 155 | test__clzsi2(0x87000000, 0); | |
| 156 | test__clzsi2(0x88000000, 0); | |
| 157 | test__clzsi2(0x89000000, 0); | |
| 158 | test__clzsi2(0x8A000000, 0); | |
| 159 | test__clzsi2(0x8B000000, 0); | |
| 160 | test__clzsi2(0x8C000000, 0); | |
| 161 | test__clzsi2(0x8D000000, 0); | |
| 162 | test__clzsi2(0x8E000000, 0); | |
| 163 | test__clzsi2(0x8F000000, 0); | |
| 164 | test__clzsi2(0x90000000, 0); | |
| 165 | test__clzsi2(0x91000000, 0); | |
| 166 | test__clzsi2(0x92000000, 0); | |
| 167 | test__clzsi2(0x93000000, 0); | |
| 168 | test__clzsi2(0x94000000, 0); | |
| 169 | test__clzsi2(0x95000000, 0); | |
| 170 | test__clzsi2(0x96000000, 0); | |
| 171 | test__clzsi2(0x97000000, 0); | |
| 172 | test__clzsi2(0x98000000, 0); | |
| 173 | test__clzsi2(0x99000000, 0); | |
| 174 | test__clzsi2(0x9A000000, 0); | |
| 175 | test__clzsi2(0x9B000000, 0); | |
| 176 | test__clzsi2(0x9C000000, 0); | |
| 177 | test__clzsi2(0x9D000000, 0); | |
| 178 | test__clzsi2(0x9E000000, 0); | |
| 179 | test__clzsi2(0x9F000000, 0); | |
| 180 | test__clzsi2(0xA0000000, 0); | |
| 181 | test__clzsi2(0xA1000000, 0); | |
| 182 | test__clzsi2(0xA2000000, 0); | |
| 183 | test__clzsi2(0xA3000000, 0); | |
| 184 | test__clzsi2(0xA4000000, 0); | |
| 185 | test__clzsi2(0xA5000000, 0); | |
| 186 | test__clzsi2(0xA6000000, 0); | |
| 187 | test__clzsi2(0xA7000000, 0); | |
| 188 | test__clzsi2(0xA8000000, 0); | |
| 189 | test__clzsi2(0xA9000000, 0); | |
| 190 | test__clzsi2(0xAA000000, 0); | |
| 191 | test__clzsi2(0xAB000000, 0); | |
| 192 | test__clzsi2(0xAC000000, 0); | |
| 193 | test__clzsi2(0xAD000000, 0); | |
| 194 | test__clzsi2(0xAE000000, 0); | |
| 195 | test__clzsi2(0xAF000000, 0); | |
| 196 | test__clzsi2(0xB0000000, 0); | |
| 197 | test__clzsi2(0xB1000000, 0); | |
| 198 | test__clzsi2(0xB2000000, 0); | |
| 199 | test__clzsi2(0xB3000000, 0); | |
| 200 | test__clzsi2(0xB4000000, 0); | |
| 201 | test__clzsi2(0xB5000000, 0); | |
| 202 | test__clzsi2(0xB6000000, 0); | |
| 203 | test__clzsi2(0xB7000000, 0); | |
| 204 | test__clzsi2(0xB8000000, 0); | |
| 205 | test__clzsi2(0xB9000000, 0); | |
| 206 | test__clzsi2(0xBA000000, 0); | |
| 207 | test__clzsi2(0xBB000000, 0); | |
| 208 | test__clzsi2(0xBC000000, 0); | |
| 209 | test__clzsi2(0xBD000000, 0); | |
| 210 | test__clzsi2(0xBE000000, 0); | |
| 211 | test__clzsi2(0xBF000000, 0); | |
| 212 | test__clzsi2(0xC0000000, 0); | |
| 213 | test__clzsi2(0xC1000000, 0); | |
| 214 | test__clzsi2(0xC2000000, 0); | |
| 215 | test__clzsi2(0xC3000000, 0); | |
| 216 | test__clzsi2(0xC4000000, 0); | |
| 217 | test__clzsi2(0xC5000000, 0); | |
| 218 | test__clzsi2(0xC6000000, 0); | |
| 219 | test__clzsi2(0xC7000000, 0); | |
| 220 | test__clzsi2(0xC8000000, 0); | |
| 221 | test__clzsi2(0xC9000000, 0); | |
| 222 | test__clzsi2(0xCA000000, 0); | |
| 223 | test__clzsi2(0xCB000000, 0); | |
| 224 | test__clzsi2(0xCC000000, 0); | |
| 225 | test__clzsi2(0xCD000000, 0); | |
| 226 | test__clzsi2(0xCE000000, 0); | |
| 227 | test__clzsi2(0xCF000000, 0); | |
| 228 | test__clzsi2(0xD0000000, 0); | |
| 229 | test__clzsi2(0xD1000000, 0); | |
| 230 | test__clzsi2(0xD2000000, 0); | |
| 231 | test__clzsi2(0xD3000000, 0); | |
| 232 | test__clzsi2(0xD4000000, 0); | |
| 233 | test__clzsi2(0xD5000000, 0); | |
| 234 | test__clzsi2(0xD6000000, 0); | |
| 235 | test__clzsi2(0xD7000000, 0); | |
| 236 | test__clzsi2(0xD8000000, 0); | |
| 237 | test__clzsi2(0xD9000000, 0); | |
| 238 | test__clzsi2(0xDA000000, 0); | |
| 239 | test__clzsi2(0xDB000000, 0); | |
| 240 | test__clzsi2(0xDC000000, 0); | |
| 241 | test__clzsi2(0xDD000000, 0); | |
| 242 | test__clzsi2(0xDE000000, 0); | |
| 243 | test__clzsi2(0xDF000000, 0); | |
| 244 | test__clzsi2(0xE0000000, 0); | |
| 245 | test__clzsi2(0xE1000000, 0); | |
| 246 | test__clzsi2(0xE2000000, 0); | |
| 247 | test__clzsi2(0xE3000000, 0); | |
| 248 | test__clzsi2(0xE4000000, 0); | |
| 249 | test__clzsi2(0xE5000000, 0); | |
| 250 | test__clzsi2(0xE6000000, 0); | |
| 251 | test__clzsi2(0xE7000000, 0); | |
| 252 | test__clzsi2(0xE8000000, 0); | |
| 253 | test__clzsi2(0xE9000000, 0); | |
| 254 | test__clzsi2(0xEA000000, 0); | |
| 255 | test__clzsi2(0xEB000000, 0); | |
| 256 | test__clzsi2(0xEC000000, 0); | |
| 257 | test__clzsi2(0xED000000, 0); | |
| 258 | test__clzsi2(0xEE000000, 0); | |
| 259 | test__clzsi2(0xEF000000, 0); | |
| 260 | test__clzsi2(0xF0000000, 0); | |
| 261 | test__clzsi2(0xF1000000, 0); | |
| 262 | test__clzsi2(0xF2000000, 0); | |
| 263 | test__clzsi2(0xF3000000, 0); | |
| 264 | test__clzsi2(0xF4000000, 0); | |
| 265 | test__clzsi2(0xF5000000, 0); | |
| 266 | test__clzsi2(0xF6000000, 0); | |
| 267 | test__clzsi2(0xF7000000, 0); | |
| 268 | test__clzsi2(0xF8000000, 0); | |
| 269 | test__clzsi2(0xF9000000, 0); | |
| 270 | test__clzsi2(0xFA000000, 0); | |
| 271 | test__clzsi2(0xFB000000, 0); | |
| 272 | test__clzsi2(0xFC000000, 0); | |
| 273 | test__clzsi2(0xFD000000, 0); | |
| 274 | test__clzsi2(0xFE000000, 0); | |
| 275 | test__clzsi2(0xFF000000, 0); | |
| 276 | test__clzsi2(0x00000001, 31); | |
| 277 | test__clzsi2(0x00000002, 30); | |
| 278 | test__clzsi2(0x00000004, 29); | |
| 279 | test__clzsi2(0x00000008, 28); | |
| 280 | test__clzsi2(0x00000010, 27); | |
| 281 | test__clzsi2(0x00000020, 26); | |
| 282 | test__clzsi2(0x00000040, 25); | |
| 283 | test__clzsi2(0x00000080, 24); | |
| 284 | test__clzsi2(0x00000100, 23); | |
| 285 | test__clzsi2(0x00000200, 22); | |
| 286 | test__clzsi2(0x00000400, 21); | |
| 287 | test__clzsi2(0x00000800, 20); | |
| 288 | test__clzsi2(0x00001000, 19); | |
| 289 | test__clzsi2(0x00002000, 18); | |
| 290 | test__clzsi2(0x00004000, 17); | |
| 291 | test__clzsi2(0x00008000, 16); | |
| 292 | test__clzsi2(0x00010000, 15); | |
| 293 | test__clzsi2(0x00020000, 14); | |
| 294 | test__clzsi2(0x00040000, 13); | |
| 295 | test__clzsi2(0x00080000, 12); | |
| 296 | test__clzsi2(0x00100000, 11); | |
| 297 | test__clzsi2(0x00200000, 10); | |
| 298 | test__clzsi2(0x00400000, 9); | |
| 20 | try test__clzsi2(0x00800000, 8); | |
| 21 | try test__clzsi2(0x01000000, 7); | |
| 22 | try test__clzsi2(0x02000000, 6); | |
| 23 | try test__clzsi2(0x03000000, 6); | |
| 24 | try test__clzsi2(0x04000000, 5); | |
| 25 | try test__clzsi2(0x05000000, 5); | |
| 26 | try test__clzsi2(0x06000000, 5); | |
| 27 | try test__clzsi2(0x07000000, 5); | |
| 28 | try test__clzsi2(0x08000000, 4); | |
| 29 | try test__clzsi2(0x09000000, 4); | |
| 30 | try test__clzsi2(0x0A000000, 4); | |
| 31 | try test__clzsi2(0x0B000000, 4); | |
| 32 | try test__clzsi2(0x0C000000, 4); | |
| 33 | try test__clzsi2(0x0D000000, 4); | |
| 34 | try test__clzsi2(0x0E000000, 4); | |
| 35 | try test__clzsi2(0x0F000000, 4); | |
| 36 | try test__clzsi2(0x10000000, 3); | |
| 37 | try test__clzsi2(0x11000000, 3); | |
| 38 | try test__clzsi2(0x12000000, 3); | |
| 39 | try test__clzsi2(0x13000000, 3); | |
| 40 | try test__clzsi2(0x14000000, 3); | |
| 41 | try test__clzsi2(0x15000000, 3); | |
| 42 | try test__clzsi2(0x16000000, 3); | |
| 43 | try test__clzsi2(0x17000000, 3); | |
| 44 | try test__clzsi2(0x18000000, 3); | |
| 45 | try test__clzsi2(0x19000000, 3); | |
| 46 | try test__clzsi2(0x1A000000, 3); | |
| 47 | try test__clzsi2(0x1B000000, 3); | |
| 48 | try test__clzsi2(0x1C000000, 3); | |
| 49 | try test__clzsi2(0x1D000000, 3); | |
| 50 | try test__clzsi2(0x1E000000, 3); | |
| 51 | try test__clzsi2(0x1F000000, 3); | |
| 52 | try test__clzsi2(0x20000000, 2); | |
| 53 | try test__clzsi2(0x21000000, 2); | |
| 54 | try test__clzsi2(0x22000000, 2); | |
| 55 | try test__clzsi2(0x23000000, 2); | |
| 56 | try test__clzsi2(0x24000000, 2); | |
| 57 | try test__clzsi2(0x25000000, 2); | |
| 58 | try test__clzsi2(0x26000000, 2); | |
| 59 | try test__clzsi2(0x27000000, 2); | |
| 60 | try test__clzsi2(0x28000000, 2); | |
| 61 | try test__clzsi2(0x29000000, 2); | |
| 62 | try test__clzsi2(0x2A000000, 2); | |
| 63 | try test__clzsi2(0x2B000000, 2); | |
| 64 | try test__clzsi2(0x2C000000, 2); | |
| 65 | try test__clzsi2(0x2D000000, 2); | |
| 66 | try test__clzsi2(0x2E000000, 2); | |
| 67 | try test__clzsi2(0x2F000000, 2); | |
| 68 | try test__clzsi2(0x30000000, 2); | |
| 69 | try test__clzsi2(0x31000000, 2); | |
| 70 | try test__clzsi2(0x32000000, 2); | |
| 71 | try test__clzsi2(0x33000000, 2); | |
| 72 | try test__clzsi2(0x34000000, 2); | |
| 73 | try test__clzsi2(0x35000000, 2); | |
| 74 | try test__clzsi2(0x36000000, 2); | |
| 75 | try test__clzsi2(0x37000000, 2); | |
| 76 | try test__clzsi2(0x38000000, 2); | |
| 77 | try test__clzsi2(0x39000000, 2); | |
| 78 | try test__clzsi2(0x3A000000, 2); | |
| 79 | try test__clzsi2(0x3B000000, 2); | |
| 80 | try test__clzsi2(0x3C000000, 2); | |
| 81 | try test__clzsi2(0x3D000000, 2); | |
| 82 | try test__clzsi2(0x3E000000, 2); | |
| 83 | try test__clzsi2(0x3F000000, 2); | |
| 84 | try test__clzsi2(0x40000000, 1); | |
| 85 | try test__clzsi2(0x41000000, 1); | |
| 86 | try test__clzsi2(0x42000000, 1); | |
| 87 | try test__clzsi2(0x43000000, 1); | |
| 88 | try test__clzsi2(0x44000000, 1); | |
| 89 | try test__clzsi2(0x45000000, 1); | |
| 90 | try test__clzsi2(0x46000000, 1); | |
| 91 | try test__clzsi2(0x47000000, 1); | |
| 92 | try test__clzsi2(0x48000000, 1); | |
| 93 | try test__clzsi2(0x49000000, 1); | |
| 94 | try test__clzsi2(0x4A000000, 1); | |
| 95 | try test__clzsi2(0x4B000000, 1); | |
| 96 | try test__clzsi2(0x4C000000, 1); | |
| 97 | try test__clzsi2(0x4D000000, 1); | |
| 98 | try test__clzsi2(0x4E000000, 1); | |
| 99 | try test__clzsi2(0x4F000000, 1); | |
| 100 | try test__clzsi2(0x50000000, 1); | |
| 101 | try test__clzsi2(0x51000000, 1); | |
| 102 | try test__clzsi2(0x52000000, 1); | |
| 103 | try test__clzsi2(0x53000000, 1); | |
| 104 | try test__clzsi2(0x54000000, 1); | |
| 105 | try test__clzsi2(0x55000000, 1); | |
| 106 | try test__clzsi2(0x56000000, 1); | |
| 107 | try test__clzsi2(0x57000000, 1); | |
| 108 | try test__clzsi2(0x58000000, 1); | |
| 109 | try test__clzsi2(0x59000000, 1); | |
| 110 | try test__clzsi2(0x5A000000, 1); | |
| 111 | try test__clzsi2(0x5B000000, 1); | |
| 112 | try test__clzsi2(0x5C000000, 1); | |
| 113 | try test__clzsi2(0x5D000000, 1); | |
| 114 | try test__clzsi2(0x5E000000, 1); | |
| 115 | try test__clzsi2(0x5F000000, 1); | |
| 116 | try test__clzsi2(0x60000000, 1); | |
| 117 | try test__clzsi2(0x61000000, 1); | |
| 118 | try test__clzsi2(0x62000000, 1); | |
| 119 | try test__clzsi2(0x63000000, 1); | |
| 120 | try test__clzsi2(0x64000000, 1); | |
| 121 | try test__clzsi2(0x65000000, 1); | |
| 122 | try test__clzsi2(0x66000000, 1); | |
| 123 | try test__clzsi2(0x67000000, 1); | |
| 124 | try test__clzsi2(0x68000000, 1); | |
| 125 | try test__clzsi2(0x69000000, 1); | |
| 126 | try test__clzsi2(0x6A000000, 1); | |
| 127 | try test__clzsi2(0x6B000000, 1); | |
| 128 | try test__clzsi2(0x6C000000, 1); | |
| 129 | try test__clzsi2(0x6D000000, 1); | |
| 130 | try test__clzsi2(0x6E000000, 1); | |
| 131 | try test__clzsi2(0x6F000000, 1); | |
| 132 | try test__clzsi2(0x70000000, 1); | |
| 133 | try test__clzsi2(0x71000000, 1); | |
| 134 | try test__clzsi2(0x72000000, 1); | |
| 135 | try test__clzsi2(0x73000000, 1); | |
| 136 | try test__clzsi2(0x74000000, 1); | |
| 137 | try test__clzsi2(0x75000000, 1); | |
| 138 | try test__clzsi2(0x76000000, 1); | |
| 139 | try test__clzsi2(0x77000000, 1); | |
| 140 | try test__clzsi2(0x78000000, 1); | |
| 141 | try test__clzsi2(0x79000000, 1); | |
| 142 | try test__clzsi2(0x7A000000, 1); | |
| 143 | try test__clzsi2(0x7B000000, 1); | |
| 144 | try test__clzsi2(0x7C000000, 1); | |
| 145 | try test__clzsi2(0x7D000000, 1); | |
| 146 | try test__clzsi2(0x7E000000, 1); | |
| 147 | try test__clzsi2(0x7F000000, 1); | |
| 148 | try test__clzsi2(0x80000000, 0); | |
| 149 | try test__clzsi2(0x81000000, 0); | |
| 150 | try test__clzsi2(0x82000000, 0); | |
| 151 | try test__clzsi2(0x83000000, 0); | |
| 152 | try test__clzsi2(0x84000000, 0); | |
| 153 | try test__clzsi2(0x85000000, 0); | |
| 154 | try test__clzsi2(0x86000000, 0); | |
| 155 | try test__clzsi2(0x87000000, 0); | |
| 156 | try test__clzsi2(0x88000000, 0); | |
| 157 | try test__clzsi2(0x89000000, 0); | |
| 158 | try test__clzsi2(0x8A000000, 0); | |
| 159 | try test__clzsi2(0x8B000000, 0); | |
| 160 | try test__clzsi2(0x8C000000, 0); | |
| 161 | try test__clzsi2(0x8D000000, 0); | |
| 162 | try test__clzsi2(0x8E000000, 0); | |
| 163 | try test__clzsi2(0x8F000000, 0); | |
| 164 | try test__clzsi2(0x90000000, 0); | |
| 165 | try test__clzsi2(0x91000000, 0); | |
| 166 | try test__clzsi2(0x92000000, 0); | |
| 167 | try test__clzsi2(0x93000000, 0); | |
| 168 | try test__clzsi2(0x94000000, 0); | |
| 169 | try test__clzsi2(0x95000000, 0); | |
| 170 | try test__clzsi2(0x96000000, 0); | |
| 171 | try test__clzsi2(0x97000000, 0); | |
| 172 | try test__clzsi2(0x98000000, 0); | |
| 173 | try test__clzsi2(0x99000000, 0); | |
| 174 | try test__clzsi2(0x9A000000, 0); | |
| 175 | try test__clzsi2(0x9B000000, 0); | |
| 176 | try test__clzsi2(0x9C000000, 0); | |
| 177 | try test__clzsi2(0x9D000000, 0); | |
| 178 | try test__clzsi2(0x9E000000, 0); | |
| 179 | try test__clzsi2(0x9F000000, 0); | |
| 180 | try test__clzsi2(0xA0000000, 0); | |
| 181 | try test__clzsi2(0xA1000000, 0); | |
| 182 | try test__clzsi2(0xA2000000, 0); | |
| 183 | try test__clzsi2(0xA3000000, 0); | |
| 184 | try test__clzsi2(0xA4000000, 0); | |
| 185 | try test__clzsi2(0xA5000000, 0); | |
| 186 | try test__clzsi2(0xA6000000, 0); | |
| 187 | try test__clzsi2(0xA7000000, 0); | |
| 188 | try test__clzsi2(0xA8000000, 0); | |
| 189 | try test__clzsi2(0xA9000000, 0); | |
| 190 | try test__clzsi2(0xAA000000, 0); | |
| 191 | try test__clzsi2(0xAB000000, 0); | |
| 192 | try test__clzsi2(0xAC000000, 0); | |
| 193 | try test__clzsi2(0xAD000000, 0); | |
| 194 | try test__clzsi2(0xAE000000, 0); | |
| 195 | try test__clzsi2(0xAF000000, 0); | |
| 196 | try test__clzsi2(0xB0000000, 0); | |
| 197 | try test__clzsi2(0xB1000000, 0); | |
| 198 | try test__clzsi2(0xB2000000, 0); | |
| 199 | try test__clzsi2(0xB3000000, 0); | |
| 200 | try test__clzsi2(0xB4000000, 0); | |
| 201 | try test__clzsi2(0xB5000000, 0); | |
| 202 | try test__clzsi2(0xB6000000, 0); | |
| 203 | try test__clzsi2(0xB7000000, 0); | |
| 204 | try test__clzsi2(0xB8000000, 0); | |
| 205 | try test__clzsi2(0xB9000000, 0); | |
| 206 | try test__clzsi2(0xBA000000, 0); | |
| 207 | try test__clzsi2(0xBB000000, 0); | |
| 208 | try test__clzsi2(0xBC000000, 0); | |
| 209 | try test__clzsi2(0xBD000000, 0); | |
| 210 | try test__clzsi2(0xBE000000, 0); | |
| 211 | try test__clzsi2(0xBF000000, 0); | |
| 212 | try test__clzsi2(0xC0000000, 0); | |
| 213 | try test__clzsi2(0xC1000000, 0); | |
| 214 | try test__clzsi2(0xC2000000, 0); | |
| 215 | try test__clzsi2(0xC3000000, 0); | |
| 216 | try test__clzsi2(0xC4000000, 0); | |
| 217 | try test__clzsi2(0xC5000000, 0); | |
| 218 | try test__clzsi2(0xC6000000, 0); | |
| 219 | try test__clzsi2(0xC7000000, 0); | |
| 220 | try test__clzsi2(0xC8000000, 0); | |
| 221 | try test__clzsi2(0xC9000000, 0); | |
| 222 | try test__clzsi2(0xCA000000, 0); | |
| 223 | try test__clzsi2(0xCB000000, 0); | |
| 224 | try test__clzsi2(0xCC000000, 0); | |
| 225 | try test__clzsi2(0xCD000000, 0); | |
| 226 | try test__clzsi2(0xCE000000, 0); | |
| 227 | try test__clzsi2(0xCF000000, 0); | |
| 228 | try test__clzsi2(0xD0000000, 0); | |
| 229 | try test__clzsi2(0xD1000000, 0); | |
| 230 | try test__clzsi2(0xD2000000, 0); | |
| 231 | try test__clzsi2(0xD3000000, 0); | |
| 232 | try test__clzsi2(0xD4000000, 0); | |
| 233 | try test__clzsi2(0xD5000000, 0); | |
| 234 | try test__clzsi2(0xD6000000, 0); | |
| 235 | try test__clzsi2(0xD7000000, 0); | |
| 236 | try test__clzsi2(0xD8000000, 0); | |
| 237 | try test__clzsi2(0xD9000000, 0); | |
| 238 | try test__clzsi2(0xDA000000, 0); | |
| 239 | try test__clzsi2(0xDB000000, 0); | |
| 240 | try test__clzsi2(0xDC000000, 0); | |
| 241 | try test__clzsi2(0xDD000000, 0); | |
| 242 | try test__clzsi2(0xDE000000, 0); | |
| 243 | try test__clzsi2(0xDF000000, 0); | |
| 244 | try test__clzsi2(0xE0000000, 0); | |
| 245 | try test__clzsi2(0xE1000000, 0); | |
| 246 | try test__clzsi2(0xE2000000, 0); | |
| 247 | try test__clzsi2(0xE3000000, 0); | |
| 248 | try test__clzsi2(0xE4000000, 0); | |
| 249 | try test__clzsi2(0xE5000000, 0); | |
| 250 | try test__clzsi2(0xE6000000, 0); | |
| 251 | try test__clzsi2(0xE7000000, 0); | |
| 252 | try test__clzsi2(0xE8000000, 0); | |
| 253 | try test__clzsi2(0xE9000000, 0); | |
| 254 | try test__clzsi2(0xEA000000, 0); | |
| 255 | try test__clzsi2(0xEB000000, 0); | |
| 256 | try test__clzsi2(0xEC000000, 0); | |
| 257 | try test__clzsi2(0xED000000, 0); | |
| 258 | try test__clzsi2(0xEE000000, 0); | |
| 259 | try test__clzsi2(0xEF000000, 0); | |
| 260 | try test__clzsi2(0xF0000000, 0); | |
| 261 | try test__clzsi2(0xF1000000, 0); | |
| 262 | try test__clzsi2(0xF2000000, 0); | |
| 263 | try test__clzsi2(0xF3000000, 0); | |
| 264 | try test__clzsi2(0xF4000000, 0); | |
| 265 | try test__clzsi2(0xF5000000, 0); | |
| 266 | try test__clzsi2(0xF6000000, 0); | |
| 267 | try test__clzsi2(0xF7000000, 0); | |
| 268 | try test__clzsi2(0xF8000000, 0); | |
| 269 | try test__clzsi2(0xF9000000, 0); | |
| 270 | try test__clzsi2(0xFA000000, 0); | |
| 271 | try test__clzsi2(0xFB000000, 0); | |
| 272 | try test__clzsi2(0xFC000000, 0); | |
| 273 | try test__clzsi2(0xFD000000, 0); | |
| 274 | try test__clzsi2(0xFE000000, 0); | |
| 275 | try test__clzsi2(0xFF000000, 0); | |
| 276 | try test__clzsi2(0x00000001, 31); | |
| 277 | try test__clzsi2(0x00000002, 30); | |
| 278 | try test__clzsi2(0x00000004, 29); | |
| 279 | try test__clzsi2(0x00000008, 28); | |
| 280 | try test__clzsi2(0x00000010, 27); | |
| 281 | try test__clzsi2(0x00000020, 26); | |
| 282 | try test__clzsi2(0x00000040, 25); | |
| 283 | try test__clzsi2(0x00000080, 24); | |
| 284 | try test__clzsi2(0x00000100, 23); | |
| 285 | try test__clzsi2(0x00000200, 22); | |
| 286 | try test__clzsi2(0x00000400, 21); | |
| 287 | try test__clzsi2(0x00000800, 20); | |
| 288 | try test__clzsi2(0x00001000, 19); | |
| 289 | try test__clzsi2(0x00002000, 18); | |
| 290 | try test__clzsi2(0x00004000, 17); | |
| 291 | try test__clzsi2(0x00008000, 16); | |
| 292 | try test__clzsi2(0x00010000, 15); | |
| 293 | try test__clzsi2(0x00020000, 14); | |
| 294 | try test__clzsi2(0x00040000, 13); | |
| 295 | try test__clzsi2(0x00080000, 12); | |
| 296 | try test__clzsi2(0x00100000, 11); | |
| 297 | try test__clzsi2(0x00200000, 10); | |
| 298 | try test__clzsi2(0x00400000, 9); | |
| 299 | 299 | } |
lib/std/special/compiler_rt/comparedf2_test.zig+1-1| ... | ... | @@ -101,6 +101,6 @@ const test_vectors = init: { |
| 101 | 101 | |
| 102 | 102 | test "compare f64" { |
| 103 | 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 | 101 | |
| 102 | 102 | test "compare f32" { |
| 103 | 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 | 27 | return false; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | fn test__divdf3(a: f64, b: f64, expected: u64) void { | |
| 30 | fn test__divdf3(a: f64, b: f64, expected: u64) !void { | |
| 31 | 31 | const x = __divdf3(a, b); |
| 32 | 32 | const ret = compareResultD(x, expected); |
| 33 | testing.expect(ret == true); | |
| 33 | try testing.expect(ret == true); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | test "divdf3" { |
| 37 | test__divdf3(1.0, 3.0, 0x3fd5555555555555); | |
| 38 | test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000); | |
| 37 | try test__divdf3(1.0, 3.0, 0x3fd5555555555555); | |
| 38 | try test__divdf3(4.450147717014403e-308, 2.0, 0x10000000000000); | |
| 39 | 39 | } |
lib/std/special/compiler_rt/divsf3_test.zig+4-4| ... | ... | @@ -27,13 +27,13 @@ fn compareResultF(result: f32, expected: u32) bool { |
| 27 | 27 | return false; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | fn test__divsf3(a: f32, b: f32, expected: u32) void { | |
| 30 | fn test__divsf3(a: f32, b: f32, expected: u32) !void { | |
| 31 | 31 | const x = __divsf3(a, b); |
| 32 | 32 | const ret = compareResultF(x, expected); |
| 33 | testing.expect(ret == true); | |
| 33 | try testing.expect(ret == true); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | test "divsf3" { |
| 37 | test__divsf3(1.0, 3.0, 0x3EAAAAAB); | |
| 38 | test__divsf3(2.3509887e-38, 2.0, 0x00800000); | |
| 37 | try test__divsf3(1.0, 3.0, 0x3EAAAAAB); | |
| 38 | try test__divsf3(2.3509887e-38, 2.0, 0x00800000); | |
| 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 | 28 | return false; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) void { | |
| 31 | fn test__divtf3(a: f128, b: f128, expectedHi: u64, expectedLo: u64) !void { | |
| 32 | 32 | const x = __divtf3(a, b); |
| 33 | 33 | const ret = compareResultLD(x, expectedHi, expectedLo); |
| 34 | testing.expect(ret == true); | |
| 34 | try testing.expect(ret == true); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test "divtf3" { |
| 38 | 38 | // 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 | 40 | // 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 | 42 | // 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); | |
| 44 | 44 | |
| 45 | test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2); | |
| 46 | test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2); | |
| 47 | test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac); | |
| 48 | test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252); | |
| 49 | test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078); | |
| 50 | test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0); | |
| 45 | try test__divtf3(0x1.a23b45362464523375893ab4cdefp+5, 0x1.eedcbaba3a94546558237654321fp-1, 0x4004b0b72924d407, 0x0717e84356c6eba2); | |
| 46 | try test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50, 0x1.ed2c3ba15935332532287654321fp-9, 0x3fd5b2af3f828c9b, 0x40e51f64cde8b1f2); | |
| 47 | try test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456, 0x1.edacbba9874f765463544dd3621fp+6400, 0x28c62e15dc464466, 0xb5a07586348557ac); | |
| 48 | try test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234, 0x1.eddcdba39f3c8b7a36564354321fp-4455, 0x507b38442b539266, 0x22ce0f1d024e1252); | |
| 49 | try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078); | |
| 50 | try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0); | |
| 51 | 51 | } |
lib/std/special/compiler_rt/divti3_test.zig+12-12| ... | ... | @@ -6,21 +6,21 @@ |
| 6 | 6 | const __divti3 = @import("divti3.zig").__divti3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__divti3(a: i128, b: i128, expected: i128) void { | |
| 9 | fn test__divti3(a: i128, b: i128, expected: i128) !void { | |
| 10 | 10 | const x = __divti3(a, b); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "divti3" { |
| 15 | test__divti3(0, 1, 0); | |
| 16 | test__divti3(0, -1, 0); | |
| 17 | test__divti3(2, 1, 2); | |
| 18 | test__divti3(2, -1, -2); | |
| 19 | test__divti3(-2, 1, -2); | |
| 20 | test__divti3(-2, -1, 2); | |
| 15 | try test__divti3(0, 1, 0); | |
| 16 | try test__divti3(0, -1, 0); | |
| 17 | try test__divti3(2, 1, 2); | |
| 18 | try test__divti3(2, -1, -2); | |
| 19 | try test__divti3(-2, 1, -2); | |
| 20 | try test__divti3(-2, -1, 2); | |
| 21 | 21 | |
| 22 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124))); | |
| 23 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124))); | |
| 24 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124))); | |
| 25 | test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124))); | |
| 22 | try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124))); | |
| 23 | try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124))); | |
| 24 | try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124))); | |
| 25 | try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124))); | |
| 26 | 26 | } |
lib/std/special/compiler_rt/emutls.zig+11-11| ... | ... | @@ -339,12 +339,12 @@ test "simple_allocator" { |
| 339 | 339 | |
| 340 | 340 | test "__emutls_get_address zeroed" { |
| 341 | 341 | var ctl = emutls_control.init(usize, null); |
| 342 | expect(ctl.object.index == 0); | |
| 342 | try expect(ctl.object.index == 0); | |
| 343 | 343 | |
| 344 | 344 | // retrieve a variable from ctl |
| 345 | 345 | var x = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl))); |
| 346 | expect(ctl.object.index != 0); // index has been allocated for this ctl | |
| 347 | expect(x.* == 0); // storage has been zeroed | |
| 346 | try expect(ctl.object.index != 0); // index has been allocated for this ctl | |
| 347 | try expect(x.* == 0); // storage has been zeroed | |
| 348 | 348 | |
| 349 | 349 | // modify the storage |
| 350 | 350 | x.* = 1234; |
| ... | ... | @@ -352,26 +352,26 @@ test "__emutls_get_address zeroed" { |
| 352 | 352 | // retrieve a variable from ctl (same ctl) |
| 353 | 353 | var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl))); |
| 354 | 354 | |
| 355 | expect(y.* == 1234); // same content that x.* | |
| 356 | expect(x == y); // same pointer | |
| 355 | try expect(y.* == 1234); // same content that x.* | |
| 356 | try expect(x == y); // same pointer | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | test "__emutls_get_address with default_value" { |
| 360 | 360 | var value: usize = 5678; // default value |
| 361 | 361 | var ctl = emutls_control.init(usize, &value); |
| 362 | expect(ctl.object.index == 0); | |
| 362 | try expect(ctl.object.index == 0); | |
| 363 | 363 | |
| 364 | 364 | var x: *usize = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl))); |
| 365 | expect(ctl.object.index != 0); | |
| 366 | expect(x.* == 5678); // storage initialized with default value | |
| 365 | try expect(ctl.object.index != 0); | |
| 366 | try expect(x.* == 5678); // storage initialized with default value | |
| 367 | 367 | |
| 368 | 368 | // modify the storage |
| 369 | 369 | x.* = 9012; |
| 370 | 370 | |
| 371 | expect(value == 5678); // the default value didn't change | |
| 371 | try expect(value == 5678); // the default value didn't change | |
| 372 | 372 | |
| 373 | 373 | var y = @ptrCast(*usize, @alignCast(@alignOf(usize), __emutls_get_address(&ctl))); |
| 374 | expect(y.* == 9012); // the modified storage persists | |
| 374 | try expect(y.* == 9012); // the modified storage persists | |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | test "test default_value with differents sizes" { |
| ... | ... | @@ -380,7 +380,7 @@ test "test default_value with differents sizes" { |
| 380 | 380 | var def: T = value; |
| 381 | 381 | var ctl = emutls_control.init(T, &def); |
| 382 | 382 | var x = ctl.get_typed_pointer(T); |
| 383 | expect(x.* == value); | |
| 383 | try expect(x.* == value); | |
| 384 | 384 | } |
| 385 | 385 | }._testType; |
| 386 | 386 |
lib/std/special/compiler_rt/extendXfYf2_test.zig+55-55| ... | ... | @@ -9,7 +9,7 @@ const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2; |
| 9 | 9 | const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2; |
| 10 | 10 | const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2; |
| 11 | 11 | |
| 12 | fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void { | |
| 12 | fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) !void { | |
| 13 | 13 | const x = __extenddftf2(a); |
| 14 | 14 | |
| 15 | 15 | const rep = @bitCast(u128, x); |
| ... | ... | @@ -31,7 +31,7 @@ fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void { |
| 31 | 31 | @panic("__extenddftf2 test failure"); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | fn test__extendhfsf2(a: u16, expected: u32) void { | |
| 34 | fn test__extendhfsf2(a: u16, expected: u32) !void { | |
| 35 | 35 | const x = __extendhfsf2(a); |
| 36 | 36 | const rep = @bitCast(u32, x); |
| 37 | 37 | |
| ... | ... | @@ -44,10 +44,10 @@ fn test__extendhfsf2(a: u16, expected: u32) void { |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | @panic("__extendhfsf2 test failure"); | |
| 47 | return error.TestFailure; | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void { | |
| 50 | fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) !void { | |
| 51 | 51 | const x = __extendsftf2(a); |
| 52 | 52 | |
| 53 | 53 | const rep = @bitCast(u128, x); |
| ... | ... | @@ -66,77 +66,77 @@ fn test__extendsftf2(a: f32, expectedHi: u64, expectedLo: u64) void { |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | @panic("__extendsftf2 test failure"); | |
| 69 | return error.TestFailure; | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | test "extenddftf2" { |
| 73 | 73 | // qNaN |
| 74 | test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0); | |
| 74 | try test__extenddftf2(makeQNaN64(), 0x7fff800000000000, 0x0); | |
| 75 | 75 | |
| 76 | 76 | // NaN |
| 77 | test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0); | |
| 77 | try test__extenddftf2(makeNaN64(0x7100000000000), 0x7fff710000000000, 0x0); | |
| 78 | 78 | |
| 79 | 79 | // inf |
| 80 | test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0); | |
| 80 | try test__extenddftf2(makeInf64(), 0x7fff000000000000, 0x0); | |
| 81 | 81 | |
| 82 | 82 | // zero |
| 83 | test__extenddftf2(0.0, 0x0, 0x0); | |
| 83 | try test__extenddftf2(0.0, 0x0, 0x0); | |
| 84 | 84 | |
| 85 | test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000); | |
| 85 | try test__extenddftf2(0x1.23456789abcdefp+5, 0x400423456789abcd, 0xf000000000000000); | |
| 86 | 86 | |
| 87 | test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000); | |
| 87 | try test__extenddftf2(0x1.edcba987654321fp-9, 0x3ff6edcba9876543, 0x2000000000000000); | |
| 88 | 88 | |
| 89 | test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000); | |
| 89 | try test__extenddftf2(0x1.23456789abcdefp+45, 0x402c23456789abcd, 0xf000000000000000); | |
| 90 | 90 | |
| 91 | test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000); | |
| 91 | try test__extenddftf2(0x1.edcba987654321fp-45, 0x3fd2edcba9876543, 0x2000000000000000); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "extendhfsf2" { |
| 95 | test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN | |
| 96 | test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN | |
| 95 | try test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN | |
| 96 | try test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN | |
| 97 | 97 | // On x86 the NaN becomes quiet because the return is pushed on the x87 |
| 98 | 98 | // stack due to ABI requirements |
| 99 | 99 | if (builtin.arch != .i386 and builtin.os.tag == .windows) |
| 100 | test__extendhfsf2(0x7c01, 0x7f802000); // sNaN | |
| 100 | try test__extendhfsf2(0x7c01, 0x7f802000); // sNaN | |
| 101 | 101 | |
| 102 | test__extendhfsf2(0, 0); // 0 | |
| 103 | test__extendhfsf2(0x8000, 0x80000000); // -0 | |
| 102 | try test__extendhfsf2(0, 0); // 0 | |
| 103 | try test__extendhfsf2(0x8000, 0x80000000); // -0 | |
| 104 | 104 | |
| 105 | test__extendhfsf2(0x7c00, 0x7f800000); // inf | |
| 106 | test__extendhfsf2(0xfc00, 0xff800000); // -inf | |
| 105 | try test__extendhfsf2(0x7c00, 0x7f800000); // inf | |
| 106 | try test__extendhfsf2(0xfc00, 0xff800000); // -inf | |
| 107 | 107 | |
| 108 | test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24 | |
| 109 | test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24 | |
| 108 | try test__extendhfsf2(0x0001, 0x33800000); // denormal (min), 2**-24 | |
| 109 | try test__extendhfsf2(0x8001, 0xb3800000); // denormal (min), -2**-24 | |
| 110 | 110 | |
| 111 | test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24 | |
| 112 | test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24 | |
| 111 | try test__extendhfsf2(0x03ff, 0x387fc000); // denormal (max), 2**-14 - 2**-24 | |
| 112 | try test__extendhfsf2(0x83ff, 0xb87fc000); // denormal (max), -2**-14 + 2**-24 | |
| 113 | 113 | |
| 114 | test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14 | |
| 115 | test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14 | |
| 114 | try test__extendhfsf2(0x0400, 0x38800000); // normal (min), 2**-14 | |
| 115 | try test__extendhfsf2(0x8400, 0xb8800000); // normal (min), -2**-14 | |
| 116 | 116 | |
| 117 | test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504 | |
| 118 | test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504 | |
| 117 | try test__extendhfsf2(0x7bff, 0x477fe000); // normal (max), 65504 | |
| 118 | try test__extendhfsf2(0xfbff, 0xc77fe000); // normal (max), -65504 | |
| 119 | 119 | |
| 120 | test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10 | |
| 121 | test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10 | |
| 120 | try test__extendhfsf2(0x3c01, 0x3f802000); // normal, 1 + 2**-10 | |
| 121 | try test__extendhfsf2(0xbc01, 0xbf802000); // normal, -1 - 2**-10 | |
| 122 | 122 | |
| 123 | test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3 | |
| 124 | test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3 | |
| 123 | try test__extendhfsf2(0x3555, 0x3eaaa000); // normal, approx. 1/3 | |
| 124 | try test__extendhfsf2(0xb555, 0xbeaaa000); // normal, approx. -1/3 | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | test "extendsftf2" { |
| 128 | 128 | // qNaN |
| 129 | test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0); | |
| 129 | try test__extendsftf2(makeQNaN32(), 0x7fff800000000000, 0x0); | |
| 130 | 130 | // NaN |
| 131 | test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0); | |
| 131 | try test__extendsftf2(makeNaN32(0x410000), 0x7fff820000000000, 0x0); | |
| 132 | 132 | // inf |
| 133 | test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0); | |
| 133 | try test__extendsftf2(makeInf32(), 0x7fff000000000000, 0x0); | |
| 134 | 134 | // zero |
| 135 | test__extendsftf2(0.0, 0x0, 0x0); | |
| 136 | test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0); | |
| 137 | test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0); | |
| 138 | test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0); | |
| 139 | test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0); | |
| 135 | try test__extendsftf2(0.0, 0x0, 0x0); | |
| 136 | try test__extendsftf2(0x1.23456p+5, 0x4004234560000000, 0x0); | |
| 137 | try test__extendsftf2(0x1.edcbap-9, 0x3ff6edcba0000000, 0x0); | |
| 138 | try test__extendsftf2(0x1.23456p+45, 0x402c234560000000, 0x0); | |
| 139 | try test__extendsftf2(0x1.edcbap-45, 0x3fd2edcba0000000, 0x0); | |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | fn makeQNaN64() f64 { |
| ... | ... | @@ -163,7 +163,7 @@ fn makeInf32() f32 { |
| 163 | 163 | return @bitCast(f32, @as(u32, 0x7f800000)); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void { | |
| 166 | fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) !void { | |
| 167 | 167 | const x = __extendhftf2(a); |
| 168 | 168 | |
| 169 | 169 | const rep = @bitCast(u128, x); |
| ... | ... | @@ -182,29 +182,29 @@ fn test__extendhftf2(a: u16, expectedHi: u64, expectedLo: u64) void { |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | @panic("__extendhftf2 test failure"); | |
| 185 | return error.TestFailure; | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | test "extendhftf2" { |
| 189 | 189 | // qNaN |
| 190 | test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0); | |
| 190 | try test__extendhftf2(0x7e00, 0x7fff800000000000, 0x0); | |
| 191 | 191 | // NaN |
| 192 | test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0); | |
| 192 | try test__extendhftf2(0x7d00, 0x7fff400000000000, 0x0); | |
| 193 | 193 | // inf |
| 194 | test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0); | |
| 195 | test__extendhftf2(0xfc00, 0xffff000000000000, 0x0); | |
| 194 | try test__extendhftf2(0x7c00, 0x7fff000000000000, 0x0); | |
| 195 | try test__extendhftf2(0xfc00, 0xffff000000000000, 0x0); | |
| 196 | 196 | // zero |
| 197 | test__extendhftf2(0x0000, 0x0000000000000000, 0x0); | |
| 198 | test__extendhftf2(0x8000, 0x8000000000000000, 0x0); | |
| 197 | try test__extendhftf2(0x0000, 0x0000000000000000, 0x0); | |
| 198 | try test__extendhftf2(0x8000, 0x8000000000000000, 0x0); | |
| 199 | 199 | // denormal |
| 200 | test__extendhftf2(0x0010, 0x3feb000000000000, 0x0); | |
| 201 | test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0); | |
| 202 | test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0); | |
| 200 | try test__extendhftf2(0x0010, 0x3feb000000000000, 0x0); | |
| 201 | try test__extendhftf2(0x0001, 0x3fe7000000000000, 0x0); | |
| 202 | try test__extendhftf2(0x8001, 0xbfe7000000000000, 0x0); | |
| 203 | 203 | |
| 204 | 204 | // pi |
| 205 | test__extendhftf2(0x4248, 0x4000920000000000, 0x0); | |
| 206 | test__extendhftf2(0xc248, 0xc000920000000000, 0x0); | |
| 205 | try test__extendhftf2(0x4248, 0x4000920000000000, 0x0); | |
| 206 | try test__extendhftf2(0xc248, 0xc000920000000000, 0x0); | |
| 207 | 207 | |
| 208 | test__extendhftf2(0x508c, 0x4004230000000000, 0x0); | |
| 209 | test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0); | |
| 208 | try test__extendhftf2(0x508c, 0x4004230000000000, 0x0); | |
| 209 | try test__extendhftf2(0x1bb7, 0x3ff6edc000000000, 0x0); | |
| 210 | 210 | } |
lib/std/special/compiler_rt/fixdfdi_test.zig+42-42| ... | ... | @@ -9,62 +9,62 @@ const math = std.math; |
| 9 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixdfdi(a: f64, expected: i64) void { | |
| 12 | fn test__fixdfdi(a: f64, expected: i64) !void { | |
| 13 | 13 | const x = __fixdfdi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixdfdi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixdfdi(-math.f64_max, math.minInt(i64)); | |
| 20 | try test__fixdfdi(-math.f64_max, math.minInt(i64)); | |
| 21 | 21 | |
| 22 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 22 | try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 24 | 24 | |
| 25 | test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 25 | try test__fixdfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 28 | 28 | |
| 29 | test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | try test__fixdfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | try test__fixdfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | try test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | try test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 33 | 33 | |
| 34 | test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 34 | try test__fixdfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | try test__fixdfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 36 | 36 | |
| 37 | test__fixdfdi(-2.01, -2); | |
| 38 | test__fixdfdi(-2.0, -2); | |
| 39 | test__fixdfdi(-1.99, -1); | |
| 40 | test__fixdfdi(-1.0, -1); | |
| 41 | test__fixdfdi(-0.99, 0); | |
| 42 | test__fixdfdi(-0.5, 0); | |
| 43 | test__fixdfdi(-math.f64_min, 0); | |
| 44 | test__fixdfdi(0.0, 0); | |
| 45 | test__fixdfdi(math.f64_min, 0); | |
| 46 | test__fixdfdi(0.5, 0); | |
| 47 | test__fixdfdi(0.99, 0); | |
| 48 | test__fixdfdi(1.0, 1); | |
| 49 | test__fixdfdi(1.5, 1); | |
| 50 | test__fixdfdi(1.99, 1); | |
| 51 | test__fixdfdi(2.0, 2); | |
| 52 | test__fixdfdi(2.01, 2); | |
| 37 | try test__fixdfdi(-2.01, -2); | |
| 38 | try test__fixdfdi(-2.0, -2); | |
| 39 | try test__fixdfdi(-1.99, -1); | |
| 40 | try test__fixdfdi(-1.0, -1); | |
| 41 | try test__fixdfdi(-0.99, 0); | |
| 42 | try test__fixdfdi(-0.5, 0); | |
| 43 | try test__fixdfdi(-math.f64_min, 0); | |
| 44 | try test__fixdfdi(0.0, 0); | |
| 45 | try test__fixdfdi(math.f64_min, 0); | |
| 46 | try test__fixdfdi(0.5, 0); | |
| 47 | try test__fixdfdi(0.99, 0); | |
| 48 | try test__fixdfdi(1.0, 1); | |
| 49 | try test__fixdfdi(1.5, 1); | |
| 50 | try test__fixdfdi(1.99, 1); | |
| 51 | try test__fixdfdi(2.0, 2); | |
| 52 | try test__fixdfdi(2.01, 2); | |
| 53 | 53 | |
| 54 | test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 54 | try test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | try test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 56 | 56 | |
| 57 | test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 60 | test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 57 | try test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | try test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | try test__fixdfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 60 | try test__fixdfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 61 | 61 | |
| 62 | test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 63 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 64 | test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 62 | try test__fixdfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 63 | try test__fixdfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 64 | try test__fixdfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 65 | 65 | |
| 66 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 67 | test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 66 | try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 67 | try test__fixdfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 68 | 68 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixdfsi(a: f64, expected: i32) void { | |
| 12 | fn test__fixdfsi(a: f64, expected: i32) !void { | |
| 13 | 13 | const x = __fixdfsi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixdfsi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixdfsi(-math.f64_max, math.minInt(i32)); | |
| 20 | try test__fixdfsi(-math.f64_max, math.minInt(i32)); | |
| 21 | 21 | |
| 22 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 22 | try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 24 | 24 | |
| 25 | test__fixdfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 25 | try test__fixdfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 28 | 28 | |
| 29 | test__fixdfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | test__fixdfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | try test__fixdfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | try test__fixdfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | try test__fixdfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | try test__fixdfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 33 | 33 | |
| 34 | test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 34 | try test__fixdfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | try test__fixdfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 36 | 36 | |
| 37 | test__fixdfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 37 | try test__fixdfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | try test__fixdfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | try test__fixdfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | 40 | |
| 41 | test__fixdfsi(-2.01, -2); | |
| 42 | test__fixdfsi(-2.0, -2); | |
| 43 | test__fixdfsi(-1.99, -1); | |
| 44 | test__fixdfsi(-1.0, -1); | |
| 45 | test__fixdfsi(-0.99, 0); | |
| 46 | test__fixdfsi(-0.5, 0); | |
| 47 | test__fixdfsi(-math.f64_min, 0); | |
| 48 | test__fixdfsi(0.0, 0); | |
| 49 | test__fixdfsi(math.f64_min, 0); | |
| 50 | test__fixdfsi(0.5, 0); | |
| 51 | test__fixdfsi(0.99, 0); | |
| 52 | test__fixdfsi(1.0, 1); | |
| 53 | test__fixdfsi(1.5, 1); | |
| 54 | test__fixdfsi(1.99, 1); | |
| 55 | test__fixdfsi(2.0, 2); | |
| 56 | test__fixdfsi(2.01, 2); | |
| 41 | try test__fixdfsi(-2.01, -2); | |
| 42 | try test__fixdfsi(-2.0, -2); | |
| 43 | try test__fixdfsi(-1.99, -1); | |
| 44 | try test__fixdfsi(-1.0, -1); | |
| 45 | try test__fixdfsi(-0.99, 0); | |
| 46 | try test__fixdfsi(-0.5, 0); | |
| 47 | try test__fixdfsi(-math.f64_min, 0); | |
| 48 | try test__fixdfsi(0.0, 0); | |
| 49 | try test__fixdfsi(math.f64_min, 0); | |
| 50 | try test__fixdfsi(0.5, 0); | |
| 51 | try test__fixdfsi(0.99, 0); | |
| 52 | try test__fixdfsi(1.0, 1); | |
| 53 | try test__fixdfsi(1.5, 1); | |
| 54 | try test__fixdfsi(1.99, 1); | |
| 55 | try test__fixdfsi(2.0, 2); | |
| 56 | try test__fixdfsi(2.01, 2); | |
| 57 | 57 | |
| 58 | test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 59 | test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 60 | test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 58 | try test__fixdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 59 | try test__fixdfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 60 | try test__fixdfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 61 | 61 | |
| 62 | test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 63 | test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 62 | try test__fixdfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 63 | try test__fixdfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 64 | 64 | |
| 65 | test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 66 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 67 | test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 68 | test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 65 | try test__fixdfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 66 | try test__fixdfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 67 | try test__fixdfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 68 | try test__fixdfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 69 | 69 | |
| 70 | test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 71 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 72 | test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 70 | try test__fixdfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 71 | try test__fixdfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 72 | try test__fixdfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 73 | 73 | |
| 74 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 75 | test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 74 | try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 75 | try test__fixdfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 76 | 76 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixdfti(a: f64, expected: i128) void { | |
| 12 | fn test__fixdfti(a: f64, expected: i128) !void { | |
| 13 | 13 | const x = __fixdfti(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixdfti" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixdfti(-math.f64_max, math.minInt(i128)); | |
| 20 | try test__fixdfti(-math.f64_max, math.minInt(i128)); | |
| 21 | 21 | |
| 22 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 22 | try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | try test__fixdfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 24 | 24 | |
| 25 | test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 27 | test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 25 | try test__fixdfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | try test__fixdfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 27 | try test__fixdfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 28 | 28 | |
| 29 | test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 30 | test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | try test__fixdfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 30 | try test__fixdfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | try test__fixdfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | try test__fixdfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 33 | 33 | |
| 34 | test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 34 | try test__fixdfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | try test__fixdfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 36 | 36 | |
| 37 | test__fixdfti(-2.01, -2); | |
| 38 | test__fixdfti(-2.0, -2); | |
| 39 | test__fixdfti(-1.99, -1); | |
| 40 | test__fixdfti(-1.0, -1); | |
| 41 | test__fixdfti(-0.99, 0); | |
| 42 | test__fixdfti(-0.5, 0); | |
| 43 | test__fixdfti(-math.f64_min, 0); | |
| 44 | test__fixdfti(0.0, 0); | |
| 45 | test__fixdfti(math.f64_min, 0); | |
| 46 | test__fixdfti(0.5, 0); | |
| 47 | test__fixdfti(0.99, 0); | |
| 48 | test__fixdfti(1.0, 1); | |
| 49 | test__fixdfti(1.5, 1); | |
| 50 | test__fixdfti(1.99, 1); | |
| 51 | test__fixdfti(2.0, 2); | |
| 52 | test__fixdfti(2.01, 2); | |
| 37 | try test__fixdfti(-2.01, -2); | |
| 38 | try test__fixdfti(-2.0, -2); | |
| 39 | try test__fixdfti(-1.99, -1); | |
| 40 | try test__fixdfti(-1.0, -1); | |
| 41 | try test__fixdfti(-0.99, 0); | |
| 42 | try test__fixdfti(-0.5, 0); | |
| 43 | try test__fixdfti(-math.f64_min, 0); | |
| 44 | try test__fixdfti(0.0, 0); | |
| 45 | try test__fixdfti(math.f64_min, 0); | |
| 46 | try test__fixdfti(0.5, 0); | |
| 47 | try test__fixdfti(0.99, 0); | |
| 48 | try test__fixdfti(1.0, 1); | |
| 49 | try test__fixdfti(1.5, 1); | |
| 50 | try test__fixdfti(1.99, 1); | |
| 51 | try test__fixdfti(2.0, 2); | |
| 52 | try test__fixdfti(2.01, 2); | |
| 53 | 53 | |
| 54 | test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 54 | try test__fixdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | try test__fixdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 56 | 56 | |
| 57 | test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 60 | test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 57 | try test__fixdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | try test__fixdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | try test__fixdfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 60 | try test__fixdfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 61 | 61 | |
| 62 | test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 63 | test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 64 | test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 62 | try test__fixdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 63 | try test__fixdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 64 | try test__fixdfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 65 | 65 | |
| 66 | test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 67 | test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 66 | try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 67 | try test__fixdfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 68 | 68 | |
| 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 | 11 | |
| 12 | 12 | const fixint = @import("fixint.zig").fixint; |
| 13 | 13 | |
| 14 | fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) void { | |
| 14 | fn test__fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t, expected: fixint_t) !void { | |
| 15 | 15 | const x = fixint(fp_t, fixint_t, a); |
| 16 | 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 | } |
| 19 | 19 | |
| 20 | 20 | test "fixint.i1" { |
| 21 | test__fixint(f32, i1, -math.inf_f32, -1); | |
| 22 | test__fixint(f32, i1, -math.f32_max, -1); | |
| 23 | test__fixint(f32, i1, -2.0, -1); | |
| 24 | test__fixint(f32, i1, -1.1, -1); | |
| 25 | test__fixint(f32, i1, -1.0, -1); | |
| 26 | test__fixint(f32, i1, -0.9, 0); | |
| 27 | test__fixint(f32, i1, -0.1, 0); | |
| 28 | test__fixint(f32, i1, -math.f32_min, 0); | |
| 29 | test__fixint(f32, i1, -0.0, 0); | |
| 30 | test__fixint(f32, i1, 0.0, 0); | |
| 31 | test__fixint(f32, i1, math.f32_min, 0); | |
| 32 | test__fixint(f32, i1, 0.1, 0); | |
| 33 | test__fixint(f32, i1, 0.9, 0); | |
| 34 | test__fixint(f32, i1, 1.0, 0); | |
| 35 | test__fixint(f32, i1, 2.0, 0); | |
| 36 | test__fixint(f32, i1, math.f32_max, 0); | |
| 37 | test__fixint(f32, i1, math.inf_f32, 0); | |
| 21 | try test__fixint(f32, i1, -math.inf_f32, -1); | |
| 22 | try test__fixint(f32, i1, -math.f32_max, -1); | |
| 23 | try test__fixint(f32, i1, -2.0, -1); | |
| 24 | try test__fixint(f32, i1, -1.1, -1); | |
| 25 | try test__fixint(f32, i1, -1.0, -1); | |
| 26 | try test__fixint(f32, i1, -0.9, 0); | |
| 27 | try test__fixint(f32, i1, -0.1, 0); | |
| 28 | try test__fixint(f32, i1, -math.f32_min, 0); | |
| 29 | try test__fixint(f32, i1, -0.0, 0); | |
| 30 | try test__fixint(f32, i1, 0.0, 0); | |
| 31 | try test__fixint(f32, i1, math.f32_min, 0); | |
| 32 | try test__fixint(f32, i1, 0.1, 0); | |
| 33 | try test__fixint(f32, i1, 0.9, 0); | |
| 34 | try test__fixint(f32, i1, 1.0, 0); | |
| 35 | try test__fixint(f32, i1, 2.0, 0); | |
| 36 | try test__fixint(f32, i1, math.f32_max, 0); | |
| 37 | try test__fixint(f32, i1, math.inf_f32, 0); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "fixint.i2" { |
| 41 | test__fixint(f32, i2, -math.inf_f32, -2); | |
| 42 | test__fixint(f32, i2, -math.f32_max, -2); | |
| 43 | test__fixint(f32, i2, -2.0, -2); | |
| 44 | test__fixint(f32, i2, -1.9, -1); | |
| 45 | test__fixint(f32, i2, -1.1, -1); | |
| 46 | test__fixint(f32, i2, -1.0, -1); | |
| 47 | test__fixint(f32, i2, -0.9, 0); | |
| 48 | test__fixint(f32, i2, -0.1, 0); | |
| 49 | test__fixint(f32, i2, -math.f32_min, 0); | |
| 50 | test__fixint(f32, i2, -0.0, 0); | |
| 51 | test__fixint(f32, i2, 0.0, 0); | |
| 52 | test__fixint(f32, i2, math.f32_min, 0); | |
| 53 | test__fixint(f32, i2, 0.1, 0); | |
| 54 | test__fixint(f32, i2, 0.9, 0); | |
| 55 | test__fixint(f32, i2, 1.0, 1); | |
| 56 | test__fixint(f32, i2, 2.0, 1); | |
| 57 | test__fixint(f32, i2, math.f32_max, 1); | |
| 58 | test__fixint(f32, i2, math.inf_f32, 1); | |
| 41 | try test__fixint(f32, i2, -math.inf_f32, -2); | |
| 42 | try test__fixint(f32, i2, -math.f32_max, -2); | |
| 43 | try test__fixint(f32, i2, -2.0, -2); | |
| 44 | try test__fixint(f32, i2, -1.9, -1); | |
| 45 | try test__fixint(f32, i2, -1.1, -1); | |
| 46 | try test__fixint(f32, i2, -1.0, -1); | |
| 47 | try test__fixint(f32, i2, -0.9, 0); | |
| 48 | try test__fixint(f32, i2, -0.1, 0); | |
| 49 | try test__fixint(f32, i2, -math.f32_min, 0); | |
| 50 | try test__fixint(f32, i2, -0.0, 0); | |
| 51 | try test__fixint(f32, i2, 0.0, 0); | |
| 52 | try test__fixint(f32, i2, math.f32_min, 0); | |
| 53 | try test__fixint(f32, i2, 0.1, 0); | |
| 54 | try test__fixint(f32, i2, 0.9, 0); | |
| 55 | try test__fixint(f32, i2, 1.0, 1); | |
| 56 | try test__fixint(f32, i2, 2.0, 1); | |
| 57 | try test__fixint(f32, i2, math.f32_max, 1); | |
| 58 | try test__fixint(f32, i2, math.inf_f32, 1); | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | test "fixint.i3" { |
| 62 | test__fixint(f32, i3, -math.inf_f32, -4); | |
| 63 | test__fixint(f32, i3, -math.f32_max, -4); | |
| 64 | test__fixint(f32, i3, -4.0, -4); | |
| 65 | test__fixint(f32, i3, -3.0, -3); | |
| 66 | test__fixint(f32, i3, -2.0, -2); | |
| 67 | test__fixint(f32, i3, -1.9, -1); | |
| 68 | test__fixint(f32, i3, -1.1, -1); | |
| 69 | test__fixint(f32, i3, -1.0, -1); | |
| 70 | test__fixint(f32, i3, -0.9, 0); | |
| 71 | test__fixint(f32, i3, -0.1, 0); | |
| 72 | test__fixint(f32, i3, -math.f32_min, 0); | |
| 73 | test__fixint(f32, i3, -0.0, 0); | |
| 74 | test__fixint(f32, i3, 0.0, 0); | |
| 75 | test__fixint(f32, i3, math.f32_min, 0); | |
| 76 | test__fixint(f32, i3, 0.1, 0); | |
| 77 | test__fixint(f32, i3, 0.9, 0); | |
| 78 | test__fixint(f32, i3, 1.0, 1); | |
| 79 | test__fixint(f32, i3, 2.0, 2); | |
| 80 | test__fixint(f32, i3, 3.0, 3); | |
| 81 | test__fixint(f32, i3, 4.0, 3); | |
| 82 | test__fixint(f32, i3, math.f32_max, 3); | |
| 83 | test__fixint(f32, i3, math.inf_f32, 3); | |
| 62 | try test__fixint(f32, i3, -math.inf_f32, -4); | |
| 63 | try test__fixint(f32, i3, -math.f32_max, -4); | |
| 64 | try test__fixint(f32, i3, -4.0, -4); | |
| 65 | try test__fixint(f32, i3, -3.0, -3); | |
| 66 | try test__fixint(f32, i3, -2.0, -2); | |
| 67 | try test__fixint(f32, i3, -1.9, -1); | |
| 68 | try test__fixint(f32, i3, -1.1, -1); | |
| 69 | try test__fixint(f32, i3, -1.0, -1); | |
| 70 | try test__fixint(f32, i3, -0.9, 0); | |
| 71 | try test__fixint(f32, i3, -0.1, 0); | |
| 72 | try test__fixint(f32, i3, -math.f32_min, 0); | |
| 73 | try test__fixint(f32, i3, -0.0, 0); | |
| 74 | try test__fixint(f32, i3, 0.0, 0); | |
| 75 | try test__fixint(f32, i3, math.f32_min, 0); | |
| 76 | try test__fixint(f32, i3, 0.1, 0); | |
| 77 | try test__fixint(f32, i3, 0.9, 0); | |
| 78 | try test__fixint(f32, i3, 1.0, 1); | |
| 79 | try test__fixint(f32, i3, 2.0, 2); | |
| 80 | try test__fixint(f32, i3, 3.0, 3); | |
| 81 | try test__fixint(f32, i3, 4.0, 3); | |
| 82 | try test__fixint(f32, i3, math.f32_max, 3); | |
| 83 | try test__fixint(f32, i3, math.inf_f32, 3); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "fixint.i32" { |
| 87 | test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); | |
| 88 | test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); | |
| 89 | test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32)); | |
| 90 | test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1); | |
| 91 | test__fixint(f64, i32, -2.0, -2); | |
| 92 | test__fixint(f64, i32, -1.9, -1); | |
| 93 | test__fixint(f64, i32, -1.1, -1); | |
| 94 | test__fixint(f64, i32, -1.0, -1); | |
| 95 | test__fixint(f64, i32, -0.9, 0); | |
| 96 | test__fixint(f64, i32, -0.1, 0); | |
| 97 | test__fixint(f64, i32, -math.f32_min, 0); | |
| 98 | test__fixint(f64, i32, -0.0, 0); | |
| 99 | test__fixint(f64, i32, 0.0, 0); | |
| 100 | test__fixint(f64, i32, math.f32_min, 0); | |
| 101 | test__fixint(f64, i32, 0.1, 0); | |
| 102 | test__fixint(f64, i32, 0.9, 0); | |
| 103 | test__fixint(f64, i32, 1.0, 1); | |
| 104 | test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1); | |
| 105 | test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32)); | |
| 106 | test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); | |
| 107 | test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); | |
| 87 | try test__fixint(f64, i32, -math.inf_f64, math.minInt(i32)); | |
| 88 | try test__fixint(f64, i32, -math.f64_max, math.minInt(i32)); | |
| 89 | try test__fixint(f64, i32, @as(f64, math.minInt(i32)), math.minInt(i32)); | |
| 90 | try test__fixint(f64, i32, @as(f64, math.minInt(i32)) + 1, math.minInt(i32) + 1); | |
| 91 | try test__fixint(f64, i32, -2.0, -2); | |
| 92 | try test__fixint(f64, i32, -1.9, -1); | |
| 93 | try test__fixint(f64, i32, -1.1, -1); | |
| 94 | try test__fixint(f64, i32, -1.0, -1); | |
| 95 | try test__fixint(f64, i32, -0.9, 0); | |
| 96 | try test__fixint(f64, i32, -0.1, 0); | |
| 97 | try test__fixint(f64, i32, -math.f32_min, 0); | |
| 98 | try test__fixint(f64, i32, -0.0, 0); | |
| 99 | try test__fixint(f64, i32, 0.0, 0); | |
| 100 | try test__fixint(f64, i32, math.f32_min, 0); | |
| 101 | try test__fixint(f64, i32, 0.1, 0); | |
| 102 | try test__fixint(f64, i32, 0.9, 0); | |
| 103 | try test__fixint(f64, i32, 1.0, 1); | |
| 104 | try test__fixint(f64, i32, @as(f64, math.maxInt(i32)) - 1, math.maxInt(i32) - 1); | |
| 105 | try test__fixint(f64, i32, @as(f64, math.maxInt(i32)), math.maxInt(i32)); | |
| 106 | try test__fixint(f64, i32, math.f64_max, math.maxInt(i32)); | |
| 107 | try test__fixint(f64, i32, math.inf_f64, math.maxInt(i32)); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | test "fixint.i64" { |
| 111 | test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); | |
| 112 | test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); | |
| 113 | test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64)); | |
| 114 | test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64)); | |
| 115 | test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2); | |
| 116 | test__fixint(f64, i64, -2.0, -2); | |
| 117 | test__fixint(f64, i64, -1.9, -1); | |
| 118 | test__fixint(f64, i64, -1.1, -1); | |
| 119 | test__fixint(f64, i64, -1.0, -1); | |
| 120 | test__fixint(f64, i64, -0.9, 0); | |
| 121 | test__fixint(f64, i64, -0.1, 0); | |
| 122 | test__fixint(f64, i64, -math.f32_min, 0); | |
| 123 | test__fixint(f64, i64, -0.0, 0); | |
| 124 | test__fixint(f64, i64, 0.0, 0); | |
| 125 | test__fixint(f64, i64, math.f32_min, 0); | |
| 126 | test__fixint(f64, i64, 0.1, 0); | |
| 127 | test__fixint(f64, i64, 0.9, 0); | |
| 128 | test__fixint(f64, i64, 1.0, 1); | |
| 129 | test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64)); | |
| 130 | test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64)); | |
| 131 | test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); | |
| 132 | test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); | |
| 111 | try test__fixint(f64, i64, -math.inf_f64, math.minInt(i64)); | |
| 112 | try test__fixint(f64, i64, -math.f64_max, math.minInt(i64)); | |
| 113 | try test__fixint(f64, i64, @as(f64, math.minInt(i64)), math.minInt(i64)); | |
| 114 | try test__fixint(f64, i64, @as(f64, math.minInt(i64)) + 1, math.minInt(i64)); | |
| 115 | try test__fixint(f64, i64, @as(f64, math.minInt(i64) / 2), math.minInt(i64) / 2); | |
| 116 | try test__fixint(f64, i64, -2.0, -2); | |
| 117 | try test__fixint(f64, i64, -1.9, -1); | |
| 118 | try test__fixint(f64, i64, -1.1, -1); | |
| 119 | try test__fixint(f64, i64, -1.0, -1); | |
| 120 | try test__fixint(f64, i64, -0.9, 0); | |
| 121 | try test__fixint(f64, i64, -0.1, 0); | |
| 122 | try test__fixint(f64, i64, -math.f32_min, 0); | |
| 123 | try test__fixint(f64, i64, -0.0, 0); | |
| 124 | try test__fixint(f64, i64, 0.0, 0); | |
| 125 | try test__fixint(f64, i64, math.f32_min, 0); | |
| 126 | try test__fixint(f64, i64, 0.1, 0); | |
| 127 | try test__fixint(f64, i64, 0.9, 0); | |
| 128 | try test__fixint(f64, i64, 1.0, 1); | |
| 129 | try test__fixint(f64, i64, @as(f64, math.maxInt(i64)) - 1, math.maxInt(i64)); | |
| 130 | try test__fixint(f64, i64, @as(f64, math.maxInt(i64)), math.maxInt(i64)); | |
| 131 | try test__fixint(f64, i64, math.f64_max, math.maxInt(i64)); | |
| 132 | try test__fixint(f64, i64, math.inf_f64, math.maxInt(i64)); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | test "fixint.i128" { |
| 136 | test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); | |
| 137 | test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); | |
| 138 | test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128)); | |
| 139 | test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128)); | |
| 140 | test__fixint(f64, i128, -2.0, -2); | |
| 141 | test__fixint(f64, i128, -1.9, -1); | |
| 142 | test__fixint(f64, i128, -1.1, -1); | |
| 143 | test__fixint(f64, i128, -1.0, -1); | |
| 144 | test__fixint(f64, i128, -0.9, 0); | |
| 145 | test__fixint(f64, i128, -0.1, 0); | |
| 146 | test__fixint(f64, i128, -math.f32_min, 0); | |
| 147 | test__fixint(f64, i128, -0.0, 0); | |
| 148 | test__fixint(f64, i128, 0.0, 0); | |
| 149 | test__fixint(f64, i128, math.f32_min, 0); | |
| 150 | test__fixint(f64, i128, 0.1, 0); | |
| 151 | test__fixint(f64, i128, 0.9, 0); | |
| 152 | test__fixint(f64, i128, 1.0, 1); | |
| 153 | test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128)); | |
| 154 | test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128)); | |
| 155 | test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); | |
| 156 | test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); | |
| 136 | try test__fixint(f64, i128, -math.inf_f64, math.minInt(i128)); | |
| 137 | try test__fixint(f64, i128, -math.f64_max, math.minInt(i128)); | |
| 138 | try test__fixint(f64, i128, @as(f64, math.minInt(i128)), math.minInt(i128)); | |
| 139 | try test__fixint(f64, i128, @as(f64, math.minInt(i128)) + 1, math.minInt(i128)); | |
| 140 | try test__fixint(f64, i128, -2.0, -2); | |
| 141 | try test__fixint(f64, i128, -1.9, -1); | |
| 142 | try test__fixint(f64, i128, -1.1, -1); | |
| 143 | try test__fixint(f64, i128, -1.0, -1); | |
| 144 | try test__fixint(f64, i128, -0.9, 0); | |
| 145 | try test__fixint(f64, i128, -0.1, 0); | |
| 146 | try test__fixint(f64, i128, -math.f32_min, 0); | |
| 147 | try test__fixint(f64, i128, -0.0, 0); | |
| 148 | try test__fixint(f64, i128, 0.0, 0); | |
| 149 | try test__fixint(f64, i128, math.f32_min, 0); | |
| 150 | try test__fixint(f64, i128, 0.1, 0); | |
| 151 | try test__fixint(f64, i128, 0.9, 0); | |
| 152 | try test__fixint(f64, i128, 1.0, 1); | |
| 153 | try test__fixint(f64, i128, @as(f64, math.maxInt(i128)) - 1, math.maxInt(i128)); | |
| 154 | try test__fixint(f64, i128, @as(f64, math.maxInt(i128)), math.maxInt(i128)); | |
| 155 | try test__fixint(f64, i128, math.f64_max, math.maxInt(i128)); | |
| 156 | try test__fixint(f64, i128, math.inf_f64, math.maxInt(i128)); | |
| 157 | 157 | } |
lib/std/special/compiler_rt/fixsfdi_test.zig+44-44| ... | ... | @@ -9,64 +9,64 @@ const math = std.math; |
| 9 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixsfdi(a: f32, expected: i64) void { | |
| 12 | fn test__fixsfdi(a: f32, expected: i64) !void { | |
| 13 | 13 | const x = __fixsfdi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixsfdi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixsfdi(-math.f32_max, math.minInt(i64)); | |
| 20 | try test__fixsfdi(-math.f32_max, math.minInt(i64)); | |
| 21 | 21 | |
| 22 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 22 | try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 24 | 24 | |
| 25 | test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 25 | try test__fixsfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 28 | 28 | |
| 29 | test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 32 | test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 29 | try test__fixsfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | try test__fixsfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | try test__fixsfdi(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 32 | try test__fixsfdi(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 33 | 33 | |
| 34 | test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 35 | test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 36 | test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 34 | try test__fixsfdi(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 35 | try test__fixsfdi(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 36 | try test__fixsfdi(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 37 | 37 | |
| 38 | test__fixsfdi(-2.01, -2); | |
| 39 | test__fixsfdi(-2.0, -2); | |
| 40 | test__fixsfdi(-1.99, -1); | |
| 41 | test__fixsfdi(-1.0, -1); | |
| 42 | test__fixsfdi(-0.99, 0); | |
| 43 | test__fixsfdi(-0.5, 0); | |
| 44 | test__fixsfdi(-math.f32_min, 0); | |
| 45 | test__fixsfdi(0.0, 0); | |
| 46 | test__fixsfdi(math.f32_min, 0); | |
| 47 | test__fixsfdi(0.5, 0); | |
| 48 | test__fixsfdi(0.99, 0); | |
| 49 | test__fixsfdi(1.0, 1); | |
| 50 | test__fixsfdi(1.5, 1); | |
| 51 | test__fixsfdi(1.99, 1); | |
| 52 | test__fixsfdi(2.0, 2); | |
| 53 | test__fixsfdi(2.01, 2); | |
| 38 | try test__fixsfdi(-2.01, -2); | |
| 39 | try test__fixsfdi(-2.0, -2); | |
| 40 | try test__fixsfdi(-1.99, -1); | |
| 41 | try test__fixsfdi(-1.0, -1); | |
| 42 | try test__fixsfdi(-0.99, 0); | |
| 43 | try test__fixsfdi(-0.5, 0); | |
| 44 | try test__fixsfdi(-math.f32_min, 0); | |
| 45 | try test__fixsfdi(0.0, 0); | |
| 46 | try test__fixsfdi(math.f32_min, 0); | |
| 47 | try test__fixsfdi(0.5, 0); | |
| 48 | try test__fixsfdi(0.99, 0); | |
| 49 | try test__fixsfdi(1.0, 1); | |
| 50 | try test__fixsfdi(1.5, 1); | |
| 51 | try test__fixsfdi(1.99, 1); | |
| 52 | try test__fixsfdi(2.0, 2); | |
| 53 | try test__fixsfdi(2.01, 2); | |
| 54 | 54 | |
| 55 | test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 56 | test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 57 | test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 55 | try test__fixsfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 56 | try test__fixsfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 57 | try test__fixsfdi(0x1.FFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 58 | 58 | |
| 59 | test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF); | |
| 60 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 61 | test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 62 | test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 59 | try test__fixsfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFFFFF); | |
| 60 | try test__fixsfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFFFF); | |
| 61 | try test__fixsfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 62 | try test__fixsfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 63 | 63 | |
| 64 | test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 65 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 66 | test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 64 | try test__fixsfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 65 | try test__fixsfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 66 | try test__fixsfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 67 | 67 | |
| 68 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 69 | test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 68 | try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 69 | try test__fixsfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 70 | 70 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixsfsi(a: f32, expected: i32) void { | |
| 12 | fn test__fixsfsi(a: f32, expected: i32) !void { | |
| 13 | 13 | const x = __fixsfsi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixsfsi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixsfsi(-math.f32_max, math.minInt(i32)); | |
| 20 | try test__fixsfsi(-math.f32_max, math.minInt(i32)); | |
| 21 | 21 | |
| 22 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 22 | try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 24 | 24 | |
| 25 | test__fixsfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 25 | try test__fixsfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 28 | 28 | |
| 29 | test__fixsfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | test__fixsfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | try test__fixsfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | try test__fixsfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | try test__fixsfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | try test__fixsfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 33 | 33 | |
| 34 | test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 34 | try test__fixsfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | try test__fixsfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 36 | 36 | |
| 37 | test__fixsfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000); | |
| 39 | test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | try test__fixsfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | try test__fixsfsi(-0x1.FFFFFFp+30, -0x80000000); | |
| 39 | try test__fixsfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | try test__fixsfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 41 | 41 | |
| 42 | test__fixsfsi(-2.01, -2); | |
| 43 | test__fixsfsi(-2.0, -2); | |
| 44 | test__fixsfsi(-1.99, -1); | |
| 45 | test__fixsfsi(-1.0, -1); | |
| 46 | test__fixsfsi(-0.99, 0); | |
| 47 | test__fixsfsi(-0.5, 0); | |
| 48 | test__fixsfsi(-math.f32_min, 0); | |
| 49 | test__fixsfsi(0.0, 0); | |
| 50 | test__fixsfsi(math.f32_min, 0); | |
| 51 | test__fixsfsi(0.5, 0); | |
| 52 | test__fixsfsi(0.99, 0); | |
| 53 | test__fixsfsi(1.0, 1); | |
| 54 | test__fixsfsi(1.5, 1); | |
| 55 | test__fixsfsi(1.99, 1); | |
| 56 | test__fixsfsi(2.0, 2); | |
| 57 | test__fixsfsi(2.01, 2); | |
| 42 | try test__fixsfsi(-2.01, -2); | |
| 43 | try test__fixsfsi(-2.0, -2); | |
| 44 | try test__fixsfsi(-1.99, -1); | |
| 45 | try test__fixsfsi(-1.0, -1); | |
| 46 | try test__fixsfsi(-0.99, 0); | |
| 47 | try test__fixsfsi(-0.5, 0); | |
| 48 | try test__fixsfsi(-math.f32_min, 0); | |
| 49 | try test__fixsfsi(0.0, 0); | |
| 50 | try test__fixsfsi(math.f32_min, 0); | |
| 51 | try test__fixsfsi(0.5, 0); | |
| 52 | try test__fixsfsi(0.99, 0); | |
| 53 | try test__fixsfsi(1.0, 1); | |
| 54 | try test__fixsfsi(1.5, 1); | |
| 55 | try test__fixsfsi(1.99, 1); | |
| 56 | try test__fixsfsi(2.0, 2); | |
| 57 | try test__fixsfsi(2.01, 2); | |
| 58 | 58 | |
| 59 | test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF); | |
| 62 | test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 59 | try test__fixsfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | try test__fixsfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | try test__fixsfsi(0x1.FFFFFFp+30, 0x7FFFFFFF); | |
| 62 | try test__fixsfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 63 | 63 | |
| 64 | test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 65 | test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 64 | try test__fixsfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 65 | try test__fixsfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 66 | 66 | |
| 67 | test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 68 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 69 | test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 70 | test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 67 | try test__fixsfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 68 | try test__fixsfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 69 | try test__fixsfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 70 | try test__fixsfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 71 | 71 | |
| 72 | test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 73 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 74 | test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 72 | try test__fixsfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 73 | try test__fixsfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 74 | try test__fixsfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 75 | 75 | |
| 76 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 77 | test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 76 | try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 77 | try test__fixsfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 78 | 78 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixsfti(a: f32, expected: i128) void { | |
| 12 | fn test__fixsfti(a: f32, expected: i128) !void { | |
| 13 | 13 | const x = __fixsfti(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixsfti" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixsfti(-math.f32_max, math.minInt(i128)); | |
| 20 | try test__fixsfti(-math.f32_max, math.minInt(i128)); | |
| 21 | 21 | |
| 22 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 22 | try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | try test__fixsfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 24 | 24 | |
| 25 | test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000); | |
| 27 | test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000); | |
| 28 | test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000); | |
| 29 | test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000); | |
| 30 | test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000); | |
| 25 | try test__fixsfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | try test__fixsfti(-0x1.FFFFFFFFFFFFFp+126, -0x80000000000000000000000000000000); | |
| 27 | try test__fixsfti(-0x1.FFFFFFFFFFFFEp+126, -0x80000000000000000000000000000000); | |
| 28 | try test__fixsfti(-0x1.FFFFFF0000000p+126, -0x80000000000000000000000000000000); | |
| 29 | try test__fixsfti(-0x1.FFFFFE0000000p+126, -0x7FFFFF80000000000000000000000000); | |
| 30 | try test__fixsfti(-0x1.FFFFFC0000000p+126, -0x7FFFFF00000000000000000000000000); | |
| 31 | 31 | |
| 32 | test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 33 | test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 34 | test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 35 | test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 32 | try test__fixsfti(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 33 | try test__fixsfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 34 | try test__fixsfti(-0x1.FFFFFFFFFFFFFp+62, -0x8000000000000000); | |
| 35 | try test__fixsfti(-0x1.FFFFFFFFFFFFEp+62, -0x8000000000000000); | |
| 36 | 36 | |
| 37 | test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 38 | test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 39 | test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 37 | try test__fixsfti(-0x1.FFFFFFp+62, -0x8000000000000000); | |
| 38 | try test__fixsfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 39 | try test__fixsfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 40 | 40 | |
| 41 | test__fixsfti(-0x1.000000p+31, -0x80000000); | |
| 42 | test__fixsfti(-0x1.FFFFFFp+30, -0x80000000); | |
| 43 | test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 44 | test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 41 | try test__fixsfti(-0x1.000000p+31, -0x80000000); | |
| 42 | try test__fixsfti(-0x1.FFFFFFp+30, -0x80000000); | |
| 43 | try test__fixsfti(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 44 | try test__fixsfti(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 45 | 45 | |
| 46 | test__fixsfti(-2.01, -2); | |
| 47 | test__fixsfti(-2.0, -2); | |
| 48 | test__fixsfti(-1.99, -1); | |
| 49 | test__fixsfti(-1.0, -1); | |
| 50 | test__fixsfti(-0.99, 0); | |
| 51 | test__fixsfti(-0.5, 0); | |
| 52 | test__fixsfti(-math.f32_min, 0); | |
| 53 | test__fixsfti(0.0, 0); | |
| 54 | test__fixsfti(math.f32_min, 0); | |
| 55 | test__fixsfti(0.5, 0); | |
| 56 | test__fixsfti(0.99, 0); | |
| 57 | test__fixsfti(1.0, 1); | |
| 58 | test__fixsfti(1.5, 1); | |
| 59 | test__fixsfti(1.99, 1); | |
| 60 | test__fixsfti(2.0, 2); | |
| 61 | test__fixsfti(2.01, 2); | |
| 46 | try test__fixsfti(-2.01, -2); | |
| 47 | try test__fixsfti(-2.0, -2); | |
| 48 | try test__fixsfti(-1.99, -1); | |
| 49 | try test__fixsfti(-1.0, -1); | |
| 50 | try test__fixsfti(-0.99, 0); | |
| 51 | try test__fixsfti(-0.5, 0); | |
| 52 | try test__fixsfti(-math.f32_min, 0); | |
| 53 | try test__fixsfti(0.0, 0); | |
| 54 | try test__fixsfti(math.f32_min, 0); | |
| 55 | try test__fixsfti(0.5, 0); | |
| 56 | try test__fixsfti(0.99, 0); | |
| 57 | try test__fixsfti(1.0, 1); | |
| 58 | try test__fixsfti(1.5, 1); | |
| 59 | try test__fixsfti(1.99, 1); | |
| 60 | try test__fixsfti(2.0, 2); | |
| 61 | try test__fixsfti(2.01, 2); | |
| 62 | 62 | |
| 63 | test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 64 | test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 65 | test__fixsfti(0x1.FFFFFFp+30, 0x80000000); | |
| 66 | test__fixsfti(0x1.000000p+31, 0x80000000); | |
| 63 | try test__fixsfti(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 64 | try test__fixsfti(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 65 | try test__fixsfti(0x1.FFFFFFp+30, 0x80000000); | |
| 66 | try test__fixsfti(0x1.000000p+31, 0x80000000); | |
| 67 | 67 | |
| 68 | test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 69 | test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 70 | test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000); | |
| 68 | try test__fixsfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 69 | try test__fixsfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 70 | try test__fixsfti(0x1.FFFFFFp+62, 0x8000000000000000); | |
| 71 | 71 | |
| 72 | test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000); | |
| 73 | test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000); | |
| 74 | test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 75 | test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000); | |
| 72 | try test__fixsfti(0x1.FFFFFFFFFFFFEp+62, 0x8000000000000000); | |
| 73 | try test__fixsfti(0x1.FFFFFFFFFFFFFp+62, 0x8000000000000000); | |
| 74 | try test__fixsfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 75 | try test__fixsfti(0x1.0000000000001p+63, 0x8000000000000000); | |
| 76 | 76 | |
| 77 | test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000); | |
| 78 | test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000); | |
| 79 | test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 80 | test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 81 | test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 82 | test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 77 | try test__fixsfti(0x1.FFFFFC0000000p+126, 0x7FFFFF00000000000000000000000000); | |
| 78 | try test__fixsfti(0x1.FFFFFE0000000p+126, 0x7FFFFF80000000000000000000000000); | |
| 79 | try test__fixsfti(0x1.FFFFFF0000000p+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 80 | try test__fixsfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 81 | try test__fixsfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 82 | try test__fixsfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 83 | 83 | |
| 84 | test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 85 | test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 84 | try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 85 | try test__fixsfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 86 | 86 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixtfdi(a: f128, expected: i64) void { | |
| 12 | fn test__fixtfdi(a: f128, expected: i64) !void { | |
| 13 | 13 | const x = __fixtfdi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixtfdi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixtfdi(-math.f128_max, math.minInt(i64)); | |
| 20 | try test__fixtfdi(-math.f128_max, math.minInt(i64)); | |
| 21 | 21 | |
| 22 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 22 | try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i64)); | |
| 23 | try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+1023, -0x8000000000000000); | |
| 24 | 24 | |
| 25 | test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 25 | try test__fixtfdi(-0x1.0000000000000p+127, -0x8000000000000000); | |
| 26 | try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+126, -0x8000000000000000); | |
| 27 | try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+126, -0x8000000000000000); | |
| 28 | 28 | |
| 29 | test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | try test__fixtfdi(-0x1.0000000000001p+63, -0x8000000000000000); | |
| 30 | try test__fixtfdi(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | try test__fixtfdi(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | try test__fixtfdi(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 33 | 33 | |
| 34 | test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000); | |
| 35 | test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000); | |
| 34 | try test__fixtfdi(-0x1.FFFFFEp+62, -0x7FFFFF8000000000); | |
| 35 | try test__fixtfdi(-0x1.FFFFFCp+62, -0x7FFFFF0000000000); | |
| 36 | 36 | |
| 37 | test__fixtfdi(-0x1.000000p+31, -0x80000000); | |
| 38 | test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | try test__fixtfdi(-0x1.000000p+31, -0x80000000); | |
| 38 | try test__fixtfdi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | try test__fixtfdi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | try test__fixtfdi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 41 | 41 | |
| 42 | test__fixtfdi(-2.01, -2); | |
| 43 | test__fixtfdi(-2.0, -2); | |
| 44 | test__fixtfdi(-1.99, -1); | |
| 45 | test__fixtfdi(-1.0, -1); | |
| 46 | test__fixtfdi(-0.99, 0); | |
| 47 | test__fixtfdi(-0.5, 0); | |
| 48 | test__fixtfdi(-math.f64_min, 0); | |
| 49 | test__fixtfdi(0.0, 0); | |
| 50 | test__fixtfdi(math.f64_min, 0); | |
| 51 | test__fixtfdi(0.5, 0); | |
| 52 | test__fixtfdi(0.99, 0); | |
| 53 | test__fixtfdi(1.0, 1); | |
| 54 | test__fixtfdi(1.5, 1); | |
| 55 | test__fixtfdi(1.99, 1); | |
| 56 | test__fixtfdi(2.0, 2); | |
| 57 | test__fixtfdi(2.01, 2); | |
| 42 | try test__fixtfdi(-2.01, -2); | |
| 43 | try test__fixtfdi(-2.0, -2); | |
| 44 | try test__fixtfdi(-1.99, -1); | |
| 45 | try test__fixtfdi(-1.0, -1); | |
| 46 | try test__fixtfdi(-0.99, 0); | |
| 47 | try test__fixtfdi(-0.5, 0); | |
| 48 | try test__fixtfdi(-math.f64_min, 0); | |
| 49 | try test__fixtfdi(0.0, 0); | |
| 50 | try test__fixtfdi(math.f64_min, 0); | |
| 51 | try test__fixtfdi(0.5, 0); | |
| 52 | try test__fixtfdi(0.99, 0); | |
| 53 | try test__fixtfdi(1.0, 1); | |
| 54 | try test__fixtfdi(1.5, 1); | |
| 55 | try test__fixtfdi(1.99, 1); | |
| 56 | try test__fixtfdi(2.0, 2); | |
| 57 | try test__fixtfdi(2.01, 2); | |
| 58 | 58 | |
| 59 | test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 62 | test__fixtfdi(0x1.000000p+31, 0x80000000); | |
| 59 | try test__fixtfdi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | try test__fixtfdi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | try test__fixtfdi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 62 | try test__fixtfdi(0x1.000000p+31, 0x80000000); | |
| 63 | 63 | |
| 64 | test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 65 | test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 64 | try test__fixtfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 65 | try test__fixtfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 66 | 66 | |
| 67 | test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 68 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 69 | test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 70 | test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 67 | try test__fixtfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 68 | try test__fixtfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 69 | try test__fixtfdi(0x1.0000000000000p+63, 0x7FFFFFFFFFFFFFFF); | |
| 70 | try test__fixtfdi(0x1.0000000000001p+63, 0x7FFFFFFFFFFFFFFF); | |
| 71 | 71 | |
| 72 | test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 73 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 74 | test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 72 | try test__fixtfdi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFFFFF); | |
| 73 | try test__fixtfdi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFFFF); | |
| 74 | try test__fixtfdi(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFF); | |
| 75 | 75 | |
| 76 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 77 | test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 76 | try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFF); | |
| 77 | try test__fixtfdi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i64)); | |
| 78 | 78 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixtfsi(a: f128, expected: i32) void { | |
| 12 | fn test__fixtfsi(a: f128, expected: i32) !void { | |
| 13 | 13 | const x = __fixtfsi(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixtfsi" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixtfsi(-math.f128_max, math.minInt(i32)); | |
| 20 | try test__fixtfsi(-math.f128_max, math.minInt(i32)); | |
| 21 | 21 | |
| 22 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 22 | try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i32)); | |
| 23 | try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000); | |
| 24 | 24 | |
| 25 | test__fixtfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 25 | try test__fixtfsi(-0x1.0000000000000p+127, -0x80000000); | |
| 26 | try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+126, -0x80000000); | |
| 27 | try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+126, -0x80000000); | |
| 28 | 28 | |
| 29 | test__fixtfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | test__fixtfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 29 | try test__fixtfsi(-0x1.0000000000001p+63, -0x80000000); | |
| 30 | try test__fixtfsi(-0x1.0000000000000p+63, -0x80000000); | |
| 31 | try test__fixtfsi(-0x1.FFFFFFFFFFFFFp+62, -0x80000000); | |
| 32 | try test__fixtfsi(-0x1.FFFFFFFFFFFFEp+62, -0x80000000); | |
| 33 | 33 | |
| 34 | test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 34 | try test__fixtfsi(-0x1.FFFFFEp+62, -0x80000000); | |
| 35 | try test__fixtfsi(-0x1.FFFFFCp+62, -0x80000000); | |
| 36 | 36 | |
| 37 | test__fixtfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 37 | try test__fixtfsi(-0x1.000000p+31, -0x80000000); | |
| 38 | try test__fixtfsi(-0x1.FFFFFFp+30, -0x7FFFFFC0); | |
| 39 | try test__fixtfsi(-0x1.FFFFFEp+30, -0x7FFFFF80); | |
| 40 | try test__fixtfsi(-0x1.FFFFFCp+30, -0x7FFFFF00); | |
| 41 | 41 | |
| 42 | test__fixtfsi(-2.01, -2); | |
| 43 | test__fixtfsi(-2.0, -2); | |
| 44 | test__fixtfsi(-1.99, -1); | |
| 45 | test__fixtfsi(-1.0, -1); | |
| 46 | test__fixtfsi(-0.99, 0); | |
| 47 | test__fixtfsi(-0.5, 0); | |
| 48 | test__fixtfsi(-math.f32_min, 0); | |
| 49 | test__fixtfsi(0.0, 0); | |
| 50 | test__fixtfsi(math.f32_min, 0); | |
| 51 | test__fixtfsi(0.5, 0); | |
| 52 | test__fixtfsi(0.99, 0); | |
| 53 | test__fixtfsi(1.0, 1); | |
| 54 | test__fixtfsi(1.5, 1); | |
| 55 | test__fixtfsi(1.99, 1); | |
| 56 | test__fixtfsi(2.0, 2); | |
| 57 | test__fixtfsi(2.01, 2); | |
| 42 | try test__fixtfsi(-2.01, -2); | |
| 43 | try test__fixtfsi(-2.0, -2); | |
| 44 | try test__fixtfsi(-1.99, -1); | |
| 45 | try test__fixtfsi(-1.0, -1); | |
| 46 | try test__fixtfsi(-0.99, 0); | |
| 47 | try test__fixtfsi(-0.5, 0); | |
| 48 | try test__fixtfsi(-math.f32_min, 0); | |
| 49 | try test__fixtfsi(0.0, 0); | |
| 50 | try test__fixtfsi(math.f32_min, 0); | |
| 51 | try test__fixtfsi(0.5, 0); | |
| 52 | try test__fixtfsi(0.99, 0); | |
| 53 | try test__fixtfsi(1.0, 1); | |
| 54 | try test__fixtfsi(1.5, 1); | |
| 55 | try test__fixtfsi(1.99, 1); | |
| 56 | try test__fixtfsi(2.0, 2); | |
| 57 | try test__fixtfsi(2.01, 2); | |
| 58 | 58 | |
| 59 | test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 62 | test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 59 | try test__fixtfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 60 | try test__fixtfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 61 | try test__fixtfsi(0x1.FFFFFFp+30, 0x7FFFFFC0); | |
| 62 | try test__fixtfsi(0x1.000000p+31, 0x7FFFFFFF); | |
| 63 | 63 | |
| 64 | test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 65 | test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 64 | try test__fixtfsi(0x1.FFFFFCp+62, 0x7FFFFFFF); | |
| 65 | try test__fixtfsi(0x1.FFFFFEp+62, 0x7FFFFFFF); | |
| 66 | 66 | |
| 67 | test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 68 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 69 | test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 70 | test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 67 | try test__fixtfsi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFF); | |
| 68 | try test__fixtfsi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFF); | |
| 69 | try test__fixtfsi(0x1.0000000000000p+63, 0x7FFFFFFF); | |
| 70 | try test__fixtfsi(0x1.0000000000001p+63, 0x7FFFFFFF); | |
| 71 | 71 | |
| 72 | test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 73 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 74 | test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 72 | try test__fixtfsi(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFF); | |
| 73 | try test__fixtfsi(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFF); | |
| 74 | try test__fixtfsi(0x1.0000000000000p+127, 0x7FFFFFFF); | |
| 75 | 75 | |
| 76 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 77 | test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 76 | try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFF); | |
| 77 | try test__fixtfsi(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i32)); | |
| 78 | 78 | |
| 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 | 9 | const testing = std.testing; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | |
| 12 | fn test__fixtfti(a: f128, expected: i128) void { | |
| 12 | fn test__fixtfti(a: f128, expected: i128) !void { | |
| 13 | 13 | const x = __fixtfti(a); |
| 14 | 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 | } |
| 17 | 17 | |
| 18 | 18 | test "fixtfti" { |
| 19 | 19 | //warn("\n", .{}); |
| 20 | test__fixtfti(-math.f128_max, math.minInt(i128)); | |
| 20 | try test__fixtfti(-math.f128_max, math.minInt(i128)); | |
| 21 | 21 | |
| 22 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 22 | try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, math.minInt(i128)); | |
| 23 | try test__fixtfti(-0x1.FFFFFFFFFFFFFp+1023, -0x80000000000000000000000000000000); | |
| 24 | 24 | |
| 25 | test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 27 | test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 25 | try test__fixtfti(-0x1.0000000000000p+127, -0x80000000000000000000000000000000); | |
| 26 | try test__fixtfti(-0x1.FFFFFFFFFFFFFp+126, -0x7FFFFFFFFFFFFC000000000000000000); | |
| 27 | try test__fixtfti(-0x1.FFFFFFFFFFFFEp+126, -0x7FFFFFFFFFFFF8000000000000000000); | |
| 28 | 28 | |
| 29 | test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 30 | test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 29 | try test__fixtfti(-0x1.0000000000001p+63, -0x8000000000000800); | |
| 30 | try test__fixtfti(-0x1.0000000000000p+63, -0x8000000000000000); | |
| 31 | try test__fixtfti(-0x1.FFFFFFFFFFFFFp+62, -0x7FFFFFFFFFFFFC00); | |
| 32 | try test__fixtfti(-0x1.FFFFFFFFFFFFEp+62, -0x7FFFFFFFFFFFF800); | |
| 33 | 33 | |
| 34 | test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 34 | try test__fixtfti(-0x1.FFFFFEp+62, -0x7fffff8000000000); | |
| 35 | try test__fixtfti(-0x1.FFFFFCp+62, -0x7fffff0000000000); | |
| 36 | 36 | |
| 37 | test__fixtfti(-2.01, -2); | |
| 38 | test__fixtfti(-2.0, -2); | |
| 39 | test__fixtfti(-1.99, -1); | |
| 40 | test__fixtfti(-1.0, -1); | |
| 41 | test__fixtfti(-0.99, 0); | |
| 42 | test__fixtfti(-0.5, 0); | |
| 43 | test__fixtfti(-math.f128_min, 0); | |
| 44 | test__fixtfti(0.0, 0); | |
| 45 | test__fixtfti(math.f128_min, 0); | |
| 46 | test__fixtfti(0.5, 0); | |
| 47 | test__fixtfti(0.99, 0); | |
| 48 | test__fixtfti(1.0, 1); | |
| 49 | test__fixtfti(1.5, 1); | |
| 50 | test__fixtfti(1.99, 1); | |
| 51 | test__fixtfti(2.0, 2); | |
| 52 | test__fixtfti(2.01, 2); | |
| 37 | try test__fixtfti(-2.01, -2); | |
| 38 | try test__fixtfti(-2.0, -2); | |
| 39 | try test__fixtfti(-1.99, -1); | |
| 40 | try test__fixtfti(-1.0, -1); | |
| 41 | try test__fixtfti(-0.99, 0); | |
| 42 | try test__fixtfti(-0.5, 0); | |
| 43 | try test__fixtfti(-math.f128_min, 0); | |
| 44 | try test__fixtfti(0.0, 0); | |
| 45 | try test__fixtfti(math.f128_min, 0); | |
| 46 | try test__fixtfti(0.5, 0); | |
| 47 | try test__fixtfti(0.99, 0); | |
| 48 | try test__fixtfti(1.0, 1); | |
| 49 | try test__fixtfti(1.5, 1); | |
| 50 | try test__fixtfti(1.99, 1); | |
| 51 | try test__fixtfti(2.0, 2); | |
| 52 | try test__fixtfti(2.01, 2); | |
| 53 | 53 | |
| 54 | test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 54 | try test__fixtfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 55 | try test__fixtfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 56 | 56 | |
| 57 | test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 60 | test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 57 | try test__fixtfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 58 | try test__fixtfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 59 | try test__fixtfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 60 | try test__fixtfti(0x1.0000000000001p+63, 0x8000000000000800); | |
| 61 | 61 | |
| 62 | test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 63 | test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 64 | test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 62 | try test__fixtfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 63 | try test__fixtfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 64 | try test__fixtfti(0x1.0000000000000p+127, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 65 | 65 | |
| 66 | test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 67 | test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 66 | try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 67 | try test__fixtfti(0x1.FFFFFFFFFFFFFp+1023, math.maxInt(i128)); | |
| 68 | 68 | |
| 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 | 6 | const __fixunsdfdi = @import("fixunsdfdi.zig").__fixunsdfdi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunsdfdi(a: f64, expected: u64) void { | |
| 9 | fn test__fixunsdfdi(a: f64, expected: u64) !void { | |
| 10 | 10 | const x = __fixunsdfdi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunsdfdi" { |
| 15 | 15 | //test__fixunsdfdi(0.0, 0); |
| 16 | 16 | //test__fixunsdfdi(0.5, 0); |
| 17 | 17 | //test__fixunsdfdi(0.99, 0); |
| 18 | test__fixunsdfdi(1.0, 1); | |
| 19 | test__fixunsdfdi(1.5, 1); | |
| 20 | test__fixunsdfdi(1.99, 1); | |
| 21 | test__fixunsdfdi(2.0, 2); | |
| 22 | test__fixunsdfdi(2.01, 2); | |
| 23 | test__fixunsdfdi(-0.5, 0); | |
| 24 | test__fixunsdfdi(-0.99, 0); | |
| 25 | test__fixunsdfdi(-1.0, 0); | |
| 26 | test__fixunsdfdi(-1.5, 0); | |
| 27 | test__fixunsdfdi(-1.99, 0); | |
| 28 | test__fixunsdfdi(-2.0, 0); | |
| 29 | test__fixunsdfdi(-2.01, 0); | |
| 18 | try test__fixunsdfdi(1.0, 1); | |
| 19 | try test__fixunsdfdi(1.5, 1); | |
| 20 | try test__fixunsdfdi(1.99, 1); | |
| 21 | try test__fixunsdfdi(2.0, 2); | |
| 22 | try test__fixunsdfdi(2.01, 2); | |
| 23 | try test__fixunsdfdi(-0.5, 0); | |
| 24 | try test__fixunsdfdi(-0.99, 0); | |
| 25 | try test__fixunsdfdi(-1.0, 0); | |
| 26 | try test__fixunsdfdi(-1.5, 0); | |
| 27 | try test__fixunsdfdi(-1.99, 0); | |
| 28 | try test__fixunsdfdi(-2.0, 0); | |
| 29 | try test__fixunsdfdi(-2.01, 0); | |
| 30 | 30 | |
| 31 | test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 32 | test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 31 | try test__fixunsdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 32 | try test__fixunsdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 33 | 33 | |
| 34 | test__fixunsdfdi(-0x1.FFFFFEp+62, 0); | |
| 35 | test__fixunsdfdi(-0x1.FFFFFCp+62, 0); | |
| 34 | try test__fixunsdfdi(-0x1.FFFFFEp+62, 0); | |
| 35 | try test__fixunsdfdi(-0x1.FFFFFCp+62, 0); | |
| 36 | 36 | |
| 37 | test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); | |
| 38 | test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000); | |
| 39 | test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 40 | test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 37 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); | |
| 38 | try test__fixunsdfdi(0x1.0000000000000p+63, 0x8000000000000000); | |
| 39 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 40 | try test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 41 | 41 | |
| 42 | test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 43 | test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 42 | try test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 43 | try test__fixunsdfdi(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 44 | 44 | } |
lib/std/special/compiler_rt/fixunsdfsi_test.zig+27-27| ... | ... | @@ -6,39 +6,39 @@ |
| 6 | 6 | const __fixunsdfsi = @import("fixunsdfsi.zig").__fixunsdfsi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunsdfsi(a: f64, expected: u32) void { | |
| 9 | fn test__fixunsdfsi(a: f64, expected: u32) !void { | |
| 10 | 10 | const x = __fixunsdfsi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunsdfsi" { |
| 15 | test__fixunsdfsi(0.0, 0); | |
| 15 | try test__fixunsdfsi(0.0, 0); | |
| 16 | 16 | |
| 17 | test__fixunsdfsi(0.5, 0); | |
| 18 | test__fixunsdfsi(0.99, 0); | |
| 19 | test__fixunsdfsi(1.0, 1); | |
| 20 | test__fixunsdfsi(1.5, 1); | |
| 21 | test__fixunsdfsi(1.99, 1); | |
| 22 | test__fixunsdfsi(2.0, 2); | |
| 23 | test__fixunsdfsi(2.01, 2); | |
| 24 | test__fixunsdfsi(-0.5, 0); | |
| 25 | test__fixunsdfsi(-0.99, 0); | |
| 26 | test__fixunsdfsi(-1.0, 0); | |
| 27 | test__fixunsdfsi(-1.5, 0); | |
| 28 | test__fixunsdfsi(-1.99, 0); | |
| 29 | test__fixunsdfsi(-2.0, 0); | |
| 30 | test__fixunsdfsi(-2.01, 0); | |
| 17 | try test__fixunsdfsi(0.5, 0); | |
| 18 | try test__fixunsdfsi(0.99, 0); | |
| 19 | try test__fixunsdfsi(1.0, 1); | |
| 20 | try test__fixunsdfsi(1.5, 1); | |
| 21 | try test__fixunsdfsi(1.99, 1); | |
| 22 | try test__fixunsdfsi(2.0, 2); | |
| 23 | try test__fixunsdfsi(2.01, 2); | |
| 24 | try test__fixunsdfsi(-0.5, 0); | |
| 25 | try test__fixunsdfsi(-0.99, 0); | |
| 26 | try test__fixunsdfsi(-1.0, 0); | |
| 27 | try test__fixunsdfsi(-1.5, 0); | |
| 28 | try test__fixunsdfsi(-1.99, 0); | |
| 29 | try test__fixunsdfsi(-2.0, 0); | |
| 30 | try test__fixunsdfsi(-2.01, 0); | |
| 31 | 31 | |
| 32 | test__fixunsdfsi(0x1.000000p+31, 0x80000000); | |
| 33 | test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF); | |
| 34 | test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00); | |
| 35 | test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 36 | test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 32 | try test__fixunsdfsi(0x1.000000p+31, 0x80000000); | |
| 33 | try test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF); | |
| 34 | try test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00); | |
| 35 | try test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 36 | try test__fixunsdfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 37 | 37 | |
| 38 | test__fixunsdfsi(-0x1.FFFFFEp+30, 0); | |
| 39 | test__fixunsdfsi(-0x1.FFFFFCp+30, 0); | |
| 38 | try test__fixunsdfsi(-0x1.FFFFFEp+30, 0); | |
| 39 | try test__fixunsdfsi(-0x1.FFFFFCp+30, 0); | |
| 40 | 40 | |
| 41 | test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF); | |
| 42 | test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF); | |
| 43 | test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE); | |
| 41 | try test__fixunsdfsi(0x1.FFFFFFFEp+31, 0xFFFFFFFF); | |
| 42 | try test__fixunsdfsi(0x1.FFFFFFFC00000p+30, 0x7FFFFFFF); | |
| 43 | try test__fixunsdfsi(0x1.FFFFFFF800000p+30, 0x7FFFFFFE); | |
| 44 | 44 | } |
lib/std/special/compiler_rt/fixunsdfti_test.zig+38-38| ... | ... | @@ -6,46 +6,46 @@ |
| 6 | 6 | const __fixunsdfti = @import("fixunsdfti.zig").__fixunsdfti; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunsdfti(a: f64, expected: u128) void { | |
| 9 | fn test__fixunsdfti(a: f64, expected: u128) !void { | |
| 10 | 10 | const x = __fixunsdfti(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunsdfti" { |
| 15 | test__fixunsdfti(0.0, 0); | |
| 16 | ||
| 17 | test__fixunsdfti(0.5, 0); | |
| 18 | test__fixunsdfti(0.99, 0); | |
| 19 | test__fixunsdfti(1.0, 1); | |
| 20 | test__fixunsdfti(1.5, 1); | |
| 21 | test__fixunsdfti(1.99, 1); | |
| 22 | test__fixunsdfti(2.0, 2); | |
| 23 | test__fixunsdfti(2.01, 2); | |
| 24 | test__fixunsdfti(-0.5, 0); | |
| 25 | test__fixunsdfti(-0.99, 0); | |
| 26 | test__fixunsdfti(-1.0, 0); | |
| 27 | test__fixunsdfti(-1.5, 0); | |
| 28 | test__fixunsdfti(-1.99, 0); | |
| 29 | test__fixunsdfti(-2.0, 0); | |
| 30 | test__fixunsdfti(-2.01, 0); | |
| 31 | ||
| 32 | test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 33 | test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 34 | ||
| 35 | test__fixunsdfti(-0x1.FFFFFEp+62, 0); | |
| 36 | test__fixunsdfti(-0x1.FFFFFCp+62, 0); | |
| 37 | ||
| 38 | test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); | |
| 39 | test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 40 | test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 41 | test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 42 | ||
| 43 | test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000); | |
| 44 | test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000); | |
| 45 | test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 46 | test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 47 | test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 48 | ||
| 49 | test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 50 | test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 15 | try test__fixunsdfti(0.0, 0); | |
| 16 | ||
| 17 | try test__fixunsdfti(0.5, 0); | |
| 18 | try test__fixunsdfti(0.99, 0); | |
| 19 | try test__fixunsdfti(1.0, 1); | |
| 20 | try test__fixunsdfti(1.5, 1); | |
| 21 | try test__fixunsdfti(1.99, 1); | |
| 22 | try test__fixunsdfti(2.0, 2); | |
| 23 | try test__fixunsdfti(2.01, 2); | |
| 24 | try test__fixunsdfti(-0.5, 0); | |
| 25 | try test__fixunsdfti(-0.99, 0); | |
| 26 | try test__fixunsdfti(-1.0, 0); | |
| 27 | try test__fixunsdfti(-1.5, 0); | |
| 28 | try test__fixunsdfti(-1.99, 0); | |
| 29 | try test__fixunsdfti(-2.0, 0); | |
| 30 | try test__fixunsdfti(-2.01, 0); | |
| 31 | ||
| 32 | try test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 33 | try test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 34 | ||
| 35 | try test__fixunsdfti(-0x1.FFFFFEp+62, 0); | |
| 36 | try test__fixunsdfti(-0x1.FFFFFCp+62, 0); | |
| 37 | ||
| 38 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800); | |
| 39 | try test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000); | |
| 40 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 41 | try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 42 | ||
| 43 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, 0xFFFFFFFFFFFFF8000000000000000000); | |
| 44 | try test__fixunsdfti(0x1.0000000000000p+127, 0x80000000000000000000000000000000); | |
| 45 | try test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, 0x7FFFFFFFFFFFFC000000000000000000); | |
| 46 | try test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, 0x7FFFFFFFFFFFF8000000000000000000); | |
| 47 | try test__fixunsdfti(0x1.0000000000000p+128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 48 | ||
| 49 | try test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 50 | try test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 51 | 51 | } |
lib/std/special/compiler_rt/fixunssfdi_test.zig+23-23| ... | ... | @@ -6,35 +6,35 @@ |
| 6 | 6 | const __fixunssfdi = @import("fixunssfdi.zig").__fixunssfdi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunssfdi(a: f32, expected: u64) void { | |
| 9 | fn test__fixunssfdi(a: f32, expected: u64) !void { | |
| 10 | 10 | const x = __fixunssfdi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunssfdi" { |
| 15 | test__fixunssfdi(0.0, 0); | |
| 15 | try test__fixunssfdi(0.0, 0); | |
| 16 | 16 | |
| 17 | test__fixunssfdi(0.5, 0); | |
| 18 | test__fixunssfdi(0.99, 0); | |
| 19 | test__fixunssfdi(1.0, 1); | |
| 20 | test__fixunssfdi(1.5, 1); | |
| 21 | test__fixunssfdi(1.99, 1); | |
| 22 | test__fixunssfdi(2.0, 2); | |
| 23 | test__fixunssfdi(2.01, 2); | |
| 24 | test__fixunssfdi(-0.5, 0); | |
| 25 | test__fixunssfdi(-0.99, 0); | |
| 17 | try test__fixunssfdi(0.5, 0); | |
| 18 | try test__fixunssfdi(0.99, 0); | |
| 19 | try test__fixunssfdi(1.0, 1); | |
| 20 | try test__fixunssfdi(1.5, 1); | |
| 21 | try test__fixunssfdi(1.99, 1); | |
| 22 | try test__fixunssfdi(2.0, 2); | |
| 23 | try test__fixunssfdi(2.01, 2); | |
| 24 | try test__fixunssfdi(-0.5, 0); | |
| 25 | try test__fixunssfdi(-0.99, 0); | |
| 26 | 26 | |
| 27 | test__fixunssfdi(-1.0, 0); | |
| 28 | test__fixunssfdi(-1.5, 0); | |
| 29 | test__fixunssfdi(-1.99, 0); | |
| 30 | test__fixunssfdi(-2.0, 0); | |
| 31 | test__fixunssfdi(-2.01, 0); | |
| 27 | try test__fixunssfdi(-1.0, 0); | |
| 28 | try test__fixunssfdi(-1.5, 0); | |
| 29 | try test__fixunssfdi(-1.99, 0); | |
| 30 | try test__fixunssfdi(-2.0, 0); | |
| 31 | try test__fixunssfdi(-2.01, 0); | |
| 32 | 32 | |
| 33 | test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000); | |
| 34 | test__fixunssfdi(0x1.000000p+63, 0x8000000000000000); | |
| 35 | test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 36 | test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 33 | try test__fixunssfdi(0x1.FFFFFEp+63, 0xFFFFFF0000000000); | |
| 34 | try test__fixunssfdi(0x1.000000p+63, 0x8000000000000000); | |
| 35 | try test__fixunssfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 36 | try test__fixunssfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 37 | 37 | |
| 38 | test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000); | |
| 39 | test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000); | |
| 38 | try test__fixunssfdi(-0x1.FFFFFEp+62, 0x0000000000000000); | |
| 39 | try test__fixunssfdi(-0x1.FFFFFCp+62, 0x0000000000000000); | |
| 40 | 40 | } |
lib/std/special/compiler_rt/fixunssfsi_test.zig+24-24| ... | ... | @@ -6,36 +6,36 @@ |
| 6 | 6 | const __fixunssfsi = @import("fixunssfsi.zig").__fixunssfsi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunssfsi(a: f32, expected: u32) void { | |
| 9 | fn test__fixunssfsi(a: f32, expected: u32) !void { | |
| 10 | 10 | const x = __fixunssfsi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunssfsi" { |
| 15 | test__fixunssfsi(0.0, 0); | |
| 15 | try test__fixunssfsi(0.0, 0); | |
| 16 | 16 | |
| 17 | test__fixunssfsi(0.5, 0); | |
| 18 | test__fixunssfsi(0.99, 0); | |
| 19 | test__fixunssfsi(1.0, 1); | |
| 20 | test__fixunssfsi(1.5, 1); | |
| 21 | test__fixunssfsi(1.99, 1); | |
| 22 | test__fixunssfsi(2.0, 2); | |
| 23 | test__fixunssfsi(2.01, 2); | |
| 24 | test__fixunssfsi(-0.5, 0); | |
| 25 | test__fixunssfsi(-0.99, 0); | |
| 17 | try test__fixunssfsi(0.5, 0); | |
| 18 | try test__fixunssfsi(0.99, 0); | |
| 19 | try test__fixunssfsi(1.0, 1); | |
| 20 | try test__fixunssfsi(1.5, 1); | |
| 21 | try test__fixunssfsi(1.99, 1); | |
| 22 | try test__fixunssfsi(2.0, 2); | |
| 23 | try test__fixunssfsi(2.01, 2); | |
| 24 | try test__fixunssfsi(-0.5, 0); | |
| 25 | try test__fixunssfsi(-0.99, 0); | |
| 26 | 26 | |
| 27 | test__fixunssfsi(-1.0, 0); | |
| 28 | test__fixunssfsi(-1.5, 0); | |
| 29 | test__fixunssfsi(-1.99, 0); | |
| 30 | test__fixunssfsi(-2.0, 0); | |
| 31 | test__fixunssfsi(-2.01, 0); | |
| 27 | try test__fixunssfsi(-1.0, 0); | |
| 28 | try test__fixunssfsi(-1.5, 0); | |
| 29 | try test__fixunssfsi(-1.99, 0); | |
| 30 | try test__fixunssfsi(-2.0, 0); | |
| 31 | try test__fixunssfsi(-2.01, 0); | |
| 32 | 32 | |
| 33 | test__fixunssfsi(0x1.000000p+31, 0x80000000); | |
| 34 | test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF); | |
| 35 | test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00); | |
| 36 | test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 37 | test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 33 | try test__fixunssfsi(0x1.000000p+31, 0x80000000); | |
| 34 | try test__fixunssfsi(0x1.000000p+32, 0xFFFFFFFF); | |
| 35 | try test__fixunssfsi(0x1.FFFFFEp+31, 0xFFFFFF00); | |
| 36 | try test__fixunssfsi(0x1.FFFFFEp+30, 0x7FFFFF80); | |
| 37 | try test__fixunssfsi(0x1.FFFFFCp+30, 0x7FFFFF00); | |
| 38 | 38 | |
| 39 | test__fixunssfsi(-0x1.FFFFFEp+30, 0); | |
| 40 | test__fixunssfsi(-0x1.FFFFFCp+30, 0); | |
| 39 | try test__fixunssfsi(-0x1.FFFFFEp+30, 0); | |
| 40 | try test__fixunssfsi(-0x1.FFFFFCp+30, 0); | |
| 41 | 41 | } |
lib/std/special/compiler_rt/fixunssfti_test.zig+29-29| ... | ... | @@ -6,41 +6,41 @@ |
| 6 | 6 | const __fixunssfti = @import("fixunssfti.zig").__fixunssfti; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunssfti(a: f32, expected: u128) void { | |
| 9 | fn test__fixunssfti(a: f32, expected: u128) !void { | |
| 10 | 10 | const x = __fixunssfti(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunssfti" { |
| 15 | test__fixunssfti(0.0, 0); | |
| 15 | try test__fixunssfti(0.0, 0); | |
| 16 | 16 | |
| 17 | test__fixunssfti(0.5, 0); | |
| 18 | test__fixunssfti(0.99, 0); | |
| 19 | test__fixunssfti(1.0, 1); | |
| 20 | test__fixunssfti(1.5, 1); | |
| 21 | test__fixunssfti(1.99, 1); | |
| 22 | test__fixunssfti(2.0, 2); | |
| 23 | test__fixunssfti(2.01, 2); | |
| 24 | test__fixunssfti(-0.5, 0); | |
| 25 | test__fixunssfti(-0.99, 0); | |
| 17 | try test__fixunssfti(0.5, 0); | |
| 18 | try test__fixunssfti(0.99, 0); | |
| 19 | try test__fixunssfti(1.0, 1); | |
| 20 | try test__fixunssfti(1.5, 1); | |
| 21 | try test__fixunssfti(1.99, 1); | |
| 22 | try test__fixunssfti(2.0, 2); | |
| 23 | try test__fixunssfti(2.01, 2); | |
| 24 | try test__fixunssfti(-0.5, 0); | |
| 25 | try test__fixunssfti(-0.99, 0); | |
| 26 | 26 | |
| 27 | test__fixunssfti(-1.0, 0); | |
| 28 | test__fixunssfti(-1.5, 0); | |
| 29 | test__fixunssfti(-1.99, 0); | |
| 30 | test__fixunssfti(-2.0, 0); | |
| 31 | test__fixunssfti(-2.01, 0); | |
| 27 | try test__fixunssfti(-1.0, 0); | |
| 28 | try test__fixunssfti(-1.5, 0); | |
| 29 | try test__fixunssfti(-1.99, 0); | |
| 30 | try test__fixunssfti(-2.0, 0); | |
| 31 | try test__fixunssfti(-2.01, 0); | |
| 32 | 32 | |
| 33 | test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000); | |
| 34 | test__fixunssfti(0x1.000000p+63, 0x8000000000000000); | |
| 35 | test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 36 | test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 37 | test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000); | |
| 38 | test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000); | |
| 39 | test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000); | |
| 40 | test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000); | |
| 33 | try test__fixunssfti(0x1.FFFFFEp+63, 0xFFFFFF0000000000); | |
| 34 | try test__fixunssfti(0x1.000000p+63, 0x8000000000000000); | |
| 35 | try test__fixunssfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 36 | try test__fixunssfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 37 | try test__fixunssfti(0x1.FFFFFEp+127, 0xFFFFFF00000000000000000000000000); | |
| 38 | try test__fixunssfti(0x1.000000p+127, 0x80000000000000000000000000000000); | |
| 39 | try test__fixunssfti(0x1.FFFFFEp+126, 0x7FFFFF80000000000000000000000000); | |
| 40 | try test__fixunssfti(0x1.FFFFFCp+126, 0x7FFFFF00000000000000000000000000); | |
| 41 | 41 | |
| 42 | test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000); | |
| 43 | test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000); | |
| 44 | test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000); | |
| 45 | test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000); | |
| 42 | try test__fixunssfti(-0x1.FFFFFEp+62, 0x0000000000000000); | |
| 43 | try test__fixunssfti(-0x1.FFFFFCp+62, 0x0000000000000000); | |
| 44 | try test__fixunssfti(-0x1.FFFFFEp+126, 0x0000000000000000); | |
| 45 | try test__fixunssfti(-0x1.FFFFFCp+126, 0x0000000000000000); | |
| 46 | 46 | } |
lib/std/special/compiler_rt/fixunstfdi_test.zig+41-41| ... | ... | @@ -6,49 +6,49 @@ |
| 6 | 6 | const __fixunstfdi = @import("fixunstfdi.zig").__fixunstfdi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunstfdi(a: f128, expected: u64) void { | |
| 9 | fn test__fixunstfdi(a: f128, expected: u64) !void { | |
| 10 | 10 | const x = __fixunstfdi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "fixunstfdi" { |
| 15 | test__fixunstfdi(0.0, 0); | |
| 16 | ||
| 17 | test__fixunstfdi(0.5, 0); | |
| 18 | test__fixunstfdi(0.99, 0); | |
| 19 | test__fixunstfdi(1.0, 1); | |
| 20 | test__fixunstfdi(1.5, 1); | |
| 21 | test__fixunstfdi(1.99, 1); | |
| 22 | test__fixunstfdi(2.0, 2); | |
| 23 | test__fixunstfdi(2.01, 2); | |
| 24 | test__fixunstfdi(-0.5, 0); | |
| 25 | test__fixunstfdi(-0.99, 0); | |
| 26 | test__fixunstfdi(-1.0, 0); | |
| 27 | test__fixunstfdi(-1.5, 0); | |
| 28 | test__fixunstfdi(-1.99, 0); | |
| 29 | test__fixunstfdi(-2.0, 0); | |
| 30 | test__fixunstfdi(-2.01, 0); | |
| 31 | ||
| 32 | test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 33 | test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 34 | ||
| 35 | test__fixunstfdi(-0x1.FFFFFEp+62, 0); | |
| 36 | test__fixunstfdi(-0x1.FFFFFCp+62, 0); | |
| 37 | ||
| 38 | test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 39 | test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 40 | ||
| 41 | test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 42 | test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 43 | ||
| 44 | test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF); | |
| 45 | test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001); | |
| 46 | test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000); | |
| 47 | test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF); | |
| 48 | test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE); | |
| 49 | test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF); | |
| 50 | ||
| 51 | test__fixunstfdi(-0x1.0000000000000000p+63, 0); | |
| 52 | test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0); | |
| 53 | test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0); | |
| 15 | try test__fixunstfdi(0.0, 0); | |
| 16 | ||
| 17 | try test__fixunstfdi(0.5, 0); | |
| 18 | try test__fixunstfdi(0.99, 0); | |
| 19 | try test__fixunstfdi(1.0, 1); | |
| 20 | try test__fixunstfdi(1.5, 1); | |
| 21 | try test__fixunstfdi(1.99, 1); | |
| 22 | try test__fixunstfdi(2.0, 2); | |
| 23 | try test__fixunstfdi(2.01, 2); | |
| 24 | try test__fixunstfdi(-0.5, 0); | |
| 25 | try test__fixunstfdi(-0.99, 0); | |
| 26 | try test__fixunstfdi(-1.0, 0); | |
| 27 | try test__fixunstfdi(-1.5, 0); | |
| 28 | try test__fixunstfdi(-1.99, 0); | |
| 29 | try test__fixunstfdi(-2.0, 0); | |
| 30 | try test__fixunstfdi(-2.01, 0); | |
| 31 | ||
| 32 | try test__fixunstfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000); | |
| 33 | try test__fixunstfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000); | |
| 34 | ||
| 35 | try test__fixunstfdi(-0x1.FFFFFEp+62, 0); | |
| 36 | try test__fixunstfdi(-0x1.FFFFFCp+62, 0); | |
| 37 | ||
| 38 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00); | |
| 39 | try test__fixunstfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800); | |
| 40 | ||
| 41 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFp+62, 0); | |
| 42 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFEp+62, 0); | |
| 43 | ||
| 44 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFEp+63, 0xFFFFFFFFFFFFFFFF); | |
| 45 | try test__fixunstfdi(0x1.0000000000000002p+63, 0x8000000000000001); | |
| 46 | try test__fixunstfdi(0x1.0000000000000000p+63, 0x8000000000000000); | |
| 47 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFFCp+62, 0x7FFFFFFFFFFFFFFF); | |
| 48 | try test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62, 0x7FFFFFFFFFFFFFFE); | |
| 49 | try test__fixunstfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFF); | |
| 50 | ||
| 51 | try test__fixunstfdi(-0x1.0000000000000000p+63, 0); | |
| 52 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFFCp+62, 0); | |
| 53 | try test__fixunstfdi(-0x1.FFFFFFFFFFFFFFF8p+62, 0); | |
| 54 | 54 | } |
lib/std/special/compiler_rt/fixunstfsi_test.zig+11-11| ... | ... | @@ -6,22 +6,22 @@ |
| 6 | 6 | const __fixunstfsi = @import("fixunstfsi.zig").__fixunstfsi; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunstfsi(a: f128, expected: u32) void { | |
| 9 | fn test__fixunstfsi(a: f128, expected: u32) !void { | |
| 10 | 10 | const x = __fixunstfsi(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); |
| 15 | 15 | |
| 16 | 16 | test "fixunstfsi" { |
| 17 | test__fixunstfsi(inf128, 0xffffffff); | |
| 18 | test__fixunstfsi(0, 0x0); | |
| 19 | test__fixunstfsi(0x1.23456789abcdefp+5, 0x24); | |
| 20 | test__fixunstfsi(0x1.23456789abcdefp-3, 0x0); | |
| 21 | test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456); | |
| 22 | test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff); | |
| 23 | test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff); | |
| 24 | test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0); | |
| 17 | try test__fixunstfsi(inf128, 0xffffffff); | |
| 18 | try test__fixunstfsi(0, 0x0); | |
| 19 | try test__fixunstfsi(0x1.23456789abcdefp+5, 0x24); | |
| 20 | try test__fixunstfsi(0x1.23456789abcdefp-3, 0x0); | |
| 21 | try test__fixunstfsi(0x1.23456789abcdefp+20, 0x123456); | |
| 22 | try test__fixunstfsi(0x1.23456789abcdefp+40, 0xffffffff); | |
| 23 | try test__fixunstfsi(0x1.23456789abcdefp+256, 0xffffffff); | |
| 24 | try test__fixunstfsi(-0x1.23456789abcdefp+3, 0x0); | |
| 25 | 25 | |
| 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 | 6 | const __fixunstfti = @import("fixunstfti.zig").__fixunstfti; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__fixunstfti(a: f128, expected: u128) void { | |
| 9 | fn test__fixunstfti(a: f128, expected: u128) !void { | |
| 10 | 10 | const x = __fixunstfti(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000)); |
| 15 | 15 | |
| 16 | 16 | test "fixunstfti" { |
| 17 | test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); | |
| 17 | try test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff); | |
| 18 | 18 | |
| 19 | test__fixunstfti(0.0, 0); | |
| 19 | try test__fixunstfti(0.0, 0); | |
| 20 | 20 | |
| 21 | test__fixunstfti(0.5, 0); | |
| 22 | test__fixunstfti(0.99, 0); | |
| 23 | test__fixunstfti(1.0, 1); | |
| 24 | test__fixunstfti(1.5, 1); | |
| 25 | test__fixunstfti(1.99, 1); | |
| 26 | test__fixunstfti(2.0, 2); | |
| 27 | test__fixunstfti(2.01, 2); | |
| 28 | test__fixunstfti(-0.01, 0); | |
| 29 | test__fixunstfti(-0.99, 0); | |
| 21 | try test__fixunstfti(0.5, 0); | |
| 22 | try test__fixunstfti(0.99, 0); | |
| 23 | try test__fixunstfti(1.0, 1); | |
| 24 | try test__fixunstfti(1.5, 1); | |
| 25 | try test__fixunstfti(1.99, 1); | |
| 26 | try test__fixunstfti(2.0, 2); | |
| 27 | try test__fixunstfti(2.01, 2); | |
| 28 | try test__fixunstfti(-0.01, 0); | |
| 29 | try test__fixunstfti(-0.99, 0); | |
| 30 | 30 | |
| 31 | test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff); | |
| 31 | try test__fixunstfti(0x1.p+128, 0xffffffffffffffffffffffffffffffff); | |
| 32 | 32 | |
| 33 | test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000); | |
| 34 | test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000); | |
| 35 | test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff); | |
| 36 | test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff); | |
| 33 | try test__fixunstfti(0x1.FFFFFEp+126, 0x7fffff80000000000000000000000000); | |
| 34 | try test__fixunstfti(0x1.FFFFFEp+127, 0xffffff00000000000000000000000000); | |
| 35 | try test__fixunstfti(0x1.FFFFFEp+128, 0xffffffffffffffffffffffffffffffff); | |
| 36 | try test__fixunstfti(0x1.FFFFFEp+129, 0xffffffffffffffffffffffffffffffff); | |
| 37 | 37 | } |
lib/std/special/compiler_rt/floatdidf_test.zig+45-45| ... | ... | @@ -6,53 +6,53 @@ |
| 6 | 6 | const __floatdidf = @import("floatdidf.zig").__floatdidf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatdidf(a: i64, expected: f64) void { | |
| 9 | fn test__floatdidf(a: i64, expected: f64) !void { | |
| 10 | 10 | const r = __floatdidf(a); |
| 11 | testing.expect(r == expected); | |
| 11 | try testing.expect(r == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatdidf" { |
| 15 | test__floatdidf(0, 0.0); | |
| 16 | test__floatdidf(1, 1.0); | |
| 17 | test__floatdidf(2, 2.0); | |
| 18 | test__floatdidf(20, 20.0); | |
| 19 | test__floatdidf(-1, -1.0); | |
| 20 | test__floatdidf(-2, -2.0); | |
| 21 | test__floatdidf(-20, -20.0); | |
| 22 | test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 23 | test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 24 | test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 25 | test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 26 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62); | |
| 27 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62); | |
| 28 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62); | |
| 29 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62); | |
| 30 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63); | |
| 31 | test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63); | |
| 32 | test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 33 | test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 34 | test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 35 | test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 36 | test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 37 | test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 38 | test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 39 | test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 40 | test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 41 | test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 42 | test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 43 | test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 44 | test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 45 | test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 46 | test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 47 | test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 48 | test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 49 | test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 50 | test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 51 | test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 52 | test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 53 | test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 54 | test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 55 | test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 56 | test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 57 | test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 15 | try test__floatdidf(0, 0.0); | |
| 16 | try test__floatdidf(1, 1.0); | |
| 17 | try test__floatdidf(2, 2.0); | |
| 18 | try test__floatdidf(20, 20.0); | |
| 19 | try test__floatdidf(-1, -1.0); | |
| 20 | try test__floatdidf(-2, -2.0); | |
| 21 | try test__floatdidf(-20, -20.0); | |
| 22 | try test__floatdidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 23 | try test__floatdidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 24 | try test__floatdidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 25 | try test__floatdidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 26 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000008000000000)), -0x1.FFFFFEp+62); | |
| 27 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000800)), -0x1.FFFFFFFFFFFFEp+62); | |
| 28 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000010000000000)), -0x1.FFFFFCp+62); | |
| 29 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000001000)), -0x1.FFFFFFFFFFFFCp+62); | |
| 30 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000000)), -0x1.000000p+63); | |
| 31 | try test__floatdidf(@bitCast(i64, @intCast(u64, 0x8000000000000001)), -0x1.000000p+63); | |
| 32 | try test__floatdidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 33 | try test__floatdidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 34 | try test__floatdidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 35 | try test__floatdidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 36 | try test__floatdidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 37 | try test__floatdidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 38 | try test__floatdidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 39 | try test__floatdidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 40 | try test__floatdidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 41 | try test__floatdidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 42 | try test__floatdidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 43 | try test__floatdidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 44 | try test__floatdidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 45 | try test__floatdidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 46 | try test__floatdidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 47 | try test__floatdidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 48 | try test__floatdidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 49 | try test__floatdidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 50 | try test__floatdidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 51 | try test__floatdidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 52 | try test__floatdidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 53 | try test__floatdidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 54 | try test__floatdidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 55 | try test__floatdidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 56 | try test__floatdidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 57 | try test__floatdidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 58 | 58 | } |
lib/std/special/compiler_rt/floatdisf_test.zig+24-24| ... | ... | @@ -6,32 +6,32 @@ |
| 6 | 6 | const __floatdisf = @import("floatXisf.zig").__floatdisf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatdisf(a: i64, expected: f32) void { | |
| 9 | fn test__floatdisf(a: i64, expected: f32) !void { | |
| 10 | 10 | const x = __floatdisf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatdisf" { |
| 15 | test__floatdisf(0, 0.0); | |
| 16 | test__floatdisf(1, 1.0); | |
| 17 | test__floatdisf(2, 2.0); | |
| 18 | test__floatdisf(-1, -1.0); | |
| 19 | test__floatdisf(-2, -2.0); | |
| 20 | test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 21 | test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 22 | test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62); | |
| 23 | test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62); | |
| 24 | test__floatdisf(0x8000000000000000, -0x1.000000p+63); | |
| 25 | test__floatdisf(0x8000000000000001, -0x1.000000p+63); | |
| 26 | test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 27 | test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 28 | test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 29 | test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 30 | test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 31 | test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 32 | test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 33 | test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 34 | test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 35 | test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 36 | test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 15 | try test__floatdisf(0, 0.0); | |
| 16 | try test__floatdisf(1, 1.0); | |
| 17 | try test__floatdisf(2, 2.0); | |
| 18 | try test__floatdisf(-1, -1.0); | |
| 19 | try test__floatdisf(-2, -2.0); | |
| 20 | try test__floatdisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 21 | try test__floatdisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 22 | try test__floatdisf(0x8000008000000000, -0x1.FFFFFEp+62); | |
| 23 | try test__floatdisf(0x8000010000000000, -0x1.FFFFFCp+62); | |
| 24 | try test__floatdisf(0x8000000000000000, -0x1.000000p+63); | |
| 25 | try test__floatdisf(0x8000000000000001, -0x1.000000p+63); | |
| 26 | try test__floatdisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 27 | try test__floatdisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 28 | try test__floatdisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 29 | try test__floatdisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 30 | try test__floatdisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 31 | try test__floatdisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 32 | try test__floatdisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 33 | try test__floatdisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 34 | try test__floatdisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 35 | try test__floatdisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 36 | try test__floatdisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 37 | 37 | } |
lib/std/special/compiler_rt/floatditf_test.zig+11-11| ... | ... | @@ -6,21 +6,21 @@ |
| 6 | 6 | const __floatditf = @import("floatditf.zig").__floatditf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatditf(a: i64, expected: f128) void { | |
| 9 | fn test__floatditf(a: i64, expected: f128) !void { | |
| 10 | 10 | const x = __floatditf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatditf" { |
| 15 | test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000)); | |
| 16 | test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000)); | |
| 17 | test__floatditf(0x2, make_ti(0x4000000000000000, 0x0)); | |
| 18 | test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0)); | |
| 19 | test__floatditf(0x0, make_ti(0x0, 0x0)); | |
| 20 | test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0)); | |
| 21 | test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0)); | |
| 22 | test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000)); | |
| 23 | test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0)); | |
| 15 | try test__floatditf(0x7fffffffffffffff, make_ti(0x403dffffffffffff, 0xfffc000000000000)); | |
| 16 | try test__floatditf(0x123456789abcdef1, make_ti(0x403b23456789abcd, 0xef10000000000000)); | |
| 17 | try test__floatditf(0x2, make_ti(0x4000000000000000, 0x0)); | |
| 18 | try test__floatditf(0x1, make_ti(0x3fff000000000000, 0x0)); | |
| 19 | try test__floatditf(0x0, make_ti(0x0, 0x0)); | |
| 20 | try test__floatditf(@bitCast(i64, @as(u64, 0xffffffffffffffff)), make_ti(0xbfff000000000000, 0x0)); | |
| 21 | try test__floatditf(@bitCast(i64, @as(u64, 0xfffffffffffffffe)), make_ti(0xc000000000000000, 0x0)); | |
| 22 | try test__floatditf(-0x123456789abcdef1, make_ti(0xc03b23456789abcd, 0xef10000000000000)); | |
| 23 | try test__floatditf(@bitCast(i64, @as(u64, 0x8000000000000000)), make_ti(0xc03e000000000000, 0x0)); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | fn 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 | 84 | return @call(.{ .modifier = .always_inline }, __floatsisf, .{arg}); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | fn test_one_floatsitf(a: i32, expected: u128) void { | |
| 87 | fn test_one_floatsitf(a: i32, expected: u128) !void { | |
| 88 | 88 | const r = __floatsitf(a); |
| 89 | std.testing.expect(@bitCast(u128, r) == expected); | |
| 89 | try std.testing.expect(@bitCast(u128, r) == expected); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | fn test_one_floatsidf(a: i32, expected: u64) void { | |
| 92 | fn test_one_floatsidf(a: i32, expected: u64) !void { | |
| 93 | 93 | const r = __floatsidf(a); |
| 94 | std.testing.expect(@bitCast(u64, r) == expected); | |
| 94 | try std.testing.expect(@bitCast(u64, r) == expected); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | fn test_one_floatsisf(a: i32, expected: u32) void { | |
| 97 | fn test_one_floatsisf(a: i32, expected: u32) !void { | |
| 98 | 98 | const r = __floatsisf(a); |
| 99 | std.testing.expect(@bitCast(u32, r) == expected); | |
| 99 | try std.testing.expect(@bitCast(u32, r) == expected); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "floatsidf" { |
| 103 | test_one_floatsidf(0, 0x0000000000000000); | |
| 104 | test_one_floatsidf(1, 0x3ff0000000000000); | |
| 105 | test_one_floatsidf(-1, 0xbff0000000000000); | |
| 106 | test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000); | |
| 107 | test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000); | |
| 103 | try test_one_floatsidf(0, 0x0000000000000000); | |
| 104 | try test_one_floatsidf(1, 0x3ff0000000000000); | |
| 105 | try test_one_floatsidf(-1, 0xbff0000000000000); | |
| 106 | try test_one_floatsidf(0x7FFFFFFF, 0x41dfffffffc00000); | |
| 107 | try test_one_floatsidf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc1e0000000000000); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | test "floatsisf" { |
| 111 | test_one_floatsisf(0, 0x00000000); | |
| 112 | test_one_floatsisf(1, 0x3f800000); | |
| 113 | test_one_floatsisf(-1, 0xbf800000); | |
| 114 | test_one_floatsisf(0x7FFFFFFF, 0x4f000000); | |
| 115 | test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000); | |
| 111 | try test_one_floatsisf(0, 0x00000000); | |
| 112 | try test_one_floatsisf(1, 0x3f800000); | |
| 113 | try test_one_floatsisf(-1, 0xbf800000); | |
| 114 | try test_one_floatsisf(0x7FFFFFFF, 0x4f000000); | |
| 115 | try test_one_floatsisf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xcf000000); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | test "floatsitf" { |
| 119 | test_one_floatsitf(0, 0); | |
| 120 | test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000); | |
| 121 | test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000); | |
| 122 | test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000); | |
| 123 | test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000); | |
| 124 | test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000); | |
| 119 | try test_one_floatsitf(0, 0); | |
| 120 | try test_one_floatsitf(0x7FFFFFFF, 0x401dfffffffc00000000000000000000); | |
| 121 | try test_one_floatsitf(0x12345678, 0x401b2345678000000000000000000000); | |
| 122 | try test_one_floatsitf(-0x12345678, 0xc01b2345678000000000000000000000); | |
| 123 | try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0xffffffff)), 0xbfff0000000000000000000000000000); | |
| 124 | try test_one_floatsitf(@bitCast(i32, @intCast(u32, 0x80000000)), 0xc01e0000000000000000000000000000); | |
| 125 | 125 | } |
lib/std/special/compiler_rt/floattidf_test.zig+60-60| ... | ... | @@ -6,79 +6,79 @@ |
| 6 | 6 | const __floattidf = @import("floattidf.zig").__floattidf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floattidf(a: i128, expected: f64) void { | |
| 9 | fn test__floattidf(a: i128, expected: f64) !void { | |
| 10 | 10 | const x = __floattidf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floattidf" { |
| 15 | test__floattidf(0, 0.0); | |
| 15 | try test__floattidf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floattidf(1, 1.0); | |
| 18 | test__floattidf(2, 2.0); | |
| 19 | test__floattidf(20, 20.0); | |
| 20 | test__floattidf(-1, -1.0); | |
| 21 | test__floattidf(-2, -2.0); | |
| 22 | test__floattidf(-20, -20.0); | |
| 17 | try test__floattidf(1, 1.0); | |
| 18 | try test__floattidf(2, 2.0); | |
| 19 | try test__floattidf(20, 20.0); | |
| 20 | try test__floattidf(-1, -1.0); | |
| 21 | try test__floattidf(-2, -2.0); | |
| 22 | try test__floattidf(-20, -20.0); | |
| 23 | 23 | |
| 24 | test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 25 | test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 26 | test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 27 | test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 24 | try test__floattidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 25 | try test__floattidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 26 | try test__floattidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 27 | try test__floattidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 28 | 28 | |
| 29 | test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126); | |
| 30 | test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126); | |
| 31 | test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126); | |
| 32 | test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126); | |
| 29 | try test__floattidf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126); | |
| 30 | try test__floattidf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126); | |
| 31 | try test__floattidf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126); | |
| 32 | try test__floattidf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126); | |
| 33 | 33 | |
| 34 | test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127); | |
| 35 | test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127); | |
| 34 | try test__floattidf(make_ti(0x8000000000000000, 0), -0x1.000000p+127); | |
| 35 | try test__floattidf(make_ti(0x8000000000000001, 0), -0x1.000000p+127); | |
| 36 | 36 | |
| 37 | test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 37 | try test__floattidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 38 | 38 | |
| 39 | test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 39 | try test__floattidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | try test__floattidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | try test__floattidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | try test__floattidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | try test__floattidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 44 | 44 | |
| 45 | test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 45 | try test__floattidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | try test__floattidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | try test__floattidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | try test__floattidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | try test__floattidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 50 | 50 | |
| 51 | test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 53 | test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 54 | test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 55 | test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 56 | test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 57 | test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 58 | test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 59 | test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 60 | test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 61 | test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 62 | test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 63 | test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 64 | test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 65 | test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 51 | try test__floattidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | try test__floattidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 53 | try test__floattidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 54 | try test__floattidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 55 | try test__floattidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 56 | try test__floattidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 57 | try test__floattidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 58 | try test__floattidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 59 | try test__floattidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 60 | try test__floattidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 61 | try test__floattidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 62 | try test__floattidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 63 | try test__floattidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 64 | try test__floattidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 65 | try test__floattidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 66 | 66 | |
| 67 | test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121); | |
| 69 | test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121); | |
| 70 | test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121); | |
| 71 | test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121); | |
| 72 | test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121); | |
| 73 | test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121); | |
| 74 | test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121); | |
| 75 | test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121); | |
| 76 | test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121); | |
| 77 | test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121); | |
| 78 | test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121); | |
| 79 | test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121); | |
| 80 | test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121); | |
| 81 | test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 67 | try test__floattidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | try test__floattidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121); | |
| 69 | try test__floattidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121); | |
| 70 | try test__floattidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121); | |
| 71 | try test__floattidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121); | |
| 72 | try test__floattidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121); | |
| 73 | try test__floattidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121); | |
| 74 | try test__floattidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121); | |
| 75 | try test__floattidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121); | |
| 76 | try test__floattidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121); | |
| 77 | try test__floattidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121); | |
| 78 | try test__floattidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121); | |
| 79 | try test__floattidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121); | |
| 80 | try test__floattidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121); | |
| 81 | try test__floattidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | fn make_ti(high: u64, low: u64) i128 { |
lib/std/special/compiler_rt/floattisf_test.zig+35-35| ... | ... | @@ -6,55 +6,55 @@ |
| 6 | 6 | const __floattisf = @import("floatXisf.zig").__floattisf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floattisf(a: i128, expected: f32) void { | |
| 9 | fn test__floattisf(a: i128, expected: f32) !void { | |
| 10 | 10 | const x = __floattisf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floattisf" { |
| 15 | test__floattisf(0, 0.0); | |
| 15 | try test__floattisf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floattisf(1, 1.0); | |
| 18 | test__floattisf(2, 2.0); | |
| 19 | test__floattisf(-1, -1.0); | |
| 20 | test__floattisf(-2, -2.0); | |
| 17 | try test__floattisf(1, 1.0); | |
| 18 | try test__floattisf(2, 2.0); | |
| 19 | try test__floattisf(-1, -1.0); | |
| 20 | try test__floattisf(-2, -2.0); | |
| 21 | 21 | |
| 22 | test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 23 | test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 22 | try test__floattisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 23 | try test__floattisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 24 | 24 | |
| 25 | test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62); | |
| 26 | test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62); | |
| 25 | try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000008000000000), -0x1.FFFFFEp+62); | |
| 26 | try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000010000000000), -0x1.FFFFFCp+62); | |
| 27 | 27 | |
| 28 | test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63); | |
| 29 | test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63); | |
| 28 | try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000000), -0x1.000000p+63); | |
| 29 | try test__floattisf(make_ti(0xFFFFFFFFFFFFFFFF, 0x8000000000000001), -0x1.000000p+63); | |
| 30 | 30 | |
| 31 | test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 31 | try test__floattisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 32 | 32 | |
| 33 | test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 34 | test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 35 | test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 36 | test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 37 | test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 33 | try test__floattisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 34 | try test__floattisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 35 | try test__floattisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 36 | try test__floattisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 37 | try test__floattisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 38 | 38 | |
| 39 | test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 40 | test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 41 | test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 42 | test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 43 | test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 39 | try test__floattisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 40 | try test__floattisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 41 | try test__floattisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 42 | try test__floattisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 43 | try test__floattisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 44 | 44 | |
| 45 | test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114); | |
| 45 | try test__floattisf(make_ti(0x0007FB72E8000000, 0), 0x1.FEDCBAp+114); | |
| 46 | 46 | |
| 47 | test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114); | |
| 48 | test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114); | |
| 49 | test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114); | |
| 50 | test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114); | |
| 51 | test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114); | |
| 47 | try test__floattisf(make_ti(0x0007FB72EA000000, 0), 0x1.FEDCBAp+114); | |
| 48 | try test__floattisf(make_ti(0x0007FB72EB000000, 0), 0x1.FEDCBAp+114); | |
| 49 | try test__floattisf(make_ti(0x0007FB72EBFFFFFF, 0), 0x1.FEDCBAp+114); | |
| 50 | try test__floattisf(make_ti(0x0007FB72EC000000, 0), 0x1.FEDCBCp+114); | |
| 51 | try test__floattisf(make_ti(0x0007FB72E8000001, 0), 0x1.FEDCBAp+114); | |
| 52 | 52 | |
| 53 | test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114); | |
| 54 | test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114); | |
| 55 | test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114); | |
| 56 | test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114); | |
| 57 | test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114); | |
| 53 | try test__floattisf(make_ti(0x0007FB72E6000000, 0), 0x1.FEDCBAp+114); | |
| 54 | try test__floattisf(make_ti(0x0007FB72E7000000, 0), 0x1.FEDCBAp+114); | |
| 55 | try test__floattisf(make_ti(0x0007FB72E7FFFFFF, 0), 0x1.FEDCBAp+114); | |
| 56 | try test__floattisf(make_ti(0x0007FB72E4000001, 0), 0x1.FEDCBAp+114); | |
| 57 | try test__floattisf(make_ti(0x0007FB72E4000000, 0), 0x1.FEDCB8p+114); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | fn make_ti(high: u64, low: u64) i128 { |
lib/std/special/compiler_rt/floattitf_test.zig+70-70| ... | ... | @@ -6,91 +6,91 @@ |
| 6 | 6 | const __floattitf = @import("floattitf.zig").__floattitf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floattitf(a: i128, expected: f128) void { | |
| 9 | fn test__floattitf(a: i128, expected: f128) !void { | |
| 10 | 10 | const x = __floattitf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floattitf" { |
| 15 | test__floattitf(0, 0.0); | |
| 15 | try test__floattitf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floattitf(1, 1.0); | |
| 18 | test__floattitf(2, 2.0); | |
| 19 | test__floattitf(20, 20.0); | |
| 20 | test__floattitf(-1, -1.0); | |
| 21 | test__floattitf(-2, -2.0); | |
| 22 | test__floattitf(-20, -20.0); | |
| 17 | try test__floattitf(1, 1.0); | |
| 18 | try test__floattitf(2, 2.0); | |
| 19 | try test__floattitf(20, 20.0); | |
| 20 | try test__floattitf(-1, -1.0); | |
| 21 | try test__floattitf(-2, -2.0); | |
| 22 | try test__floattitf(-20, -20.0); | |
| 23 | 23 | |
| 24 | test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 25 | test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 26 | test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 27 | test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 24 | try test__floattitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 25 | try test__floattitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 26 | try test__floattitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 27 | try test__floattitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 28 | 28 | |
| 29 | test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126); | |
| 30 | test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126); | |
| 31 | test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126); | |
| 32 | test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126); | |
| 29 | try test__floattitf(make_ti(0x8000008000000000, 0), -0x1.FFFFFEp+126); | |
| 30 | try test__floattitf(make_ti(0x8000000000000800, 0), -0x1.FFFFFFFFFFFFEp+126); | |
| 31 | try test__floattitf(make_ti(0x8000010000000000, 0), -0x1.FFFFFCp+126); | |
| 32 | try test__floattitf(make_ti(0x8000000000001000, 0), -0x1.FFFFFFFFFFFFCp+126); | |
| 33 | 33 | |
| 34 | test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127); | |
| 35 | test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126); | |
| 34 | try test__floattitf(make_ti(0x8000000000000000, 0), -0x1.000000p+127); | |
| 35 | try test__floattitf(make_ti(0x8000000000000001, 0), -0x1.FFFFFFFFFFFFFFFCp+126); | |
| 36 | 36 | |
| 37 | test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 37 | try test__floattitf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 38 | 38 | |
| 39 | test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 39 | try test__floattitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | try test__floattitf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | try test__floattitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | try test__floattitf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | try test__floattitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 44 | 44 | |
| 45 | test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 45 | try test__floattitf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | try test__floattitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | try test__floattitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | try test__floattitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | try test__floattitf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 50 | 50 | |
| 51 | test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57); | |
| 53 | test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57); | |
| 54 | test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57); | |
| 55 | test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57); | |
| 56 | test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57); | |
| 57 | test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57); | |
| 58 | test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57); | |
| 59 | test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57); | |
| 60 | test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57); | |
| 61 | test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57); | |
| 62 | test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57); | |
| 63 | test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57); | |
| 64 | test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57); | |
| 65 | test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 51 | try test__floattitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | try test__floattitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57); | |
| 53 | try test__floattitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57); | |
| 54 | try test__floattitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57); | |
| 55 | try test__floattitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57); | |
| 56 | try test__floattitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57); | |
| 57 | try test__floattitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57); | |
| 58 | try test__floattitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57); | |
| 59 | try test__floattitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57); | |
| 60 | try test__floattitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57); | |
| 61 | try test__floattitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57); | |
| 62 | try test__floattitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57); | |
| 63 | try test__floattitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57); | |
| 64 | try test__floattitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57); | |
| 65 | try test__floattitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 66 | 66 | |
| 67 | test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121); | |
| 69 | test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121); | |
| 70 | test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121); | |
| 71 | test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121); | |
| 72 | test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121); | |
| 73 | test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121); | |
| 74 | test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121); | |
| 75 | test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121); | |
| 76 | test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121); | |
| 77 | test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121); | |
| 78 | test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121); | |
| 79 | test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121); | |
| 80 | test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121); | |
| 81 | test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 67 | try test__floattitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | try test__floattitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121); | |
| 69 | try test__floattitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121); | |
| 70 | try test__floattitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121); | |
| 71 | try test__floattitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121); | |
| 72 | try test__floattitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121); | |
| 73 | try test__floattitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121); | |
| 74 | try test__floattitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121); | |
| 75 | try test__floattitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121); | |
| 76 | try test__floattitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121); | |
| 77 | try test__floattitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121); | |
| 78 | try test__floattitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121); | |
| 79 | try test__floattitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121); | |
| 80 | try test__floattitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121); | |
| 81 | try test__floattitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 82 | 82 | |
| 83 | test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63); | |
| 83 | try test__floattitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63); | |
| 84 | 84 | |
| 85 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 86 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 87 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 88 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 89 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 90 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 91 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 92 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 93 | test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 85 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 86 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 87 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 88 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 89 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 90 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 91 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 92 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 93 | try test__floattitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | fn make_ti(high: u64, low: u64) i128 { |
lib/std/special/compiler_rt/floatundidf_test.zig+42-42| ... | ... | @@ -6,50 +6,50 @@ |
| 6 | 6 | const __floatundidf = @import("floatundidf.zig").__floatundidf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatundidf(a: u64, expected: f64) void { | |
| 9 | fn test__floatundidf(a: u64, expected: f64) !void { | |
| 10 | 10 | const r = __floatundidf(a); |
| 11 | testing.expect(r == expected); | |
| 11 | try testing.expect(r == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatundidf" { |
| 15 | test__floatundidf(0, 0.0); | |
| 16 | test__floatundidf(1, 1.0); | |
| 17 | test__floatundidf(2, 2.0); | |
| 18 | test__floatundidf(20, 20.0); | |
| 19 | test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 20 | test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 21 | test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 22 | test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 23 | test__floatundidf(0x8000008000000000, 0x1.000001p+63); | |
| 24 | test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63); | |
| 25 | test__floatundidf(0x8000010000000000, 0x1.000002p+63); | |
| 26 | test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63); | |
| 27 | test__floatundidf(0x8000000000000000, 0x1p+63); | |
| 28 | test__floatundidf(0x8000000000000001, 0x1p+63); | |
| 29 | test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 30 | test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 31 | test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 32 | test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 33 | test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 34 | test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 35 | test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 36 | test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 37 | test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 38 | test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 39 | test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 40 | test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 41 | test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 42 | test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 43 | test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 44 | test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 45 | test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 46 | test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 47 | test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 48 | test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 49 | test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 50 | test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 51 | test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 52 | test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 53 | test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 54 | test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 15 | try test__floatundidf(0, 0.0); | |
| 16 | try test__floatundidf(1, 1.0); | |
| 17 | try test__floatundidf(2, 2.0); | |
| 18 | try test__floatundidf(20, 20.0); | |
| 19 | try test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 20 | try test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 21 | try test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 22 | try test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 23 | try test__floatundidf(0x8000008000000000, 0x1.000001p+63); | |
| 24 | try test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63); | |
| 25 | try test__floatundidf(0x8000010000000000, 0x1.000002p+63); | |
| 26 | try test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63); | |
| 27 | try test__floatundidf(0x8000000000000000, 0x1p+63); | |
| 28 | try test__floatundidf(0x8000000000000001, 0x1p+63); | |
| 29 | try test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 30 | try test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 31 | try test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 32 | try test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 33 | try test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 34 | try test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 35 | try test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 36 | try test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 37 | try test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 38 | try test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 39 | try test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 40 | try test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 41 | try test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 42 | try test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 43 | try test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 44 | try test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 45 | try test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 46 | try test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 47 | try test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 48 | try test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 49 | try test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 50 | try test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 51 | try test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 52 | try test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 53 | try test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 54 | try test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 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 | 66 | return @call(.{ .modifier = .always_inline }, __floatundisf, .{arg}); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | fn test__floatundisf(a: u64, expected: f32) void { | |
| 70 | std.testing.expectEqual(expected, __floatundisf(a)); | |
| 69 | fn test__floatundisf(a: u64, expected: f32) !void { | |
| 70 | try std.testing.expectEqual(expected, __floatundisf(a)); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | test "floatundisf" { |
| 74 | test__floatundisf(0, 0.0); | |
| 75 | test__floatundisf(1, 1.0); | |
| 76 | test__floatundisf(2, 2.0); | |
| 77 | test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 78 | test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 79 | test__floatundisf(0x8000008000000000, 0x1p+63); | |
| 80 | test__floatundisf(0x8000010000000000, 0x1.000002p+63); | |
| 81 | test__floatundisf(0x8000000000000000, 0x1p+63); | |
| 82 | test__floatundisf(0x8000000000000001, 0x1p+63); | |
| 83 | test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64); | |
| 84 | test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64); | |
| 85 | test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 86 | test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 87 | test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 88 | test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 89 | test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 90 | test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 91 | test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 92 | test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 93 | test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 94 | test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 95 | test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 74 | try test__floatundisf(0, 0.0); | |
| 75 | try test__floatundisf(1, 1.0); | |
| 76 | try test__floatundisf(2, 2.0); | |
| 77 | try test__floatundisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 78 | try test__floatundisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 79 | try test__floatundisf(0x8000008000000000, 0x1p+63); | |
| 80 | try test__floatundisf(0x8000010000000000, 0x1.000002p+63); | |
| 81 | try test__floatundisf(0x8000000000000000, 0x1p+63); | |
| 82 | try test__floatundisf(0x8000000000000001, 0x1p+63); | |
| 83 | try test__floatundisf(0xFFFFFFFFFFFFFFFE, 0x1p+64); | |
| 84 | try test__floatundisf(0xFFFFFFFFFFFFFFFF, 0x1p+64); | |
| 85 | try test__floatundisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 86 | try test__floatundisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 87 | try test__floatundisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 88 | try test__floatundisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 89 | try test__floatundisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 90 | try test__floatundisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 91 | try test__floatundisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 92 | try test__floatundisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 93 | try test__floatundisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 94 | try test__floatundisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 95 | try test__floatundisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 96 | 96 | } |
lib/std/special/compiler_rt/floatunditf_test.zig+9-9| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const __floatunditf = @import("floatunditf.zig").__floatunditf; |
| 7 | 7 | |
| 8 | fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void { | |
| 8 | fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) !void { | |
| 9 | 9 | const x = __floatunditf(a); |
| 10 | 10 | |
| 11 | 11 | const x_repr = @bitCast(u128, x); |
| ... | ... | @@ -26,12 +26,12 @@ fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "floatunditf" { |
| 29 | test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000); | |
| 30 | test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000); | |
| 31 | test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0); | |
| 32 | test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000); | |
| 33 | test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000); | |
| 34 | test__floatunditf(0x2, 0x4000000000000000, 0x0); | |
| 35 | test__floatunditf(0x1, 0x3fff000000000000, 0x0); | |
| 36 | test__floatunditf(0x0, 0x0, 0x0); | |
| 29 | try test__floatunditf(0xffffffffffffffff, 0x403effffffffffff, 0xfffe000000000000); | |
| 30 | try test__floatunditf(0xfffffffffffffffe, 0x403effffffffffff, 0xfffc000000000000); | |
| 31 | try test__floatunditf(0x8000000000000000, 0x403e000000000000, 0x0); | |
| 32 | try test__floatunditf(0x7fffffffffffffff, 0x403dffffffffffff, 0xfffc000000000000); | |
| 33 | try test__floatunditf(0x123456789abcdef1, 0x403b23456789abcd, 0xef10000000000000); | |
| 34 | try test__floatunditf(0x2, 0x4000000000000000, 0x0); | |
| 35 | try test__floatunditf(0x1, 0x3fff000000000000, 0x0); | |
| 36 | try test__floatunditf(0x0, 0x0, 0x0); | |
| 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 | 28 | return @call(.{ .modifier = .always_inline }, __floatunsidf, .{arg}); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | fn test_one_floatunsidf(a: u32, expected: u64) void { | |
| 31 | fn test_one_floatunsidf(a: u32, expected: u64) !void { | |
| 32 | 32 | const r = __floatunsidf(a); |
| 33 | std.testing.expect(@bitCast(u64, r) == expected); | |
| 33 | try std.testing.expect(@bitCast(u64, r) == expected); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | test "floatsidf" { |
| 37 | 37 | // Test the produced bit pattern |
| 38 | test_one_floatunsidf(0, 0x0000000000000000); | |
| 39 | test_one_floatunsidf(1, 0x3ff0000000000000); | |
| 40 | test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000); | |
| 41 | test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000); | |
| 42 | test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000); | |
| 38 | try test_one_floatunsidf(0, 0x0000000000000000); | |
| 39 | try test_one_floatunsidf(1, 0x3ff0000000000000); | |
| 40 | try test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000); | |
| 41 | try test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000); | |
| 42 | try test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000); | |
| 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 | 48 | return @call(.{ .modifier = .always_inline }, __floatunsisf, .{arg}); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | fn test_one_floatunsisf(a: u32, expected: u32) void { | |
| 51 | fn test_one_floatunsisf(a: u32, expected: u32) !void { | |
| 52 | 52 | const r = __floatunsisf(a); |
| 53 | std.testing.expect(@bitCast(u32, r) == expected); | |
| 53 | try std.testing.expect(@bitCast(u32, r) == expected); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | test "floatunsisf" { |
| 57 | 57 | // Test the produced bit pattern |
| 58 | test_one_floatunsisf(0, 0); | |
| 59 | test_one_floatunsisf(1, 0x3f800000); | |
| 60 | test_one_floatunsisf(0x7FFFFFFF, 0x4f000000); | |
| 61 | test_one_floatunsisf(0x80000000, 0x4f000000); | |
| 62 | test_one_floatunsisf(0xFFFFFFFF, 0x4f800000); | |
| 58 | try test_one_floatunsisf(0, 0); | |
| 59 | try test_one_floatunsisf(1, 0x3f800000); | |
| 60 | try test_one_floatunsisf(0x7FFFFFFF, 0x4f000000); | |
| 61 | try test_one_floatunsisf(0x80000000, 0x4f000000); | |
| 62 | try test_one_floatunsisf(0xFFFFFFFF, 0x4f800000); | |
| 63 | 63 | } |
lib/std/special/compiler_rt/floatunsitf_test.zig+5-5| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const __floatunsitf = @import("floatunsitf.zig").__floatunsitf; |
| 7 | 7 | |
| 8 | fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void { | |
| 8 | fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) !void { | |
| 9 | 9 | const x = __floatunsitf(a); |
| 10 | 10 | |
| 11 | 11 | const x_repr = @bitCast(u128, x); |
| ... | ... | @@ -26,8 +26,8 @@ fn test__floatunsitf(a: u64, expected_hi: u64, expected_lo: u64) void { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "floatunsitf" { |
| 29 | test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0); | |
| 30 | test__floatunsitf(0, 0x0, 0x0); | |
| 31 | test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0); | |
| 32 | test__floatunsitf(0x12345678, 0x401b234567800000, 0x0); | |
| 29 | try test__floatunsitf(0x7fffffff, 0x401dfffffffc0000, 0x0); | |
| 30 | try test__floatunsitf(0, 0x0, 0x0); | |
| 31 | try test__floatunsitf(0xffffffff, 0x401efffffffe0000, 0x0); | |
| 32 | try test__floatunsitf(0x12345678, 0x401b234567800000, 0x0); | |
| 33 | 33 | } |
lib/std/special/compiler_rt/floatuntidf_test.zig+57-57| ... | ... | @@ -6,76 +6,76 @@ |
| 6 | 6 | const __floatuntidf = @import("floatuntidf.zig").__floatuntidf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatuntidf(a: u128, expected: f64) void { | |
| 9 | fn test__floatuntidf(a: u128, expected: f64) !void { | |
| 10 | 10 | const x = __floatuntidf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatuntidf" { |
| 15 | test__floatuntidf(0, 0.0); | |
| 15 | try test__floatuntidf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floatuntidf(1, 1.0); | |
| 18 | test__floatuntidf(2, 2.0); | |
| 19 | test__floatuntidf(20, 20.0); | |
| 17 | try test__floatuntidf(1, 1.0); | |
| 18 | try test__floatuntidf(2, 2.0); | |
| 19 | try test__floatuntidf(20, 20.0); | |
| 20 | 20 | |
| 21 | test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 23 | test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 24 | test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 21 | try test__floatuntidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | try test__floatuntidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 23 | try test__floatuntidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 24 | try test__floatuntidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 25 | 25 | |
| 26 | test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127); | |
| 27 | test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127); | |
| 28 | test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127); | |
| 29 | test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127); | |
| 26 | try test__floatuntidf(make_ti(0x8000008000000000, 0), 0x1.000001p+127); | |
| 27 | try test__floatuntidf(make_ti(0x8000000000000800, 0), 0x1.0000000000001p+127); | |
| 28 | try test__floatuntidf(make_ti(0x8000010000000000, 0), 0x1.000002p+127); | |
| 29 | try test__floatuntidf(make_ti(0x8000000000001000, 0), 0x1.0000000000002p+127); | |
| 30 | 30 | |
| 31 | test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127); | |
| 32 | test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127); | |
| 31 | try test__floatuntidf(make_ti(0x8000000000000000, 0), 0x1.000000p+127); | |
| 32 | try test__floatuntidf(make_ti(0x8000000000000001, 0), 0x1.0000000000000002p+127); | |
| 33 | 33 | |
| 34 | test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 34 | try test__floatuntidf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 35 | 35 | |
| 36 | test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 37 | test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 38 | test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 39 | test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 40 | test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 36 | try test__floatuntidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 37 | try test__floatuntidf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 38 | try test__floatuntidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 39 | try test__floatuntidf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 40 | try test__floatuntidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 41 | 41 | |
| 42 | test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 43 | test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 44 | test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 45 | test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 46 | test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 42 | try test__floatuntidf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 43 | try test__floatuntidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 44 | try test__floatuntidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 45 | try test__floatuntidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 46 | try test__floatuntidf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 47 | 47 | |
| 48 | test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 49 | test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 50 | test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 51 | test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 52 | test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 53 | test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 54 | test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 55 | test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 56 | test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 57 | test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 58 | test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 59 | test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 60 | test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 61 | test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 62 | test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 48 | try test__floatuntidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 49 | try test__floatuntidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57); | |
| 50 | try test__floatuntidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57); | |
| 51 | try test__floatuntidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57); | |
| 52 | try test__floatuntidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57); | |
| 53 | try test__floatuntidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57); | |
| 54 | try test__floatuntidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57); | |
| 55 | try test__floatuntidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57); | |
| 56 | try test__floatuntidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57); | |
| 57 | try test__floatuntidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57); | |
| 58 | try test__floatuntidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57); | |
| 59 | try test__floatuntidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57); | |
| 60 | try test__floatuntidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57); | |
| 61 | try test__floatuntidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57); | |
| 62 | try test__floatuntidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 63 | 63 | |
| 64 | test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 65 | test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121); | |
| 66 | test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121); | |
| 67 | test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121); | |
| 68 | test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121); | |
| 69 | test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121); | |
| 70 | test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121); | |
| 71 | test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121); | |
| 72 | test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121); | |
| 73 | test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121); | |
| 74 | test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121); | |
| 75 | test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121); | |
| 76 | test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121); | |
| 77 | test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121); | |
| 78 | test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 64 | try test__floatuntidf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 65 | try test__floatuntidf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496Dp+121); | |
| 66 | try test__floatuntidf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496Ep+121); | |
| 67 | try test__floatuntidf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496Ep+121); | |
| 68 | try test__floatuntidf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496Ep+121); | |
| 69 | try test__floatuntidf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496Ep+121); | |
| 70 | try test__floatuntidf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496Ep+121); | |
| 71 | try test__floatuntidf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496Ep+121); | |
| 72 | try test__floatuntidf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496Ep+121); | |
| 73 | try test__floatuntidf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496Ep+121); | |
| 74 | try test__floatuntidf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496Ep+121); | |
| 75 | try test__floatuntidf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496Fp+121); | |
| 76 | try test__floatuntidf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496Fp+121); | |
| 77 | try test__floatuntidf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496Fp+121); | |
| 78 | try test__floatuntidf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | fn make_ti(high: u64, low: u64) u128 { |
lib/std/special/compiler_rt/floatuntisf_test.zig+44-44| ... | ... | @@ -6,67 +6,67 @@ |
| 6 | 6 | const __floatuntisf = @import("floatuntisf.zig").__floatuntisf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatuntisf(a: u128, expected: f32) void { | |
| 9 | fn test__floatuntisf(a: u128, expected: f32) !void { | |
| 10 | 10 | const x = __floatuntisf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatuntisf" { |
| 15 | test__floatuntisf(0, 0.0); | |
| 15 | try test__floatuntisf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floatuntisf(1, 1.0); | |
| 18 | test__floatuntisf(2, 2.0); | |
| 19 | test__floatuntisf(20, 20.0); | |
| 17 | try test__floatuntisf(1, 1.0); | |
| 18 | try test__floatuntisf(2, 2.0); | |
| 19 | try test__floatuntisf(20, 20.0); | |
| 20 | 20 | |
| 21 | test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 21 | try test__floatuntisf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | try test__floatuntisf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 23 | 23 | |
| 24 | test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127); | |
| 25 | test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127); | |
| 26 | test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127); | |
| 24 | try test__floatuntisf(make_ti(0x8000008000000000, 0), 0x1.000001p+127); | |
| 25 | try test__floatuntisf(make_ti(0x8000000000000800, 0), 0x1.0p+127); | |
| 26 | try test__floatuntisf(make_ti(0x8000010000000000, 0), 0x1.000002p+127); | |
| 27 | 27 | |
| 28 | test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127); | |
| 28 | try test__floatuntisf(make_ti(0x8000000000000000, 0), 0x1.000000p+127); | |
| 29 | 29 | |
| 30 | test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 30 | try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 31 | 31 | |
| 32 | test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 33 | test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 32 | try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 33 | try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 34 | 34 | |
| 35 | test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 35 | try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 36 | 36 | |
| 37 | test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 38 | test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 39 | test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 37 | try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 38 | try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 39 | try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 40 | 40 | |
| 41 | test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64); | |
| 42 | test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64); | |
| 41 | try test__floatuntisf(0xFFFFFFFFFFFFFFFE, 0x1p+64); | |
| 42 | try test__floatuntisf(0xFFFFFFFFFFFFFFFF, 0x1p+64); | |
| 43 | 43 | |
| 44 | test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 44 | try test__floatuntisf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 45 | 45 | |
| 46 | test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 47 | test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 48 | test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 49 | test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 50 | test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 46 | try test__floatuntisf(0x0007FB72EA000000, 0x1.FEDCBAp+50); | |
| 47 | try test__floatuntisf(0x0007FB72EB000000, 0x1.FEDCBAp+50); | |
| 48 | try test__floatuntisf(0x0007FB72EBFFFFFF, 0x1.FEDCBAp+50); | |
| 49 | try test__floatuntisf(0x0007FB72EC000000, 0x1.FEDCBCp+50); | |
| 50 | try test__floatuntisf(0x0007FB72E8000001, 0x1.FEDCBAp+50); | |
| 51 | 51 | |
| 52 | test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 53 | test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 54 | test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 55 | test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 56 | test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 52 | try test__floatuntisf(0x0007FB72E6000000, 0x1.FEDCBAp+50); | |
| 53 | try test__floatuntisf(0x0007FB72E7000000, 0x1.FEDCBAp+50); | |
| 54 | try test__floatuntisf(0x0007FB72E7FFFFFF, 0x1.FEDCBAp+50); | |
| 55 | try test__floatuntisf(0x0007FB72E4000001, 0x1.FEDCBAp+50); | |
| 56 | try test__floatuntisf(0x0007FB72E4000000, 0x1.FEDCB8p+50); | |
| 57 | 57 | |
| 58 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76); | |
| 59 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76); | |
| 60 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76); | |
| 61 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76); | |
| 62 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76); | |
| 63 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76); | |
| 64 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76); | |
| 65 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76); | |
| 66 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76); | |
| 67 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76); | |
| 68 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76); | |
| 69 | test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76); | |
| 58 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCB90000000000001), 0x1.FEDCBAp+76); | |
| 59 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBA0000000000000), 0x1.FEDCBAp+76); | |
| 60 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBAFFFFFFFFFFFFF), 0x1.FEDCBAp+76); | |
| 61 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000000), 0x1.FEDCBCp+76); | |
| 62 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBB0000000000001), 0x1.FEDCBCp+76); | |
| 63 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBBFFFFFFFFFFFFF), 0x1.FEDCBCp+76); | |
| 64 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000000), 0x1.FEDCBCp+76); | |
| 65 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBC0000000000001), 0x1.FEDCBCp+76); | |
| 66 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000000), 0x1.FEDCBCp+76); | |
| 67 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBD0000000000001), 0x1.FEDCBEp+76); | |
| 68 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBDFFFFFFFFFFFFF), 0x1.FEDCBEp+76); | |
| 69 | try test__floatuntisf(make_ti(0x0000000000001FED, 0xCBE0000000000000), 0x1.FEDCBEp+76); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | fn make_ti(high: u64, low: u64) u128 { |
lib/std/special/compiler_rt/floatuntitf_test.zig+72-72| ... | ... | @@ -6,94 +6,94 @@ |
| 6 | 6 | const __floatuntitf = @import("floatuntitf.zig").__floatuntitf; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__floatuntitf(a: u128, expected: f128) void { | |
| 9 | fn test__floatuntitf(a: u128, expected: f128) !void { | |
| 10 | 10 | const x = __floatuntitf(a); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "floatuntitf" { |
| 15 | test__floatuntitf(0, 0.0); | |
| 15 | try test__floatuntitf(0, 0.0); | |
| 16 | 16 | |
| 17 | test__floatuntitf(1, 1.0); | |
| 18 | test__floatuntitf(2, 2.0); | |
| 19 | test__floatuntitf(20, 20.0); | |
| 17 | try test__floatuntitf(1, 1.0); | |
| 18 | try test__floatuntitf(2, 2.0); | |
| 19 | try test__floatuntitf(20, 20.0); | |
| 20 | 20 | |
| 21 | test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 23 | test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 24 | test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 25 | test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59); | |
| 26 | test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60); | |
| 27 | test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60); | |
| 21 | try test__floatuntitf(0x7FFFFF8000000000, 0x1.FFFFFEp+62); | |
| 22 | try test__floatuntitf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62); | |
| 23 | try test__floatuntitf(0x7FFFFF0000000000, 0x1.FFFFFCp+62); | |
| 24 | try test__floatuntitf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62); | |
| 25 | try test__floatuntitf(0x7FFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFEp+59); | |
| 26 | try test__floatuntitf(0xFFFFFFFFFFFFFFFE, 0xF.FFFFFFFFFFFFFFEp+60); | |
| 27 | try test__floatuntitf(0xFFFFFFFFFFFFFFFF, 0xF.FFFFFFFFFFFFFFFp+60); | |
| 28 | 28 | |
| 29 | test__floatuntitf(0x8000008000000000, 0x8.000008p+60); | |
| 30 | test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60); | |
| 31 | test__floatuntitf(0x8000010000000000, 0x8.00001p+60); | |
| 32 | test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60); | |
| 29 | try test__floatuntitf(0x8000008000000000, 0x8.000008p+60); | |
| 30 | try test__floatuntitf(0x8000000000000800, 0x8.0000000000008p+60); | |
| 31 | try test__floatuntitf(0x8000010000000000, 0x8.00001p+60); | |
| 32 | try test__floatuntitf(0x8000000000001000, 0x8.000000000001p+60); | |
| 33 | 33 | |
| 34 | test__floatuntitf(0x8000000000000000, 0x8p+60); | |
| 35 | test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60); | |
| 34 | try test__floatuntitf(0x8000000000000000, 0x8p+60); | |
| 35 | try test__floatuntitf(0x8000000000000001, 0x8.000000000000001p+60); | |
| 36 | 36 | |
| 37 | test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 37 | try test__floatuntitf(0x0007FB72E8000000, 0x1.FEDCBAp+50); | |
| 38 | 38 | |
| 39 | test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 39 | try test__floatuntitf(0x0007FB72EA000000, 0x1.FEDCBA8p+50); | |
| 40 | try test__floatuntitf(0x0007FB72EB000000, 0x1.FEDCBACp+50); | |
| 41 | try test__floatuntitf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50); | |
| 42 | try test__floatuntitf(0x0007FB72EC000000, 0x1.FEDCBBp+50); | |
| 43 | try test__floatuntitf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50); | |
| 44 | 44 | |
| 45 | test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 45 | try test__floatuntitf(0x0007FB72E6000000, 0x1.FEDCB98p+50); | |
| 46 | try test__floatuntitf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50); | |
| 47 | try test__floatuntitf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50); | |
| 48 | try test__floatuntitf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50); | |
| 49 | try test__floatuntitf(0x0007FB72E4000000, 0x1.FEDCB9p+50); | |
| 50 | 50 | |
| 51 | test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57); | |
| 53 | test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57); | |
| 54 | test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57); | |
| 55 | test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57); | |
| 56 | test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57); | |
| 57 | test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57); | |
| 58 | test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57); | |
| 59 | test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57); | |
| 60 | test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57); | |
| 61 | test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57); | |
| 62 | test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57); | |
| 63 | test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57); | |
| 64 | test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57); | |
| 65 | test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 51 | try test__floatuntitf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57); | |
| 52 | try test__floatuntitf(0x023479FD0E092DA1, 0x1.1A3CFE870496D08p+57); | |
| 53 | try test__floatuntitf(0x023479FD0E092DB0, 0x1.1A3CFE870496D8p+57); | |
| 54 | try test__floatuntitf(0x023479FD0E092DB8, 0x1.1A3CFE870496DCp+57); | |
| 55 | try test__floatuntitf(0x023479FD0E092DB6, 0x1.1A3CFE870496DBp+57); | |
| 56 | try test__floatuntitf(0x023479FD0E092DBF, 0x1.1A3CFE870496DF8p+57); | |
| 57 | try test__floatuntitf(0x023479FD0E092DC1, 0x1.1A3CFE870496E08p+57); | |
| 58 | try test__floatuntitf(0x023479FD0E092DC7, 0x1.1A3CFE870496E38p+57); | |
| 59 | try test__floatuntitf(0x023479FD0E092DC8, 0x1.1A3CFE870496E4p+57); | |
| 60 | try test__floatuntitf(0x023479FD0E092DCF, 0x1.1A3CFE870496E78p+57); | |
| 61 | try test__floatuntitf(0x023479FD0E092DD0, 0x1.1A3CFE870496E8p+57); | |
| 62 | try test__floatuntitf(0x023479FD0E092DD1, 0x1.1A3CFE870496E88p+57); | |
| 63 | try test__floatuntitf(0x023479FD0E092DD8, 0x1.1A3CFE870496ECp+57); | |
| 64 | try test__floatuntitf(0x023479FD0E092DDF, 0x1.1A3CFE870496EF8p+57); | |
| 65 | try test__floatuntitf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57); | |
| 66 | 66 | |
| 67 | test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121); | |
| 69 | test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121); | |
| 70 | test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121); | |
| 71 | test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121); | |
| 72 | test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121); | |
| 73 | test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121); | |
| 74 | test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121); | |
| 75 | test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121); | |
| 76 | test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121); | |
| 77 | test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121); | |
| 78 | test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121); | |
| 79 | test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121); | |
| 80 | test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121); | |
| 81 | test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 67 | try test__floatuntitf(make_ti(0x023479FD0E092DC0, 0), 0x1.1A3CFE870496Ep+121); | |
| 68 | try test__floatuntitf(make_ti(0x023479FD0E092DA1, 1), 0x1.1A3CFE870496D08p+121); | |
| 69 | try test__floatuntitf(make_ti(0x023479FD0E092DB0, 2), 0x1.1A3CFE870496D8p+121); | |
| 70 | try test__floatuntitf(make_ti(0x023479FD0E092DB8, 3), 0x1.1A3CFE870496DCp+121); | |
| 71 | try test__floatuntitf(make_ti(0x023479FD0E092DB6, 4), 0x1.1A3CFE870496DBp+121); | |
| 72 | try test__floatuntitf(make_ti(0x023479FD0E092DBF, 5), 0x1.1A3CFE870496DF8p+121); | |
| 73 | try test__floatuntitf(make_ti(0x023479FD0E092DC1, 6), 0x1.1A3CFE870496E08p+121); | |
| 74 | try test__floatuntitf(make_ti(0x023479FD0E092DC7, 7), 0x1.1A3CFE870496E38p+121); | |
| 75 | try test__floatuntitf(make_ti(0x023479FD0E092DC8, 8), 0x1.1A3CFE870496E4p+121); | |
| 76 | try test__floatuntitf(make_ti(0x023479FD0E092DCF, 9), 0x1.1A3CFE870496E78p+121); | |
| 77 | try test__floatuntitf(make_ti(0x023479FD0E092DD0, 0), 0x1.1A3CFE870496E8p+121); | |
| 78 | try test__floatuntitf(make_ti(0x023479FD0E092DD1, 11), 0x1.1A3CFE870496E88p+121); | |
| 79 | try test__floatuntitf(make_ti(0x023479FD0E092DD8, 12), 0x1.1A3CFE870496ECp+121); | |
| 80 | try test__floatuntitf(make_ti(0x023479FD0E092DDF, 13), 0x1.1A3CFE870496EF8p+121); | |
| 81 | try test__floatuntitf(make_ti(0x023479FD0E092DE0, 14), 0x1.1A3CFE870496Fp+121); | |
| 82 | 82 | |
| 83 | test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63); | |
| 83 | try test__floatuntitf(make_ti(0, 0xFFFFFFFFFFFFFFFF), 0x1.FFFFFFFFFFFFFFFEp+63); | |
| 84 | 84 | |
| 85 | test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127); | |
| 86 | test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128); | |
| 85 | try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0x0000000000000000), 0x1.FFFFFFFFFFFFFFFEp+127); | |
| 86 | try test__floatuntitf(make_ti(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0x1.0000000000000000p+128); | |
| 87 | 87 | |
| 88 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 89 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 90 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 91 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 92 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 93 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 94 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 95 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 96 | test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 88 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC2801), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 89 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3000), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 90 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC37FF), 0x1.23456789ABCDEF0123456789ABC3p+124); | |
| 91 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC3800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 92 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4000), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 93 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC47FF), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 94 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4800), 0x1.23456789ABCDEF0123456789ABC4p+124); | |
| 95 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC4801), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 96 | try test__floatuntitf(make_ti(0x123456789ABCDEF0, 0x123456789ABC57FF), 0x1.23456789ABCDEF0123456789ABC5p+124); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | fn make_ti(high: u64, low: u64) u128 { |
lib/std/special/compiler_rt/int.zig+65-65| ... | ... | @@ -58,13 +58,13 @@ test "test_divdi3" { |
| 58 | 58 | }; |
| 59 | 59 | |
| 60 | 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 | } |
| 64 | 64 | |
| 65 | fn test_one_divdi3(a: i64, b: i64, expected_q: i64) void { | |
| 65 | fn test_one_divdi3(a: i64, b: i64, expected_q: i64) !void { | |
| 66 | 66 | const q: i64 = __divdi3(a, b); |
| 67 | testing.expect(q == expected_q); | |
| 67 | try testing.expect(q == expected_q); | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 { |
| ... | ... | @@ -98,13 +98,13 @@ test "test_moddi3" { |
| 98 | 98 | }; |
| 99 | 99 | |
| 100 | 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 | } |
| 104 | 104 | |
| 105 | fn test_one_moddi3(a: i64, b: i64, expected_r: i64) void { | |
| 105 | fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void { | |
| 106 | 106 | const r: i64 = __moddi3(a, b); |
| 107 | testing.expect(r == expected_r); | |
| 107 | try testing.expect(r == expected_r); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 { |
| ... | ... | @@ -121,16 +121,16 @@ pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 { |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | test "test_umoddi3" { |
| 124 | test_one_umoddi3(0, 1, 0); | |
| 125 | test_one_umoddi3(2, 1, 0); | |
| 126 | test_one_umoddi3(0x8000000000000000, 1, 0x0); | |
| 127 | test_one_umoddi3(0x8000000000000000, 2, 0x0); | |
| 128 | test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1); | |
| 124 | try test_one_umoddi3(0, 1, 0); | |
| 125 | try test_one_umoddi3(2, 1, 0); | |
| 126 | try test_one_umoddi3(0x8000000000000000, 1, 0x0); | |
| 127 | try test_one_umoddi3(0x8000000000000000, 2, 0x0); | |
| 128 | try test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void { | |
| 131 | fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void { | |
| 132 | 132 | const r = __umoddi3(a, b); |
| 133 | testing.expect(r == expected_r); | |
| 133 | try testing.expect(r == expected_r); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 { |
| ... | ... | @@ -159,14 +159,14 @@ test "test_divmodsi4" { |
| 159 | 159 | }; |
| 160 | 160 | |
| 161 | 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 | } |
| 165 | 165 | |
| 166 | fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) void { | |
| 166 | fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void { | |
| 167 | 167 | var r: i32 = undefined; |
| 168 | 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 | } |
| 171 | 171 | |
| 172 | 172 | pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 { |
| ... | ... | @@ -207,13 +207,13 @@ test "test_divsi3" { |
| 207 | 207 | }; |
| 208 | 208 | |
| 209 | 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 | } |
| 213 | 213 | |
| 214 | fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void { | |
| 214 | fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void { | |
| 215 | 215 | const q: i32 = __divsi3(a, b); |
| 216 | testing.expect(q == expected_q); | |
| 216 | try testing.expect(q == expected_q); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 { |
| ... | ... | @@ -394,13 +394,13 @@ test "test_udivsi3" { |
| 394 | 394 | }; |
| 395 | 395 | |
| 396 | 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 | } |
| 400 | 400 | |
| 401 | fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) void { | |
| 401 | fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void { | |
| 402 | 402 | const q: u32 = __udivsi3(a, b); |
| 403 | testing.expect(q == expected_q); | |
| 403 | try testing.expect(q == expected_q); | |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 { |
| ... | ... | @@ -425,13 +425,13 @@ test "test_modsi3" { |
| 425 | 425 | }; |
| 426 | 426 | |
| 427 | 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 | } |
| 431 | 431 | |
| 432 | fn test_one_modsi3(a: i32, b: i32, expected_r: i32) void { | |
| 432 | fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void { | |
| 433 | 433 | const r: i32 = __modsi3(a, b); |
| 434 | testing.expect(r == expected_r); | |
| 434 | try testing.expect(r == expected_r); | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 { |
| ... | ... | @@ -577,13 +577,13 @@ test "test_umodsi3" { |
| 577 | 577 | }; |
| 578 | 578 | |
| 579 | 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 | } |
| 583 | 583 | |
| 584 | fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void { | |
| 584 | fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void { | |
| 585 | 585 | const r: u32 = __umodsi3(a, b); |
| 586 | testing.expect(r == expected_r); | |
| 586 | try testing.expect(r == expected_r); | |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | 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 | 602 | return @bitCast(i32, r); |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | fn test_one_mulsi3(a: i32, b: i32, result: i32) void { | |
| 606 | testing.expectEqual(result, __mulsi3(a, b)); | |
| 605 | fn test_one_mulsi3(a: i32, b: i32, result: i32) !void { | |
| 606 | try testing.expectEqual(result, __mulsi3(a, b)); | |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | test "mulsi3" { |
| 610 | test_one_mulsi3(0, 0, 0); | |
| 611 | test_one_mulsi3(0, 1, 0); | |
| 612 | test_one_mulsi3(1, 0, 0); | |
| 613 | test_one_mulsi3(0, 10, 0); | |
| 614 | test_one_mulsi3(10, 0, 0); | |
| 615 | test_one_mulsi3(0, maxInt(i32), 0); | |
| 616 | test_one_mulsi3(maxInt(i32), 0, 0); | |
| 617 | test_one_mulsi3(0, -1, 0); | |
| 618 | test_one_mulsi3(-1, 0, 0); | |
| 619 | test_one_mulsi3(0, -10, 0); | |
| 620 | test_one_mulsi3(-10, 0, 0); | |
| 621 | test_one_mulsi3(0, minInt(i32), 0); | |
| 622 | test_one_mulsi3(minInt(i32), 0, 0); | |
| 623 | test_one_mulsi3(1, 1, 1); | |
| 624 | test_one_mulsi3(1, 10, 10); | |
| 625 | test_one_mulsi3(10, 1, 10); | |
| 626 | test_one_mulsi3(1, maxInt(i32), maxInt(i32)); | |
| 627 | test_one_mulsi3(maxInt(i32), 1, maxInt(i32)); | |
| 628 | test_one_mulsi3(1, -1, -1); | |
| 629 | test_one_mulsi3(1, -10, -10); | |
| 630 | test_one_mulsi3(-10, 1, -10); | |
| 631 | test_one_mulsi3(1, minInt(i32), minInt(i32)); | |
| 632 | test_one_mulsi3(minInt(i32), 1, minInt(i32)); | |
| 633 | test_one_mulsi3(46340, 46340, 2147395600); | |
| 634 | test_one_mulsi3(-46340, 46340, -2147395600); | |
| 635 | test_one_mulsi3(46340, -46340, -2147395600); | |
| 636 | test_one_mulsi3(-46340, -46340, 2147395600); | |
| 637 | test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176)); | |
| 638 | test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176)); | |
| 639 | test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176)); | |
| 640 | test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176)); | |
| 641 | test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176)); | |
| 642 | test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176)); | |
| 643 | test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176)); | |
| 644 | test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176)); | |
| 610 | try test_one_mulsi3(0, 0, 0); | |
| 611 | try test_one_mulsi3(0, 1, 0); | |
| 612 | try test_one_mulsi3(1, 0, 0); | |
| 613 | try test_one_mulsi3(0, 10, 0); | |
| 614 | try test_one_mulsi3(10, 0, 0); | |
| 615 | try test_one_mulsi3(0, maxInt(i32), 0); | |
| 616 | try test_one_mulsi3(maxInt(i32), 0, 0); | |
| 617 | try test_one_mulsi3(0, -1, 0); | |
| 618 | try test_one_mulsi3(-1, 0, 0); | |
| 619 | try test_one_mulsi3(0, -10, 0); | |
| 620 | try test_one_mulsi3(-10, 0, 0); | |
| 621 | try test_one_mulsi3(0, minInt(i32), 0); | |
| 622 | try test_one_mulsi3(minInt(i32), 0, 0); | |
| 623 | try test_one_mulsi3(1, 1, 1); | |
| 624 | try test_one_mulsi3(1, 10, 10); | |
| 625 | try test_one_mulsi3(10, 1, 10); | |
| 626 | try test_one_mulsi3(1, maxInt(i32), maxInt(i32)); | |
| 627 | try test_one_mulsi3(maxInt(i32), 1, maxInt(i32)); | |
| 628 | try test_one_mulsi3(1, -1, -1); | |
| 629 | try test_one_mulsi3(1, -10, -10); | |
| 630 | try test_one_mulsi3(-10, 1, -10); | |
| 631 | try test_one_mulsi3(1, minInt(i32), minInt(i32)); | |
| 632 | try test_one_mulsi3(minInt(i32), 1, minInt(i32)); | |
| 633 | try test_one_mulsi3(46340, 46340, 2147395600); | |
| 634 | try test_one_mulsi3(-46340, 46340, -2147395600); | |
| 635 | try test_one_mulsi3(46340, -46340, -2147395600); | |
| 636 | try test_one_mulsi3(-46340, -46340, 2147395600); | |
| 637 | try test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176)); | |
| 638 | try test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176)); | |
| 639 | try test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176)); | |
| 640 | try test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176)); | |
| 641 | try test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176)); | |
| 642 | try test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176)); | |
| 643 | try test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176)); | |
| 644 | try test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176)); | |
| 645 | 645 | } |
lib/std/special/compiler_rt/lshrdi3_test.zig+47-47| ... | ... | @@ -6,55 +6,55 @@ |
| 6 | 6 | const __lshrdi3 = @import("shift.zig").__lshrdi3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__lshrdi3(a: i64, b: i32, expected: u64) void { | |
| 9 | fn test__lshrdi3(a: i64, b: i32, expected: u64) !void { | |
| 10 | 10 | const x = __lshrdi3(a, b); |
| 11 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 11 | try testing.expectEqual(@bitCast(i64, expected), x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "lshrdi3" { |
| 15 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 17 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 18 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 19 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 20 | ||
| 21 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 22 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 23 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 24 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 25 | ||
| 26 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 27 | ||
| 28 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 29 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 30 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 31 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 32 | ||
| 33 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 34 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 35 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 36 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 37 | ||
| 38 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 39 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908); | |
| 40 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84); | |
| 41 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642); | |
| 42 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321); | |
| 43 | ||
| 44 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987); | |
| 45 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3); | |
| 46 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61); | |
| 47 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530); | |
| 48 | ||
| 49 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98); | |
| 50 | ||
| 51 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C); | |
| 52 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6); | |
| 53 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753); | |
| 54 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9); | |
| 55 | ||
| 56 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA); | |
| 57 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5); | |
| 58 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2); | |
| 59 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1); | |
| 15 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 16 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 17 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 18 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 19 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 20 | ||
| 21 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 22 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 23 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 24 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 25 | ||
| 26 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 27 | ||
| 28 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 29 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 30 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 31 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 32 | ||
| 33 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 34 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 35 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 36 | try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 37 | ||
| 38 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 39 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908); | |
| 40 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84); | |
| 41 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642); | |
| 42 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321); | |
| 43 | ||
| 44 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987); | |
| 45 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3); | |
| 46 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61); | |
| 47 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530); | |
| 48 | ||
| 49 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98); | |
| 50 | ||
| 51 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C); | |
| 52 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6); | |
| 53 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753); | |
| 54 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9); | |
| 55 | ||
| 56 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA); | |
| 57 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5); | |
| 58 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2); | |
| 59 | try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1); | |
| 60 | 60 | } |
lib/std/special/compiler_rt/lshrti3_test.zig+38-38| ... | ... | @@ -6,46 +6,46 @@ |
| 6 | 6 | const __lshrti3 = @import("shift.zig").__lshrti3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__lshrti3(a: i128, b: i32, expected: i128) void { | |
| 9 | fn test__lshrti3(a: i128, b: i32, expected: i128) !void { | |
| 10 | 10 | const x = __lshrti3(a, b); |
| 11 | testing.expectEqual(expected, x); | |
| 11 | try testing.expectEqual(expected, x); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "lshrti3" { |
| 15 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A))); | |
| 17 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85))); | |
| 18 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642))); | |
| 19 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321))); | |
| 20 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987))); | |
| 21 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3))); | |
| 22 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61))); | |
| 23 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530))); | |
| 24 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98))); | |
| 25 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C))); | |
| 26 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6))); | |
| 27 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753))); | |
| 28 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9))); | |
| 29 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F))); | |
| 30 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF))); | |
| 31 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857))); | |
| 32 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B))); | |
| 33 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215))); | |
| 34 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A))); | |
| 35 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85))); | |
| 36 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642))); | |
| 37 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321))); | |
| 38 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987))); | |
| 39 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3))); | |
| 40 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61))); | |
| 41 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530))); | |
| 42 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98))); | |
| 43 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C))); | |
| 44 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6))); | |
| 45 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753))); | |
| 46 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9))); | |
| 47 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F))); | |
| 48 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007))); | |
| 49 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003))); | |
| 50 | test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001))); | |
| 15 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215))); | |
| 16 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A))); | |
| 17 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85))); | |
| 18 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642))); | |
| 19 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321))); | |
| 20 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987))); | |
| 21 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3))); | |
| 22 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61))); | |
| 23 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530))); | |
| 24 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98))); | |
| 25 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C))); | |
| 26 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6))); | |
| 27 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753))); | |
| 28 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9))); | |
| 29 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F))); | |
| 30 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF))); | |
| 31 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857))); | |
| 32 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B))); | |
| 33 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215))); | |
| 34 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A))); | |
| 35 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85))); | |
| 36 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642))); | |
| 37 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321))); | |
| 38 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987))); | |
| 39 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3))); | |
| 40 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61))); | |
| 41 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530))); | |
| 42 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98))); | |
| 43 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C))); | |
| 44 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6))); | |
| 45 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753))); | |
| 46 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9))); | |
| 47 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F))); | |
| 48 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007))); | |
| 49 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003))); | |
| 50 | try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001))); | |
| 51 | 51 | } |
lib/std/special/compiler_rt/modti3_test.zig+20-20| ... | ... | @@ -6,32 +6,32 @@ |
| 6 | 6 | const __modti3 = @import("modti3.zig").__modti3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__modti3(a: i128, b: i128, expected: i128) void { | |
| 9 | fn test__modti3(a: i128, b: i128, expected: i128) !void { | |
| 10 | 10 | const x = __modti3(a, b); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "modti3" { |
| 15 | test__modti3(0, 1, 0); | |
| 16 | test__modti3(0, -1, 0); | |
| 17 | test__modti3(5, 3, 2); | |
| 18 | test__modti3(5, -3, 2); | |
| 19 | test__modti3(-5, 3, -2); | |
| 20 | test__modti3(-5, -3, -2); | |
| 15 | try test__modti3(0, 1, 0); | |
| 16 | try test__modti3(0, -1, 0); | |
| 17 | try test__modti3(5, 3, 2); | |
| 18 | try test__modti3(5, -3, 2); | |
| 19 | try test__modti3(-5, 3, -2); | |
| 20 | try test__modti3(-5, -3, -2); | |
| 21 | 21 | |
| 22 | test__modti3(0x8000000000000000, 1, 0x0); | |
| 23 | test__modti3(0x8000000000000000, -1, 0x0); | |
| 24 | test__modti3(0x8000000000000000, 2, 0x0); | |
| 25 | test__modti3(0x8000000000000000, -2, 0x0); | |
| 26 | test__modti3(0x8000000000000000, 3, 2); | |
| 27 | test__modti3(0x8000000000000000, -3, 2); | |
| 22 | try test__modti3(0x8000000000000000, 1, 0x0); | |
| 23 | try test__modti3(0x8000000000000000, -1, 0x0); | |
| 24 | try test__modti3(0x8000000000000000, 2, 0x0); | |
| 25 | try test__modti3(0x8000000000000000, -2, 0x0); | |
| 26 | try test__modti3(0x8000000000000000, 3, 2); | |
| 27 | try test__modti3(0x8000000000000000, -3, 2); | |
| 28 | 28 | |
| 29 | test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0); | |
| 30 | test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0); | |
| 31 | test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0); | |
| 32 | test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0); | |
| 33 | test__modti3(make_ti(0x8000000000000000, 0), 3, -2); | |
| 34 | test__modti3(make_ti(0x8000000000000000, 0), -3, -2); | |
| 29 | try test__modti3(make_ti(0x8000000000000000, 0), 1, 0x0); | |
| 30 | try test__modti3(make_ti(0x8000000000000000, 0), -1, 0x0); | |
| 31 | try test__modti3(make_ti(0x8000000000000000, 0), 2, 0x0); | |
| 32 | try test__modti3(make_ti(0x8000000000000000, 0), -2, 0x0); | |
| 33 | try test__modti3(make_ti(0x8000000000000000, 0), 3, -2); | |
| 34 | try test__modti3(make_ti(0x8000000000000000, 0), -3, -2); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | fn 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 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void { | |
| 37 | fn test__multf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void { | |
| 38 | 38 | const x = __multf3(a, b); |
| 39 | 39 | |
| 40 | 40 | if (compareResultLD(x, expected_hi, expected_lo)) |
| ... | ... | @@ -50,42 +50,42 @@ fn makeNaN128(rand: u64) f128 { |
| 50 | 50 | } |
| 51 | 51 | test "multf3" { |
| 52 | 52 | // qNaN * any = qNaN |
| 53 | test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 53 | try test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0); | |
| 54 | 54 | |
| 55 | 55 | // NaN * any = NaN |
| 56 | 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 | 58 | // inf * any = inf |
| 59 | test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); | |
| 59 | try test__multf3(inf128, 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0); | |
| 60 | 60 | |
| 61 | 61 | // any * any |
| 62 | test__multf3( | |
| 62 | try test__multf3( | |
| 63 | 63 | @bitCast(f128, @as(u128, 0x40042eab345678439abcdefea5678234)), |
| 64 | 64 | @bitCast(f128, @as(u128, 0x3ffeedcb34a235253948765432134675)), |
| 65 | 65 | 0x400423e7f9e3c9fc, |
| 66 | 66 | 0xd906c2c2a85777c4, |
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | test__multf3( | |
| 69 | try test__multf3( | |
| 70 | 70 | @bitCast(f128, @as(u128, 0x3fcd353e45674d89abacc3a2ebf3ff50)), |
| 71 | 71 | @bitCast(f128, @as(u128, 0x3ff6ed8764648369535adf4be3214568)), |
| 72 | 72 | 0x3fc52a163c6223fc, |
| 73 | 73 | 0xc94c4bf0430768b4, |
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | test__multf3( | |
| 76 | try test__multf3( | |
| 77 | 77 | 0x1.234425696abcad34a35eeffefdcbap+456, |
| 78 | 78 | 0x451.ed98d76e5d46e5f24323dff21ffp+600, |
| 79 | 79 | 0x44293a91de5e0e94, |
| 80 | 80 | 0xe8ed17cc2cdf64ac, |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | test__multf3( | |
| 83 | try test__multf3( | |
| 84 | 84 | @bitCast(f128, @as(u128, 0x3f154356473c82a9fabf2d22ace345df)), |
| 85 | 85 | @bitCast(f128, @as(u128, 0x3e38eda98765476743ab21da23d45679)), |
| 86 | 86 | 0x3d4f37c1a3137cae, |
| 87 | 87 | 0xfc6807048bc2836a, |
| 88 | 88 | ); |
| 89 | 89 | |
| 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 | 6 | const __muldi3 = @import("muldi3.zig").__muldi3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__muldi3(a: i64, b: i64, expected: i64) void { | |
| 9 | fn test__muldi3(a: i64, b: i64, expected: i64) !void { | |
| 10 | 10 | const x = __muldi3(a, b); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "muldi3" { |
| 15 | test__muldi3(0, 0, 0); | |
| 16 | test__muldi3(0, 1, 0); | |
| 17 | test__muldi3(1, 0, 0); | |
| 18 | test__muldi3(0, 10, 0); | |
| 19 | test__muldi3(10, 0, 0); | |
| 20 | test__muldi3(0, 81985529216486895, 0); | |
| 21 | test__muldi3(81985529216486895, 0, 0); | |
| 22 | ||
| 23 | test__muldi3(0, -1, 0); | |
| 24 | test__muldi3(-1, 0, 0); | |
| 25 | test__muldi3(0, -10, 0); | |
| 26 | test__muldi3(-10, 0, 0); | |
| 27 | test__muldi3(0, -81985529216486895, 0); | |
| 28 | test__muldi3(-81985529216486895, 0, 0); | |
| 29 | ||
| 30 | test__muldi3(1, 1, 1); | |
| 31 | test__muldi3(1, 10, 10); | |
| 32 | test__muldi3(10, 1, 10); | |
| 33 | test__muldi3(1, 81985529216486895, 81985529216486895); | |
| 34 | test__muldi3(81985529216486895, 1, 81985529216486895); | |
| 35 | ||
| 36 | test__muldi3(1, -1, -1); | |
| 37 | test__muldi3(1, -10, -10); | |
| 38 | test__muldi3(-10, 1, -10); | |
| 39 | test__muldi3(1, -81985529216486895, -81985529216486895); | |
| 40 | test__muldi3(-81985529216486895, 1, -81985529216486895); | |
| 41 | ||
| 42 | test__muldi3(3037000499, 3037000499, 9223372030926249001); | |
| 43 | test__muldi3(-3037000499, 3037000499, -9223372030926249001); | |
| 44 | test__muldi3(3037000499, -3037000499, -9223372030926249001); | |
| 45 | test__muldi3(-3037000499, -3037000499, 9223372030926249001); | |
| 46 | ||
| 47 | test__muldi3(4398046511103, 2097152, 9223372036852678656); | |
| 48 | test__muldi3(-4398046511103, 2097152, -9223372036852678656); | |
| 49 | test__muldi3(4398046511103, -2097152, -9223372036852678656); | |
| 50 | test__muldi3(-4398046511103, -2097152, 9223372036852678656); | |
| 51 | ||
| 52 | test__muldi3(2097152, 4398046511103, 9223372036852678656); | |
| 53 | test__muldi3(-2097152, 4398046511103, -9223372036852678656); | |
| 54 | test__muldi3(2097152, -4398046511103, -9223372036852678656); | |
| 55 | test__muldi3(-2097152, -4398046511103, 9223372036852678656); | |
| 15 | try test__muldi3(0, 0, 0); | |
| 16 | try test__muldi3(0, 1, 0); | |
| 17 | try test__muldi3(1, 0, 0); | |
| 18 | try test__muldi3(0, 10, 0); | |
| 19 | try test__muldi3(10, 0, 0); | |
| 20 | try test__muldi3(0, 81985529216486895, 0); | |
| 21 | try test__muldi3(81985529216486895, 0, 0); | |
| 22 | ||
| 23 | try test__muldi3(0, -1, 0); | |
| 24 | try test__muldi3(-1, 0, 0); | |
| 25 | try test__muldi3(0, -10, 0); | |
| 26 | try test__muldi3(-10, 0, 0); | |
| 27 | try test__muldi3(0, -81985529216486895, 0); | |
| 28 | try test__muldi3(-81985529216486895, 0, 0); | |
| 29 | ||
| 30 | try test__muldi3(1, 1, 1); | |
| 31 | try test__muldi3(1, 10, 10); | |
| 32 | try test__muldi3(10, 1, 10); | |
| 33 | try test__muldi3(1, 81985529216486895, 81985529216486895); | |
| 34 | try test__muldi3(81985529216486895, 1, 81985529216486895); | |
| 35 | ||
| 36 | try test__muldi3(1, -1, -1); | |
| 37 | try test__muldi3(1, -10, -10); | |
| 38 | try test__muldi3(-10, 1, -10); | |
| 39 | try test__muldi3(1, -81985529216486895, -81985529216486895); | |
| 40 | try test__muldi3(-81985529216486895, 1, -81985529216486895); | |
| 41 | ||
| 42 | try test__muldi3(3037000499, 3037000499, 9223372030926249001); | |
| 43 | try test__muldi3(-3037000499, 3037000499, -9223372030926249001); | |
| 44 | try test__muldi3(3037000499, -3037000499, -9223372030926249001); | |
| 45 | try test__muldi3(-3037000499, -3037000499, 9223372030926249001); | |
| 46 | ||
| 47 | try test__muldi3(4398046511103, 2097152, 9223372036852678656); | |
| 48 | try test__muldi3(-4398046511103, 2097152, -9223372036852678656); | |
| 49 | try test__muldi3(4398046511103, -2097152, -9223372036852678656); | |
| 50 | try test__muldi3(-4398046511103, -2097152, 9223372036852678656); | |
| 51 | ||
| 52 | try test__muldi3(2097152, 4398046511103, 9223372036852678656); | |
| 53 | try test__muldi3(-2097152, 4398046511103, -9223372036852678656); | |
| 54 | try test__muldi3(2097152, -4398046511103, -9223372036852678656); | |
| 55 | try test__muldi3(-2097152, -4398046511103, 9223372036852678656); | |
| 56 | 56 | } |
lib/std/special/compiler_rt/mulodi4_test.zig+67-67| ... | ... | @@ -6,85 +6,85 @@ |
| 6 | 6 | const __mulodi4 = @import("mulodi4.zig").__mulodi4; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void { | |
| 9 | fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) !void { | |
| 10 | 10 | var overflow: c_int = undefined; |
| 11 | 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 | } |
| 14 | 14 | |
| 15 | 15 | test "mulodi4" { |
| 16 | test__mulodi4(0, 0, 0, 0); | |
| 17 | test__mulodi4(0, 1, 0, 0); | |
| 18 | test__mulodi4(1, 0, 0, 0); | |
| 19 | test__mulodi4(0, 10, 0, 0); | |
| 20 | test__mulodi4(10, 0, 0, 0); | |
| 21 | test__mulodi4(0, 81985529216486895, 0, 0); | |
| 22 | test__mulodi4(81985529216486895, 0, 0, 0); | |
| 16 | try test__mulodi4(0, 0, 0, 0); | |
| 17 | try test__mulodi4(0, 1, 0, 0); | |
| 18 | try test__mulodi4(1, 0, 0, 0); | |
| 19 | try test__mulodi4(0, 10, 0, 0); | |
| 20 | try test__mulodi4(10, 0, 0, 0); | |
| 21 | try test__mulodi4(0, 81985529216486895, 0, 0); | |
| 22 | try test__mulodi4(81985529216486895, 0, 0, 0); | |
| 23 | 23 | |
| 24 | test__mulodi4(0, -1, 0, 0); | |
| 25 | test__mulodi4(-1, 0, 0, 0); | |
| 26 | test__mulodi4(0, -10, 0, 0); | |
| 27 | test__mulodi4(-10, 0, 0, 0); | |
| 28 | test__mulodi4(0, -81985529216486895, 0, 0); | |
| 29 | test__mulodi4(-81985529216486895, 0, 0, 0); | |
| 24 | try test__mulodi4(0, -1, 0, 0); | |
| 25 | try test__mulodi4(-1, 0, 0, 0); | |
| 26 | try test__mulodi4(0, -10, 0, 0); | |
| 27 | try test__mulodi4(-10, 0, 0, 0); | |
| 28 | try test__mulodi4(0, -81985529216486895, 0, 0); | |
| 29 | try test__mulodi4(-81985529216486895, 0, 0, 0); | |
| 30 | 30 | |
| 31 | test__mulodi4(1, 1, 1, 0); | |
| 32 | test__mulodi4(1, 10, 10, 0); | |
| 33 | test__mulodi4(10, 1, 10, 0); | |
| 34 | test__mulodi4(1, 81985529216486895, 81985529216486895, 0); | |
| 35 | test__mulodi4(81985529216486895, 1, 81985529216486895, 0); | |
| 31 | try test__mulodi4(1, 1, 1, 0); | |
| 32 | try test__mulodi4(1, 10, 10, 0); | |
| 33 | try test__mulodi4(10, 1, 10, 0); | |
| 34 | try test__mulodi4(1, 81985529216486895, 81985529216486895, 0); | |
| 35 | try test__mulodi4(81985529216486895, 1, 81985529216486895, 0); | |
| 36 | 36 | |
| 37 | test__mulodi4(1, -1, -1, 0); | |
| 38 | test__mulodi4(1, -10, -10, 0); | |
| 39 | test__mulodi4(-10, 1, -10, 0); | |
| 40 | test__mulodi4(1, -81985529216486895, -81985529216486895, 0); | |
| 41 | test__mulodi4(-81985529216486895, 1, -81985529216486895, 0); | |
| 37 | try test__mulodi4(1, -1, -1, 0); | |
| 38 | try test__mulodi4(1, -10, -10, 0); | |
| 39 | try test__mulodi4(-10, 1, -10, 0); | |
| 40 | try test__mulodi4(1, -81985529216486895, -81985529216486895, 0); | |
| 41 | try test__mulodi4(-81985529216486895, 1, -81985529216486895, 0); | |
| 42 | 42 | |
| 43 | test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0); | |
| 44 | test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0); | |
| 45 | test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0); | |
| 46 | test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0); | |
| 43 | try test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0); | |
| 44 | try test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0); | |
| 45 | try test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0); | |
| 46 | try test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0); | |
| 47 | 47 | |
| 48 | test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0); | |
| 49 | test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0); | |
| 50 | test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0); | |
| 51 | test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0); | |
| 48 | try test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0); | |
| 49 | try test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0); | |
| 50 | try test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0); | |
| 51 | try test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0); | |
| 52 | 52 | |
| 53 | test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0); | |
| 54 | test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0); | |
| 55 | test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0); | |
| 56 | test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0); | |
| 53 | try test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0); | |
| 54 | try test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0); | |
| 55 | try test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0); | |
| 56 | try test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0); | |
| 57 | 57 | |
| 58 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); | |
| 59 | test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); | |
| 60 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 61 | test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 62 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); | |
| 63 | test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); | |
| 64 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); | |
| 65 | test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); | |
| 66 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 67 | test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 58 | try test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); | |
| 59 | try test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); | |
| 60 | try test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 61 | try test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 62 | try test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); | |
| 63 | try test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); | |
| 64 | try test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); | |
| 65 | try test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); | |
| 66 | try test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 67 | try test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 68 | 68 | |
| 69 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 70 | test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 71 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 72 | test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 73 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0); | |
| 74 | test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0); | |
| 75 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0); | |
| 76 | test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0); | |
| 77 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 78 | test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 69 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 70 | try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 71 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), -1, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 72 | try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 73 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0, 0); | |
| 74 | try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000000)), 0, 0); | |
| 75 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 1, @bitCast(i64, @as(u64, 0x8000000000000000)), 0); | |
| 76 | try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 0); | |
| 77 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000000)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 78 | try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000000)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 79 | 79 | |
| 80 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 81 | test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 82 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); | |
| 83 | test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); | |
| 84 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0); | |
| 85 | test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0); | |
| 86 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 87 | test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 88 | test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 89 | test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 80 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -2, @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 81 | try test__mulodi4(-2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 1); | |
| 82 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); | |
| 83 | try test__mulodi4(-1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); | |
| 84 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0, 0); | |
| 85 | try test__mulodi4(0, @bitCast(i64, @as(u64, 0x8000000000000001)), 0, 0); | |
| 86 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 1, @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 87 | try test__mulodi4(1, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000001)), 0); | |
| 88 | try test__mulodi4(@bitCast(i64, @as(u64, 0x8000000000000001)), 2, @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 89 | try test__mulodi4(2, @bitCast(i64, @as(u64, 0x8000000000000001)), @bitCast(i64, @as(u64, 0x8000000000000000)), 1); | |
| 90 | 90 | } |
lib/std/special/compiler_rt/muloti4_test.zig+58-58| ... | ... | @@ -6,76 +6,76 @@ |
| 6 | 6 | const __muloti4 = @import("muloti4.zig").__muloti4; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void { | |
| 9 | fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) !void { | |
| 10 | 10 | var overflow: c_int = undefined; |
| 11 | 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 | } |
| 14 | 14 | |
| 15 | 15 | test "muloti4" { |
| 16 | test__muloti4(0, 0, 0, 0); | |
| 17 | test__muloti4(0, 1, 0, 0); | |
| 18 | test__muloti4(1, 0, 0, 0); | |
| 19 | test__muloti4(0, 10, 0, 0); | |
| 20 | test__muloti4(10, 0, 0, 0); | |
| 16 | try test__muloti4(0, 0, 0, 0); | |
| 17 | try test__muloti4(0, 1, 0, 0); | |
| 18 | try test__muloti4(1, 0, 0, 0); | |
| 19 | try test__muloti4(0, 10, 0, 0); | |
| 20 | try test__muloti4(10, 0, 0, 0); | |
| 21 | 21 | |
| 22 | test__muloti4(0, 81985529216486895, 0, 0); | |
| 23 | test__muloti4(81985529216486895, 0, 0, 0); | |
| 22 | try test__muloti4(0, 81985529216486895, 0, 0); | |
| 23 | try test__muloti4(81985529216486895, 0, 0, 0); | |
| 24 | 24 | |
| 25 | test__muloti4(0, -1, 0, 0); | |
| 26 | test__muloti4(-1, 0, 0, 0); | |
| 27 | test__muloti4(0, -10, 0, 0); | |
| 28 | test__muloti4(-10, 0, 0, 0); | |
| 29 | test__muloti4(0, -81985529216486895, 0, 0); | |
| 30 | test__muloti4(-81985529216486895, 0, 0, 0); | |
| 25 | try test__muloti4(0, -1, 0, 0); | |
| 26 | try test__muloti4(-1, 0, 0, 0); | |
| 27 | try test__muloti4(0, -10, 0, 0); | |
| 28 | try test__muloti4(-10, 0, 0, 0); | |
| 29 | try test__muloti4(0, -81985529216486895, 0, 0); | |
| 30 | try test__muloti4(-81985529216486895, 0, 0, 0); | |
| 31 | 31 | |
| 32 | test__muloti4(3037000499, 3037000499, 9223372030926249001, 0); | |
| 33 | test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0); | |
| 34 | test__muloti4(3037000499, -3037000499, -9223372030926249001, 0); | |
| 35 | test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0); | |
| 32 | try test__muloti4(3037000499, 3037000499, 9223372030926249001, 0); | |
| 33 | try test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0); | |
| 34 | try test__muloti4(3037000499, -3037000499, -9223372030926249001, 0); | |
| 35 | try test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0); | |
| 36 | 36 | |
| 37 | test__muloti4(4398046511103, 2097152, 9223372036852678656, 0); | |
| 38 | test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0); | |
| 39 | test__muloti4(4398046511103, -2097152, -9223372036852678656, 0); | |
| 40 | test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0); | |
| 37 | try test__muloti4(4398046511103, 2097152, 9223372036852678656, 0); | |
| 38 | try test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0); | |
| 39 | try test__muloti4(4398046511103, -2097152, -9223372036852678656, 0); | |
| 40 | try test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0); | |
| 41 | 41 | |
| 42 | test__muloti4(2097152, 4398046511103, 9223372036852678656, 0); | |
| 43 | test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0); | |
| 44 | test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); | |
| 45 | test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); | |
| 42 | try test__muloti4(2097152, 4398046511103, 9223372036852678656, 0); | |
| 43 | try test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0); | |
| 44 | try test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); | |
| 45 | try test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); | |
| 46 | 46 | |
| 47 | test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); | |
| 48 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 49 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 47 | try test__muloti4(@bitCast(i128, @as(u128, 0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, @as(u128, 0x000000000000000000B504F333F9DE5B)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); | |
| 48 | try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 49 | try test__muloti4(-2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 50 | 50 | |
| 51 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 52 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 53 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); | |
| 54 | test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); | |
| 55 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 56 | test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 57 | test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 58 | test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 51 | try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 52 | try test__muloti4(-1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 53 | try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); | |
| 54 | try test__muloti4(0, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); | |
| 55 | try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 56 | try test__muloti4(1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 57 | try test__muloti4(@bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 58 | try test__muloti4(2, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 59 | 59 | |
| 60 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 61 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 62 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 63 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 64 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0); | |
| 65 | test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0); | |
| 66 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); | |
| 67 | test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); | |
| 68 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 69 | test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 60 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 61 | try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 62 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), -1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 63 | try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 64 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0, 0); | |
| 65 | try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0, 0); | |
| 66 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); | |
| 67 | try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 0); | |
| 68 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 69 | try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 70 | 70 | |
| 71 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 72 | test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 73 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 74 | test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 75 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0); | |
| 76 | test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0); | |
| 77 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 78 | test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 79 | test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 80 | test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 71 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 72 | try test__muloti4(-2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1); | |
| 73 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), -1, @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 74 | try test__muloti4(-1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); | |
| 75 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0, 0); | |
| 76 | try test__muloti4(0, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0, 0); | |
| 77 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 78 | try test__muloti4(1, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 0); | |
| 79 | try test__muloti4(@bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), 2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 80 | try test__muloti4(2, @bitCast(i128, @as(u128, 0x80000000000000000000000000000001)), @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 1); | |
| 81 | 81 | } |
lib/std/special/compiler_rt/multi3_test.zig+45-45| ... | ... | @@ -6,53 +6,53 @@ |
| 6 | 6 | const __multi3 = @import("multi3.zig").__multi3; |
| 7 | 7 | const testing = @import("std").testing; |
| 8 | 8 | |
| 9 | fn test__multi3(a: i128, b: i128, expected: i128) void { | |
| 9 | fn test__multi3(a: i128, b: i128, expected: i128) !void { | |
| 10 | 10 | const x = __multi3(a, b); |
| 11 | testing.expect(x == expected); | |
| 11 | try testing.expect(x == expected); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "multi3" { |
| 15 | test__multi3(0, 0, 0); | |
| 16 | test__multi3(0, 1, 0); | |
| 17 | test__multi3(1, 0, 0); | |
| 18 | test__multi3(0, 10, 0); | |
| 19 | test__multi3(10, 0, 0); | |
| 20 | test__multi3(0, 81985529216486895, 0); | |
| 21 | test__multi3(81985529216486895, 0, 0); | |
| 22 | ||
| 23 | test__multi3(0, -1, 0); | |
| 24 | test__multi3(-1, 0, 0); | |
| 25 | test__multi3(0, -10, 0); | |
| 26 | test__multi3(-10, 0, 0); | |
| 27 | test__multi3(0, -81985529216486895, 0); | |
| 28 | test__multi3(-81985529216486895, 0, 0); | |
| 29 | ||
| 30 | test__multi3(1, 1, 1); | |
| 31 | test__multi3(1, 10, 10); | |
| 32 | test__multi3(10, 1, 10); | |
| 33 | test__multi3(1, 81985529216486895, 81985529216486895); | |
| 34 | test__multi3(81985529216486895, 1, 81985529216486895); | |
| 35 | ||
| 36 | test__multi3(1, -1, -1); | |
| 37 | test__multi3(1, -10, -10); | |
| 38 | test__multi3(-10, 1, -10); | |
| 39 | test__multi3(1, -81985529216486895, -81985529216486895); | |
| 40 | test__multi3(-81985529216486895, 1, -81985529216486895); | |
| 41 | ||
| 42 | test__multi3(3037000499, 3037000499, 9223372030926249001); | |
| 43 | test__multi3(-3037000499, 3037000499, -9223372030926249001); | |
| 44 | test__multi3(3037000499, -3037000499, -9223372030926249001); | |
| 45 | test__multi3(-3037000499, -3037000499, 9223372030926249001); | |
| 46 | ||
| 47 | test__multi3(4398046511103, 2097152, 9223372036852678656); | |
| 48 | test__multi3(-4398046511103, 2097152, -9223372036852678656); | |
| 49 | test__multi3(4398046511103, -2097152, -9223372036852678656); | |
| 50 | test__multi3(-4398046511103, -2097152, 9223372036852678656); | |
| 51 | ||
| 52 | test__multi3(2097152, 4398046511103, 9223372036852678656); | |
| 53 | test__multi3(-2097152, 4398046511103, -9223372036852678656); | |
| 54 | test__multi3(2097152, -4398046511103, -9223372036852678656); | |
| 55 | test__multi3(-2097152, -4398046511103, 9223372036852678656); | |
| 56 | ||
| 57 | test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000); | |
| 15 | try test__multi3(0, 0, 0); | |
| 16 | try test__multi3(0, 1, 0); | |
| 17 | try test__multi3(1, 0, 0); | |
| 18 | try test__multi3(0, 10, 0); | |
| 19 | try test__multi3(10, 0, 0); | |
| 20 | try test__multi3(0, 81985529216486895, 0); | |
| 21 | try test__multi3(81985529216486895, 0, 0); | |
| 22 | ||
| 23 | try test__multi3(0, -1, 0); | |
| 24 | try test__multi3(-1, 0, 0); | |
| 25 | try test__multi3(0, -10, 0); | |
| 26 | try test__multi3(-10, 0, 0); | |
| 27 | try test__multi3(0, -81985529216486895, 0); | |
| 28 | try test__multi3(-81985529216486895, 0, 0); | |
| 29 | ||
| 30 | try test__multi3(1, 1, 1); | |
| 31 | try test__multi3(1, 10, 10); | |
| 32 | try test__multi3(10, 1, 10); | |
| 33 | try test__multi3(1, 81985529216486895, 81985529216486895); | |
| 34 | try test__multi3(81985529216486895, 1, 81985529216486895); | |
| 35 | ||
| 36 | try test__multi3(1, -1, -1); | |
| 37 | try test__multi3(1, -10, -10); | |
| 38 | try test__multi3(-10, 1, -10); | |
| 39 | try test__multi3(1, -81985529216486895, -81985529216486895); | |
| 40 | try test__multi3(-81985529216486895, 1, -81985529216486895); | |
| 41 | ||
| 42 | try test__multi3(3037000499, 3037000499, 9223372030926249001); | |
| 43 | try test__multi3(-3037000499, 3037000499, -9223372030926249001); | |
| 44 | try test__multi3(3037000499, -3037000499, -9223372030926249001); | |
| 45 | try test__multi3(-3037000499, -3037000499, 9223372030926249001); | |
| 46 | ||
| 47 | try test__multi3(4398046511103, 2097152, 9223372036852678656); | |
| 48 | try test__multi3(-4398046511103, 2097152, -9223372036852678656); | |
| 49 | try test__multi3(4398046511103, -2097152, -9223372036852678656); | |
| 50 | try test__multi3(-4398046511103, -2097152, 9223372036852678656); | |
| 51 | ||
| 52 | try test__multi3(2097152, 4398046511103, 9223372036852678656); | |
| 53 | try test__multi3(-2097152, 4398046511103, -9223372036852678656); | |
| 54 | try test__multi3(2097152, -4398046511103, -9223372036852678656); | |
| 55 | try test__multi3(-2097152, -4398046511103, 9223372036852678656); | |
| 56 | ||
| 57 | try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000); | |
| 58 | 58 | } |
lib/std/special/compiler_rt/popcountdi2_test.zig+8-8| ... | ... | @@ -15,18 +15,18 @@ fn naive_popcount(a_param: i64) i32 { |
| 15 | 15 | return r; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | fn test__popcountdi2(a: i64) void { | |
| 18 | fn test__popcountdi2(a: i64) !void { | |
| 19 | 19 | const x = __popcountdi2(a); |
| 20 | 20 | const expected = naive_popcount(a); |
| 21 | testing.expect(expected == x); | |
| 21 | try testing.expect(expected == x); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | test "popcountdi2" { |
| 25 | test__popcountdi2(0); | |
| 26 | test__popcountdi2(1); | |
| 27 | test__popcountdi2(2); | |
| 28 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD))); | |
| 29 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE))); | |
| 30 | test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF))); | |
| 25 | try test__popcountdi2(0); | |
| 26 | try test__popcountdi2(1); | |
| 27 | try test__popcountdi2(2); | |
| 28 | try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFD))); | |
| 29 | try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFE))); | |
| 30 | try test__popcountdi2(@bitCast(i64, @as(u64, 0xFFFFFFFFFFFFFFFF))); | |
| 31 | 31 | // TODO some fuzz testing |
| 32 | 32 | } |
lib/std/special/compiler_rt/truncXfYf2_test.zig+36-36| ... | ... | @@ -5,67 +5,67 @@ |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const __truncsfhf2 = @import("truncXfYf2.zig").__truncsfhf2; |
| 7 | 7 | |
| 8 | fn test__truncsfhf2(a: u32, expected: u16) void { | |
| 8 | fn test__truncsfhf2(a: u32, expected: u16) !void { | |
| 9 | 9 | const actual = __truncsfhf2(@bitCast(f32, a)); |
| 10 | 10 | |
| 11 | 11 | if (actual == expected) { |
| 12 | 12 | return; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | @panic("__truncsfhf2 test failure"); | |
| 15 | return error.TestFailure; | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "truncsfhf2" { |
| 19 | test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN | |
| 20 | test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN | |
| 19 | try test__truncsfhf2(0x7fc00000, 0x7e00); // qNaN | |
| 20 | try test__truncsfhf2(0x7fe00000, 0x7f00); // sNaN | |
| 21 | 21 | |
| 22 | test__truncsfhf2(0, 0); // 0 | |
| 23 | test__truncsfhf2(0x80000000, 0x8000); // -0 | |
| 22 | try test__truncsfhf2(0, 0); // 0 | |
| 23 | try test__truncsfhf2(0x80000000, 0x8000); // -0 | |
| 24 | 24 | |
| 25 | test__truncsfhf2(0x7f800000, 0x7c00); // inf | |
| 26 | test__truncsfhf2(0xff800000, 0xfc00); // -inf | |
| 25 | try test__truncsfhf2(0x7f800000, 0x7c00); // inf | |
| 26 | try test__truncsfhf2(0xff800000, 0xfc00); // -inf | |
| 27 | 27 | |
| 28 | test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf | |
| 29 | test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf | |
| 28 | try test__truncsfhf2(0x477ff000, 0x7c00); // 65520 -> inf | |
| 29 | try test__truncsfhf2(0xc77ff000, 0xfc00); // -65520 -> -inf | |
| 30 | 30 | |
| 31 | test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf | |
| 32 | test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf | |
| 31 | try test__truncsfhf2(0x71cc3892, 0x7c00); // 0x1.987124876876324p+100 -> inf | |
| 32 | try test__truncsfhf2(0xf1cc3892, 0xfc00); // -0x1.987124876876324p+100 -> -inf | |
| 33 | 33 | |
| 34 | test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14 | |
| 35 | test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14 | |
| 34 | try test__truncsfhf2(0x38800000, 0x0400); // normal (min), 2**-14 | |
| 35 | try test__truncsfhf2(0xb8800000, 0x8400); // normal (min), -2**-14 | |
| 36 | 36 | |
| 37 | test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504 | |
| 38 | test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504 | |
| 37 | try test__truncsfhf2(0x477fe000, 0x7bff); // normal (max), 65504 | |
| 38 | try test__truncsfhf2(0xc77fe000, 0xfbff); // normal (max), -65504 | |
| 39 | 39 | |
| 40 | test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504 | |
| 41 | test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504 | |
| 40 | try test__truncsfhf2(0x477fe100, 0x7bff); // normal, 65505 -> 65504 | |
| 41 | try test__truncsfhf2(0xc77fe100, 0xfbff); // normal, -65505 -> -65504 | |
| 42 | 42 | |
| 43 | test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504 | |
| 44 | test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504 | |
| 43 | try test__truncsfhf2(0x477fef00, 0x7bff); // normal, 65519 -> 65504 | |
| 44 | try test__truncsfhf2(0xc77fef00, 0xfbff); // normal, -65519 -> -65504 | |
| 45 | 45 | |
| 46 | test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10 | |
| 47 | test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10 | |
| 46 | try test__truncsfhf2(0x3f802000, 0x3c01); // normal, 1 + 2**-10 | |
| 47 | try test__truncsfhf2(0xbf802000, 0xbc01); // normal, -1 - 2**-10 | |
| 48 | 48 | |
| 49 | test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3 | |
| 50 | test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3 | |
| 49 | try test__truncsfhf2(0x3eaaa000, 0x3555); // normal, approx. 1/3 | |
| 50 | try test__truncsfhf2(0xbeaaa000, 0xb555); // normal, approx. -1/3 | |
| 51 | 51 | |
| 52 | test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535 | |
| 53 | test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535 | |
| 52 | try test__truncsfhf2(0x40490fdb, 0x4248); // normal, 3.1415926535 | |
| 53 | try test__truncsfhf2(0xc0490fdb, 0xc248); // normal, -3.1415926535 | |
| 54 | 54 | |
| 55 | test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12 | |
| 55 | try test__truncsfhf2(0x45cc3892, 0x6e62); // normal, 0x1.987124876876324p+12 | |
| 56 | 56 | |
| 57 | test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1 | |
| 58 | test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14 | |
| 57 | try test__truncsfhf2(0x3f800000, 0x3c00); // normal, 1 | |
| 58 | try test__truncsfhf2(0x38800000, 0x0400); // normal, 0x1.0p-14 | |
| 59 | 59 | |
| 60 | test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24 | |
| 61 | test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24 | |
| 60 | try test__truncsfhf2(0x33800000, 0x0001); // denormal (min), 2**-24 | |
| 61 | try test__truncsfhf2(0xb3800000, 0x8001); // denormal (min), -2**-24 | |
| 62 | 62 | |
| 63 | test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24 | |
| 64 | test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24 | |
| 63 | try test__truncsfhf2(0x387fc000, 0x03ff); // denormal (max), 2**-14 - 2**-24 | |
| 64 | try test__truncsfhf2(0xb87fc000, 0x83ff); // denormal (max), -2**-14 + 2**-24 | |
| 65 | 65 | |
| 66 | test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20 | |
| 67 | test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24 | |
| 68 | test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero | |
| 66 | try test__truncsfhf2(0x35800000, 0x0010); // denormal, 0x1.0p-20 | |
| 67 | try test__truncsfhf2(0x33280000, 0x0001); // denormal, 0x1.5p-25 -> 0x1.0p-24 | |
| 68 | try test__truncsfhf2(0x33000000, 0x0000); // 0x1.0p-25 -> zero | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | const __truncdfhf2 = @import("truncXfYf2.zig").__truncdfhf2; |
lib/std/special/compiler_rt/udivmoddi4_test.zig+4-4| ... | ... | @@ -8,16 +8,16 @@ |
| 8 | 8 | const __udivmoddi4 = @import("int.zig").__udivmoddi4; |
| 9 | 9 | const testing = @import("std").testing; |
| 10 | 10 | |
| 11 | fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) void { | |
| 11 | fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void { | |
| 12 | 12 | var r: u64 = undefined; |
| 13 | 13 | const q = __udivmoddi4(a, b, &r); |
| 14 | testing.expect(q == expected_q); | |
| 15 | testing.expect(r == expected_r); | |
| 14 | try testing.expect(q == expected_q); | |
| 15 | try testing.expect(r == expected_r); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "udivmoddi4" { |
| 19 | 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 | } |
| 23 | 23 |
lib/std/special/compiler_rt/udivmodti4_test.zig+4-4| ... | ... | @@ -8,16 +8,16 @@ |
| 8 | 8 | const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; |
| 9 | 9 | const testing = @import("std").testing; |
| 10 | 10 | |
| 11 | fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) void { | |
| 11 | fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void { | |
| 12 | 12 | var r: u128 = undefined; |
| 13 | 13 | const q = __udivmodti4(a, b, &r); |
| 14 | testing.expect(q == expected_q); | |
| 15 | testing.expect(r == expected_r); | |
| 14 | try testing.expect(q == expected_q); | |
| 15 | try testing.expect(r == expected_r); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "udivmodti4" { |
| 19 | 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 | } |
| 23 | 23 |
lib/std/special/init-lib/src/main.zig+1-1| ... | ... | @@ -6,5 +6,5 @@ export fn add(a: i32, b: i32) i32 { |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "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 | 23 | const test_fn_list = builtin.test_functions; |
| 24 | 24 | var ok_count: usize = 0; |
| 25 | 25 | var skip_count: usize = 0; |
| 26 | var fail_count: usize = 0; | |
| 26 | 27 | var progress = std.Progress{}; |
| 27 | 28 | const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) { |
| 28 | 29 | // TODO still run tests in this case |
| ... | ... | @@ -62,7 +63,7 @@ pub fn main() anyerror!void { |
| 62 | 63 | .blocking => { |
| 63 | 64 | skip_count += 1; |
| 64 | 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 | 67 | if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{}); |
| 67 | 68 | continue; |
| 68 | 69 | }, |
| ... | ... | @@ -75,12 +76,14 @@ pub fn main() anyerror!void { |
| 75 | 76 | error.SkipZigTest => { |
| 76 | 77 | skip_count += 1; |
| 77 | 78 | test_node.end(); |
| 78 | progress.log("{s}...SKIP\n", .{test_fn.name}); | |
| 79 | progress.log("{s}... SKIP\n", .{test_fn.name}); | |
| 79 | 80 | if (progress.terminal == null) std.debug.print("SKIP\n", .{}); |
| 80 | 81 | }, |
| 81 | 82 | else => { |
| 82 | progress.log("", .{}); | |
| 83 | return err; | |
| 83 | fail_count += 1; | |
| 84 | test_node.end(); | |
| 85 | progress.log("{s}... FAIL ({s})\n", .{ test_fn.name, @errorName(err) }); | |
| 86 | if (progress.terminal == null) std.debug.print("FAIL ({s})\n", .{@errorName(err)}); | |
| 84 | 87 | }, |
| 85 | 88 | } |
| 86 | 89 | } |
| ... | ... | @@ -88,7 +91,7 @@ pub fn main() anyerror!void { |
| 88 | 91 | if (ok_count == test_fn_list.len) { |
| 89 | 92 | std.debug.print("All {d} tests passed.\n", .{ok_count}); |
| 90 | 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 | 96 | if (log_err_count != 0) { |
| 94 | 97 | std.debug.print("{d} errors were logged.\n", .{log_err_count}); |
| ... | ... | @@ -96,7 +99,7 @@ pub fn main() anyerror!void { |
| 96 | 99 | if (leaks != 0) { |
| 97 | 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 | 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 | 27 | |
| 28 | 28 | /// This function is intended to be used only in tests. It prints diagnostics to stderr |
| 29 | 29 | /// and then aborts when actual_error_union is not expected_error. |
| 30 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void { | |
| 30 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { | |
| 31 | 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 | 34 | } else |actual_error| { |
| 34 | 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 | 37 | @errorName(expected_error), |
| 37 | 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 | 46 | /// equal, prints diagnostics to stderr to show exactly how they are not equal, |
| 45 | 47 | /// then aborts. |
| 46 | 48 | /// `actual` is casted to the type of `expected`. |
| 47 | pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { | |
| 49 | pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void { | |
| 48 | 50 | switch (@typeInfo(@TypeOf(actual))) { |
| 49 | 51 | .NoReturn, |
| 50 | 52 | .BoundFn, |
| ... | ... | @@ -60,7 +62,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 60 | 62 | |
| 61 | 63 | .Type => { |
| 62 | 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 | }, |
| 66 | 69 | |
| ... | ... | @@ -75,7 +78,8 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 75 | 78 | .ErrorSet, |
| 76 | 79 | => { |
| 77 | 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 | }, |
| 81 | 85 | |
| ... | ... | @@ -83,34 +87,38 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 83 | 87 | switch (pointer.size) { |
| 84 | 88 | .One, .Many, .C => { |
| 85 | 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 | 94 | .Slice => { |
| 90 | 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 | 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 | }, |
| 99 | 106 | |
| 100 | .Array => |array| expectEqualSlices(array.child, &expected, &actual), | |
| 107 | .Array => |array| try expectEqualSlices(array.child, &expected, &actual), | |
| 101 | 108 | |
| 102 | 109 | .Vector => |vectorType| { |
| 103 | 110 | var i: usize = 0; |
| 104 | 111 | while (i < vectorType.len) : (i += 1) { |
| 105 | 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 | }, |
| 110 | 118 | |
| 111 | 119 | .Struct => |structType| { |
| 112 | 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 | }, |
| 116 | 124 | |
| ... | ... | @@ -124,12 +132,12 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 124 | 132 | const expectedTag = @as(Tag, expected); |
| 125 | 133 | const actualTag = @as(Tag, actual); |
| 126 | 134 | |
| 127 | expectEqual(expectedTag, actualTag); | |
| 135 | try expectEqual(expectedTag, actualTag); | |
| 128 | 136 | |
| 129 | 137 | // we only reach this loop if the tags are equal |
| 130 | 138 | inline for (std.meta.fields(@TypeOf(actual))) |fld| { |
| 131 | 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 | 141 | return; |
| 134 | 142 | } |
| 135 | 143 | } |
| ... | ... | @@ -143,13 +151,15 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void { |
| 143 | 151 | .Optional => { |
| 144 | 152 | if (expected) |expected_payload| { |
| 145 | 153 | if (actual) |actual_payload| { |
| 146 | expectEqual(expected_payload, actual_payload); | |
| 154 | try expectEqual(expected_payload, actual_payload); | |
| 147 | 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 | 159 | } else { |
| 151 | 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 | 167 | .ErrorUnion => { |
| 158 | 168 | if (expected) |expected_payload| { |
| 159 | 169 | if (actual) |actual_payload| { |
| 160 | expectEqual(expected_payload, actual_payload); | |
| 170 | try expectEqual(expected_payload, actual_payload); | |
| 161 | 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 | 175 | } else |expected_err| { |
| 165 | 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 | 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 | 193 | const a10 = T{ .a = 10 }; |
| 182 | 194 | const a20 = T{ .a = 20 }; |
| 183 | 195 | |
| 184 | expectEqual(a10, a10); | |
| 196 | try expectEqual(a10, a10); | |
| 185 | 197 | } |
| 186 | 198 | |
| 187 | 199 | /// 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 | 209 | print("\n======== instead found this: =========\n", .{}); |
| 198 | 210 | print("{s}", .{result}); |
| 199 | 211 | print("\n======================================\n", .{}); |
| 200 | return error.TestFailed; | |
| 212 | return error.TestExpectedFmt; | |
| 201 | 213 | } |
| 202 | 214 | |
| 203 | 215 | pub const expectWithinMargin = @compileError("expectWithinMargin is deprecated, use expectApproxEqAbs or expectApproxEqRel"); |
| ... | ... | @@ -208,12 +220,14 @@ pub const expectWithinEpsilon = @compileError("expectWithinEpsilon is deprecated |
| 208 | 220 | /// to show exactly how they are not equal, then aborts. |
| 209 | 221 | /// See `math.approxEqAbs` for more informations on the tolerance parameter. |
| 210 | 222 | /// The types must be floating point |
| 211 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void { | |
| 223 | pub fn expectApproxEqAbs(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | |
| 212 | 224 | const T = @TypeOf(expected); |
| 213 | 225 | |
| 214 | 226 | switch (@typeInfo(T)) { |
| 215 | .Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) | |
| 216 | std.debug.panic("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected }), | |
| 227 | .Float => if (!math.approxEqAbs(T, expected, actual, tolerance)) { | |
| 228 | std.debug.print("actual {}, not within absolute tolerance {} of expected {}", .{ actual, tolerance, expected }); | |
| 229 | return error.TestExpectedApproxEqAbs; | |
| 230 | }, | |
| 217 | 231 | |
| 218 | 232 | .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"), |
| 219 | 233 | |
| ... | ... | @@ -228,8 +242,8 @@ test "expectApproxEqAbs" { |
| 228 | 242 | const neg_x: T = -12.0; |
| 229 | 243 | const neg_y: T = -12.06; |
| 230 | 244 | |
| 231 | expectApproxEqAbs(pos_x, pos_y, 0.1); | |
| 232 | expectApproxEqAbs(neg_x, neg_y, 0.1); | |
| 245 | try expectApproxEqAbs(pos_x, pos_y, 0.1); | |
| 246 | try expectApproxEqAbs(neg_x, neg_y, 0.1); | |
| 233 | 247 | } |
| 234 | 248 | } |
| 235 | 249 | |
| ... | ... | @@ -238,12 +252,14 @@ test "expectApproxEqAbs" { |
| 238 | 252 | /// to show exactly how they are not equal, then aborts. |
| 239 | 253 | /// See `math.approxEqRel` for more informations on the tolerance parameter. |
| 240 | 254 | /// The types must be floating point |
| 241 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) void { | |
| 255 | pub fn expectApproxEqRel(expected: anytype, actual: @TypeOf(expected), tolerance: @TypeOf(expected)) !void { | |
| 242 | 256 | const T = @TypeOf(expected); |
| 243 | 257 | |
| 244 | 258 | switch (@typeInfo(T)) { |
| 245 | .Float => if (!math.approxEqRel(T, expected, actual, tolerance)) | |
| 246 | std.debug.panic("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected }), | |
| 259 | .Float => if (!math.approxEqRel(T, expected, actual, tolerance)) { | |
| 260 | std.debug.print("actual {}, not within relative tolerance {} of expected {}", .{ actual, tolerance, expected }); | |
| 261 | return error.TestExpectedApproxEqRel; | |
| 262 | }, | |
| 247 | 263 | |
| 248 | 264 | .ComptimeFloat => @compileError("Cannot approximately compare two comptime_float values"), |
| 249 | 265 | |
| ... | ... | @@ -261,8 +277,8 @@ test "expectApproxEqRel" { |
| 261 | 277 | const neg_x: T = -12.0; |
| 262 | 278 | const neg_y: T = neg_x - 2 * eps_value; |
| 263 | 279 | |
| 264 | expectApproxEqRel(pos_x, pos_y, sqrt_eps_value); | |
| 265 | expectApproxEqRel(neg_x, neg_y, sqrt_eps_value); | |
| 280 | try expectApproxEqRel(pos_x, pos_y, sqrt_eps_value); | |
| 281 | try expectApproxEqRel(neg_x, neg_y, sqrt_eps_value); | |
| 266 | 282 | } |
| 267 | 283 | } |
| 268 | 284 | |
| ... | ... | @@ -270,26 +286,28 @@ test "expectApproxEqRel" { |
| 270 | 286 | /// equal, prints diagnostics to stderr to show exactly how they are not equal, |
| 271 | 287 | /// then aborts. |
| 272 | 288 | /// If your inputs are UTF-8 encoded strings, consider calling `expectEqualStrings` instead. |
| 273 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) void { | |
| 289 | pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const T) !void { | |
| 274 | 290 | // TODO better printing of the difference |
| 275 | 291 | // If the arrays are small enough we could print the whole thing |
| 276 | 292 | // If the child type is u8 and no weird bytes, we could print it as strings |
| 277 | 293 | // Even for the length difference, it would be useful to see the values of the slices probably. |
| 278 | 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 | 298 | var i: usize = 0; |
| 282 | 299 | while (i < expected.len) : (i += 1) { |
| 283 | 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 | } |
| 288 | 306 | |
| 289 | 307 | /// This function is intended to be used only in tests. When `ok` is false, the test fails. |
| 290 | 308 | /// A message is printed to stderr and then abort is called. |
| 291 | pub fn expect(ok: bool) void { | |
| 292 | if (!ok) @panic("test failure"); | |
| 309 | pub fn expect(ok: bool) !void { | |
| 310 | if (!ok) return error.TestUnexpectedResult; | |
| 293 | 311 | } |
| 294 | 312 | |
| 295 | 313 | pub const TmpDir = struct { |
| ... | ... | @@ -356,17 +374,17 @@ test "expectEqual nested array" { |
| 356 | 374 | [_]f32{ 0.0, 1.0 }, |
| 357 | 375 | }; |
| 358 | 376 | |
| 359 | expectEqual(a, b); | |
| 377 | try expectEqual(a, b); | |
| 360 | 378 | } |
| 361 | 379 | |
| 362 | 380 | test "expectEqual vector" { |
| 363 | 381 | var a = @splat(4, @as(u32, 4)); |
| 364 | 382 | var b = @splat(4, @as(u32, 4)); |
| 365 | 383 | |
| 366 | expectEqual(a, b); | |
| 384 | try expectEqual(a, b); | |
| 367 | 385 | } |
| 368 | 386 | |
| 369 | pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void { | |
| 387 | pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void { | |
| 370 | 388 | if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| { |
| 371 | 389 | print("\n====== expected this output: =========\n", .{}); |
| 372 | 390 | printWithVisibleNewlines(expected); |
| ... | ... | @@ -386,11 +404,11 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void { |
| 386 | 404 | print("found:\n", .{}); |
| 387 | 405 | printIndicatorLine(actual, diff_index); |
| 388 | 406 | |
| 389 | @panic("test failure"); | |
| 407 | return error.TestExpectedEqual; | |
| 390 | 408 | } |
| 391 | 409 | } |
| 392 | 410 | |
| 393 | pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) void { | |
| 411 | pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void { | |
| 394 | 412 | if (std.mem.endsWith(u8, actual, expected_ends_with)) |
| 395 | 413 | return; |
| 396 | 414 | |
| ... | ... | @@ -407,7 +425,7 @@ pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) |
| 407 | 425 | printWithVisibleNewlines(actual); |
| 408 | 426 | print("\n======================================\n", .{}); |
| 409 | 427 | |
| 410 | @panic("test failure"); | |
| 428 | return error.TestExpectedEndsWith; | |
| 411 | 429 | } |
| 412 | 430 | |
| 413 | 431 | fn printIndicatorLine(source: []const u8, indicator_index: usize) void { |
| ... | ... | @@ -446,7 +464,7 @@ fn printLine(line: []const u8) void { |
| 446 | 464 | } |
| 447 | 465 | |
| 448 | 466 | test { |
| 449 | expectEqualStrings("foo", "foo"); | |
| 467 | try expectEqualStrings("foo", "foo"); | |
| 450 | 468 | } |
| 451 | 469 | |
| 452 | 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 | 271 | sleep(ns_per_ms); |
| 272 | 272 | const time_1 = milliTimestamp(); |
| 273 | 273 | const interval = time_1 - time_0; |
| 274 | testing.expect(interval > 0); | |
| 274 | try testing.expect(interval > 0); | |
| 275 | 275 | // Tests should not depend on timings: skip test if outside margin. |
| 276 | 276 | if (!(interval < margin)) return error.SkipZigTest; |
| 277 | 277 | } |
| ... | ... | @@ -282,13 +282,13 @@ test "Timer" { |
| 282 | 282 | var timer = try Timer.start(); |
| 283 | 283 | sleep(10 * ns_per_ms); |
| 284 | 284 | const time_0 = timer.read(); |
| 285 | testing.expect(time_0 > 0); | |
| 285 | try testing.expect(time_0 > 0); | |
| 286 | 286 | // Tests should not depend on timings: skip test if outside margin. |
| 287 | 287 | if (!(time_0 < margin)) return error.SkipZigTest; |
| 288 | 288 | |
| 289 | 289 | const time_1 = timer.lap(); |
| 290 | testing.expect(time_1 >= time_0); | |
| 290 | try testing.expect(time_1 >= time_0); | |
| 291 | 291 | |
| 292 | 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 | 336 | }; |
| 337 | 337 | |
| 338 | 338 | test "utf8 encode" { |
| 339 | comptime testUtf8Encode() catch unreachable; | |
| 339 | comptime try testUtf8Encode(); | |
| 340 | 340 | try testUtf8Encode(); |
| 341 | 341 | } |
| 342 | 342 | fn testUtf8Encode() !void { |
| 343 | 343 | // A few taken from wikipedia a few taken elsewhere |
| 344 | 344 | var array: [4]u8 = undefined; |
| 345 | testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3); | |
| 346 | testing.expect(array[0] == 0b11100010); | |
| 347 | testing.expect(array[1] == 0b10000010); | |
| 348 | testing.expect(array[2] == 0b10101100); | |
| 345 | try testing.expect((try utf8Encode(try utf8Decode("€"), array[0..])) == 3); | |
| 346 | try testing.expect(array[0] == 0b11100010); | |
| 347 | try testing.expect(array[1] == 0b10000010); | |
| 348 | try testing.expect(array[2] == 0b10101100); | |
| 349 | 349 | |
| 350 | testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1); | |
| 351 | testing.expect(array[0] == 0b00100100); | |
| 350 | try testing.expect((try utf8Encode(try utf8Decode("$"), array[0..])) == 1); | |
| 351 | try testing.expect(array[0] == 0b00100100); | |
| 352 | 352 | |
| 353 | testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2); | |
| 354 | testing.expect(array[0] == 0b11000010); | |
| 355 | testing.expect(array[1] == 0b10100010); | |
| 353 | try testing.expect((try utf8Encode(try utf8Decode("¢"), array[0..])) == 2); | |
| 354 | try testing.expect(array[0] == 0b11000010); | |
| 355 | try testing.expect(array[1] == 0b10100010); | |
| 356 | 356 | |
| 357 | testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4); | |
| 358 | testing.expect(array[0] == 0b11110000); | |
| 359 | testing.expect(array[1] == 0b10010000); | |
| 360 | testing.expect(array[2] == 0b10001101); | |
| 361 | testing.expect(array[3] == 0b10001000); | |
| 357 | try testing.expect((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4); | |
| 358 | try testing.expect(array[0] == 0b11110000); | |
| 359 | try testing.expect(array[1] == 0b10010000); | |
| 360 | try testing.expect(array[2] == 0b10001101); | |
| 361 | try testing.expect(array[3] == 0b10001000); | |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | test "utf8 encode error" { |
| 365 | comptime testUtf8EncodeError(); | |
| 366 | testUtf8EncodeError(); | |
| 365 | comptime try testUtf8EncodeError(); | |
| 366 | try testUtf8EncodeError(); | |
| 367 | 367 | } |
| 368 | fn testUtf8EncodeError() void { | |
| 368 | fn testUtf8EncodeError() !void { | |
| 369 | 369 | var array: [4]u8 = undefined; |
| 370 | testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf); | |
| 371 | testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf); | |
| 372 | testErrorEncode(0x110000, array[0..], error.CodepointTooLarge); | |
| 373 | testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge); | |
| 370 | try testErrorEncode(0xd800, array[0..], error.Utf8CannotEncodeSurrogateHalf); | |
| 371 | try testErrorEncode(0xdfff, array[0..], error.Utf8CannotEncodeSurrogateHalf); | |
| 372 | try testErrorEncode(0x110000, array[0..], error.CodepointTooLarge); | |
| 373 | try testErrorEncode(0x1fffff, array[0..], error.CodepointTooLarge); | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) void { | |
| 377 | testing.expectError(expectedErr, utf8Encode(codePoint, array)); | |
| 376 | fn testErrorEncode(codePoint: u21, array: []u8, expectedErr: anyerror) !void { | |
| 377 | try testing.expectError(expectedErr, utf8Encode(codePoint, array)); | |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | test "utf8 iterator on ascii" { |
| 381 | comptime testUtf8IteratorOnAscii(); | |
| 382 | testUtf8IteratorOnAscii(); | |
| 381 | comptime try testUtf8IteratorOnAscii(); | |
| 382 | try testUtf8IteratorOnAscii(); | |
| 383 | 383 | } |
| 384 | fn testUtf8IteratorOnAscii() void { | |
| 384 | fn testUtf8IteratorOnAscii() !void { | |
| 385 | 385 | const s = Utf8View.initComptime("abc"); |
| 386 | 386 | |
| 387 | 387 | var it1 = s.iterator(); |
| 388 | testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?)); | |
| 389 | testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?)); | |
| 390 | testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?)); | |
| 391 | testing.expect(it1.nextCodepointSlice() == null); | |
| 388 | try testing.expect(std.mem.eql(u8, "a", it1.nextCodepointSlice().?)); | |
| 389 | try testing.expect(std.mem.eql(u8, "b", it1.nextCodepointSlice().?)); | |
| 390 | try testing.expect(std.mem.eql(u8, "c", it1.nextCodepointSlice().?)); | |
| 391 | try testing.expect(it1.nextCodepointSlice() == null); | |
| 392 | 392 | |
| 393 | 393 | var it2 = s.iterator(); |
| 394 | testing.expect(it2.nextCodepoint().? == 'a'); | |
| 395 | testing.expect(it2.nextCodepoint().? == 'b'); | |
| 396 | testing.expect(it2.nextCodepoint().? == 'c'); | |
| 397 | testing.expect(it2.nextCodepoint() == null); | |
| 394 | try testing.expect(it2.nextCodepoint().? == 'a'); | |
| 395 | try testing.expect(it2.nextCodepoint().? == 'b'); | |
| 396 | try testing.expect(it2.nextCodepoint().? == 'c'); | |
| 397 | try testing.expect(it2.nextCodepoint() == null); | |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | test "utf8 view bad" { |
| 401 | comptime testUtf8ViewBad(); | |
| 402 | testUtf8ViewBad(); | |
| 401 | comptime try testUtf8ViewBad(); | |
| 402 | try testUtf8ViewBad(); | |
| 403 | 403 | } |
| 404 | fn testUtf8ViewBad() void { | |
| 404 | fn testUtf8ViewBad() !void { | |
| 405 | 405 | // Compile-time error. |
| 406 | 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 | } |
| 409 | 409 | |
| 410 | 410 | test "utf8 view ok" { |
| 411 | comptime testUtf8ViewOk(); | |
| 412 | testUtf8ViewOk(); | |
| 411 | comptime try testUtf8ViewOk(); | |
| 412 | try testUtf8ViewOk(); | |
| 413 | 413 | } |
| 414 | fn testUtf8ViewOk() void { | |
| 414 | fn testUtf8ViewOk() !void { | |
| 415 | 415 | const s = Utf8View.initComptime("東京市"); |
| 416 | 416 | |
| 417 | 417 | var it1 = s.iterator(); |
| 418 | testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?)); | |
| 419 | testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?)); | |
| 420 | testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?)); | |
| 421 | testing.expect(it1.nextCodepointSlice() == null); | |
| 418 | try testing.expect(std.mem.eql(u8, "東", it1.nextCodepointSlice().?)); | |
| 419 | try testing.expect(std.mem.eql(u8, "京", it1.nextCodepointSlice().?)); | |
| 420 | try testing.expect(std.mem.eql(u8, "市", it1.nextCodepointSlice().?)); | |
| 421 | try testing.expect(it1.nextCodepointSlice() == null); | |
| 422 | 422 | |
| 423 | 423 | var it2 = s.iterator(); |
| 424 | testing.expect(it2.nextCodepoint().? == 0x6771); | |
| 425 | testing.expect(it2.nextCodepoint().? == 0x4eac); | |
| 426 | testing.expect(it2.nextCodepoint().? == 0x5e02); | |
| 427 | testing.expect(it2.nextCodepoint() == null); | |
| 424 | try testing.expect(it2.nextCodepoint().? == 0x6771); | |
| 425 | try testing.expect(it2.nextCodepoint().? == 0x4eac); | |
| 426 | try testing.expect(it2.nextCodepoint().? == 0x5e02); | |
| 427 | try testing.expect(it2.nextCodepoint() == null); | |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | test "bad utf8 slice" { |
| 431 | comptime testBadUtf8Slice(); | |
| 432 | testBadUtf8Slice(); | |
| 431 | comptime try testBadUtf8Slice(); | |
| 432 | try testBadUtf8Slice(); | |
| 433 | 433 | } |
| 434 | fn testBadUtf8Slice() void { | |
| 435 | testing.expect(utf8ValidateSlice("abc")); | |
| 436 | testing.expect(!utf8ValidateSlice("abc\xc0")); | |
| 437 | testing.expect(!utf8ValidateSlice("abc\xc0abc")); | |
| 438 | testing.expect(utf8ValidateSlice("abc\xdf\xbf")); | |
| 434 | fn testBadUtf8Slice() !void { | |
| 435 | try testing.expect(utf8ValidateSlice("abc")); | |
| 436 | try testing.expect(!utf8ValidateSlice("abc\xc0")); | |
| 437 | try testing.expect(!utf8ValidateSlice("abc\xc0abc")); | |
| 438 | try testing.expect(utf8ValidateSlice("abc\xdf\xbf")); | |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | test "valid utf8" { |
| 442 | comptime testValidUtf8(); | |
| 443 | testValidUtf8(); | |
| 444 | } | |
| 445 | fn testValidUtf8() void { | |
| 446 | testValid("\x00", 0x0); | |
| 447 | testValid("\x20", 0x20); | |
| 448 | testValid("\x7f", 0x7f); | |
| 449 | testValid("\xc2\x80", 0x80); | |
| 450 | testValid("\xdf\xbf", 0x7ff); | |
| 451 | testValid("\xe0\xa0\x80", 0x800); | |
| 452 | testValid("\xe1\x80\x80", 0x1000); | |
| 453 | testValid("\xef\xbf\xbf", 0xffff); | |
| 454 | testValid("\xf0\x90\x80\x80", 0x10000); | |
| 455 | testValid("\xf1\x80\x80\x80", 0x40000); | |
| 456 | testValid("\xf3\xbf\xbf\xbf", 0xfffff); | |
| 457 | testValid("\xf4\x8f\xbf\xbf", 0x10ffff); | |
| 442 | comptime try testValidUtf8(); | |
| 443 | try testValidUtf8(); | |
| 444 | } | |
| 445 | fn testValidUtf8() !void { | |
| 446 | try testValid("\x00", 0x0); | |
| 447 | try testValid("\x20", 0x20); | |
| 448 | try testValid("\x7f", 0x7f); | |
| 449 | try testValid("\xc2\x80", 0x80); | |
| 450 | try testValid("\xdf\xbf", 0x7ff); | |
| 451 | try testValid("\xe0\xa0\x80", 0x800); | |
| 452 | try testValid("\xe1\x80\x80", 0x1000); | |
| 453 | try testValid("\xef\xbf\xbf", 0xffff); | |
| 454 | try testValid("\xf0\x90\x80\x80", 0x10000); | |
| 455 | try testValid("\xf1\x80\x80\x80", 0x40000); | |
| 456 | try testValid("\xf3\xbf\xbf\xbf", 0xfffff); | |
| 457 | try testValid("\xf4\x8f\xbf\xbf", 0x10ffff); | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | test "invalid utf8 continuation bytes" { |
| 461 | comptime testInvalidUtf8ContinuationBytes(); | |
| 462 | testInvalidUtf8ContinuationBytes(); | |
| 461 | comptime try testInvalidUtf8ContinuationBytes(); | |
| 462 | try testInvalidUtf8ContinuationBytes(); | |
| 463 | 463 | } |
| 464 | fn testInvalidUtf8ContinuationBytes() void { | |
| 464 | fn testInvalidUtf8ContinuationBytes() !void { | |
| 465 | 465 | // unexpected continuation |
| 466 | testError("\x80", error.Utf8InvalidStartByte); | |
| 467 | testError("\xbf", error.Utf8InvalidStartByte); | |
| 466 | try testError("\x80", error.Utf8InvalidStartByte); | |
| 467 | try testError("\xbf", error.Utf8InvalidStartByte); | |
| 468 | 468 | // too many leading 1's |
| 469 | testError("\xf8", error.Utf8InvalidStartByte); | |
| 470 | testError("\xff", error.Utf8InvalidStartByte); | |
| 469 | try testError("\xf8", error.Utf8InvalidStartByte); | |
| 470 | try testError("\xff", error.Utf8InvalidStartByte); | |
| 471 | 471 | // expected continuation for 2 byte sequences |
| 472 | testError("\xc2", error.UnexpectedEof); | |
| 473 | testError("\xc2\x00", error.Utf8ExpectedContinuation); | |
| 474 | testError("\xc2\xc0", error.Utf8ExpectedContinuation); | |
| 472 | try testError("\xc2", error.UnexpectedEof); | |
| 473 | try testError("\xc2\x00", error.Utf8ExpectedContinuation); | |
| 474 | try testError("\xc2\xc0", error.Utf8ExpectedContinuation); | |
| 475 | 475 | // expected continuation for 3 byte sequences |
| 476 | testError("\xe0", error.UnexpectedEof); | |
| 477 | testError("\xe0\x00", error.UnexpectedEof); | |
| 478 | testError("\xe0\xc0", error.UnexpectedEof); | |
| 479 | testError("\xe0\xa0", error.UnexpectedEof); | |
| 480 | testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation); | |
| 481 | testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation); | |
| 476 | try testError("\xe0", error.UnexpectedEof); | |
| 477 | try testError("\xe0\x00", error.UnexpectedEof); | |
| 478 | try testError("\xe0\xc0", error.UnexpectedEof); | |
| 479 | try testError("\xe0\xa0", error.UnexpectedEof); | |
| 480 | try testError("\xe0\xa0\x00", error.Utf8ExpectedContinuation); | |
| 481 | try testError("\xe0\xa0\xc0", error.Utf8ExpectedContinuation); | |
| 482 | 482 | // expected continuation for 4 byte sequences |
| 483 | testError("\xf0", error.UnexpectedEof); | |
| 484 | testError("\xf0\x00", error.UnexpectedEof); | |
| 485 | testError("\xf0\xc0", error.UnexpectedEof); | |
| 486 | testError("\xf0\x90\x00", error.UnexpectedEof); | |
| 487 | testError("\xf0\x90\xc0", error.UnexpectedEof); | |
| 488 | testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation); | |
| 489 | testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation); | |
| 483 | try testError("\xf0", error.UnexpectedEof); | |
| 484 | try testError("\xf0\x00", error.UnexpectedEof); | |
| 485 | try testError("\xf0\xc0", error.UnexpectedEof); | |
| 486 | try testError("\xf0\x90\x00", error.UnexpectedEof); | |
| 487 | try testError("\xf0\x90\xc0", error.UnexpectedEof); | |
| 488 | try testError("\xf0\x90\x80\x00", error.Utf8ExpectedContinuation); | |
| 489 | try testError("\xf0\x90\x80\xc0", error.Utf8ExpectedContinuation); | |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | test "overlong utf8 codepoint" { |
| 493 | comptime testOverlongUtf8Codepoint(); | |
| 494 | testOverlongUtf8Codepoint(); | |
| 493 | comptime try testOverlongUtf8Codepoint(); | |
| 494 | try testOverlongUtf8Codepoint(); | |
| 495 | 495 | } |
| 496 | fn testOverlongUtf8Codepoint() void { | |
| 497 | testError("\xc0\x80", error.Utf8OverlongEncoding); | |
| 498 | testError("\xc1\xbf", error.Utf8OverlongEncoding); | |
| 499 | testError("\xe0\x80\x80", error.Utf8OverlongEncoding); | |
| 500 | testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding); | |
| 501 | testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding); | |
| 502 | testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding); | |
| 496 | fn testOverlongUtf8Codepoint() !void { | |
| 497 | try testError("\xc0\x80", error.Utf8OverlongEncoding); | |
| 498 | try testError("\xc1\xbf", error.Utf8OverlongEncoding); | |
| 499 | try testError("\xe0\x80\x80", error.Utf8OverlongEncoding); | |
| 500 | try testError("\xe0\x9f\xbf", error.Utf8OverlongEncoding); | |
| 501 | try testError("\xf0\x80\x80\x80", error.Utf8OverlongEncoding); | |
| 502 | try testError("\xf0\x8f\xbf\xbf", error.Utf8OverlongEncoding); | |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | test "misc invalid utf8" { |
| 506 | comptime testMiscInvalidUtf8(); | |
| 507 | testMiscInvalidUtf8(); | |
| 506 | comptime try testMiscInvalidUtf8(); | |
| 507 | try testMiscInvalidUtf8(); | |
| 508 | 508 | } |
| 509 | fn testMiscInvalidUtf8() void { | |
| 509 | fn testMiscInvalidUtf8() !void { | |
| 510 | 510 | // codepoint out of bounds |
| 511 | testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge); | |
| 512 | testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge); | |
| 511 | try testError("\xf4\x90\x80\x80", error.Utf8CodepointTooLarge); | |
| 512 | try testError("\xf7\xbf\xbf\xbf", error.Utf8CodepointTooLarge); | |
| 513 | 513 | // surrogate halves |
| 514 | testValid("\xed\x9f\xbf", 0xd7ff); | |
| 515 | testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf); | |
| 516 | testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf); | |
| 517 | testValid("\xee\x80\x80", 0xe000); | |
| 514 | try testValid("\xed\x9f\xbf", 0xd7ff); | |
| 515 | try testError("\xed\xa0\x80", error.Utf8EncodesSurrogateHalf); | |
| 516 | try testError("\xed\xbf\xbf", error.Utf8EncodesSurrogateHalf); | |
| 517 | try testValid("\xee\x80\x80", 0xe000); | |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | test "utf8 iterator peeking" { |
| 521 | comptime testUtf8Peeking(); | |
| 522 | testUtf8Peeking(); | |
| 521 | comptime try testUtf8Peeking(); | |
| 522 | try testUtf8Peeking(); | |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | fn testUtf8Peeking() void { | |
| 525 | fn testUtf8Peeking() !void { | |
| 526 | 526 | const s = Utf8View.initComptime("noël"); |
| 527 | 527 | var it = s.iterator(); |
| 528 | 528 | |
| 529 | testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?)); | |
| 529 | try testing.expect(std.mem.eql(u8, "n", it.nextCodepointSlice().?)); | |
| 530 | 530 | |
| 531 | testing.expect(std.mem.eql(u8, "o", it.peek(1))); | |
| 532 | testing.expect(std.mem.eql(u8, "oë", it.peek(2))); | |
| 533 | testing.expect(std.mem.eql(u8, "oël", it.peek(3))); | |
| 534 | testing.expect(std.mem.eql(u8, "oël", it.peek(4))); | |
| 535 | testing.expect(std.mem.eql(u8, "oël", it.peek(10))); | |
| 531 | try testing.expect(std.mem.eql(u8, "o", it.peek(1))); | |
| 532 | try testing.expect(std.mem.eql(u8, "oë", it.peek(2))); | |
| 533 | try testing.expect(std.mem.eql(u8, "oël", it.peek(3))); | |
| 534 | try testing.expect(std.mem.eql(u8, "oël", it.peek(4))); | |
| 535 | try testing.expect(std.mem.eql(u8, "oël", it.peek(10))); | |
| 536 | 536 | |
| 537 | testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?)); | |
| 538 | testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?)); | |
| 539 | testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?)); | |
| 540 | testing.expect(it.nextCodepointSlice() == null); | |
| 537 | try testing.expect(std.mem.eql(u8, "o", it.nextCodepointSlice().?)); | |
| 538 | try testing.expect(std.mem.eql(u8, "ë", it.nextCodepointSlice().?)); | |
| 539 | try testing.expect(std.mem.eql(u8, "l", it.nextCodepointSlice().?)); | |
| 540 | try testing.expect(it.nextCodepointSlice() == null); | |
| 541 | 541 | |
| 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 | } |
| 544 | 544 | |
| 545 | fn testError(bytes: []const u8, expected_err: anyerror) void { | |
| 546 | testing.expectError(expected_err, testDecode(bytes)); | |
| 545 | fn testError(bytes: []const u8, expected_err: anyerror) !void { | |
| 546 | try testing.expectError(expected_err, testDecode(bytes)); | |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | fn testValid(bytes: []const u8, expected_codepoint: u21) void { | |
| 550 | testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint); | |
| 549 | fn testValid(bytes: []const u8, expected_codepoint: u21) !void { | |
| 550 | try testing.expect((testDecode(bytes) catch unreachable) == expected_codepoint); | |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | fn testDecode(bytes: []const u8) !u21 { |
| 554 | 554 | const length = try utf8ByteSequenceLength(bytes[0]); |
| 555 | 555 | if (bytes.len < length) return error.UnexpectedEof; |
| 556 | testing.expect(bytes.len == length); | |
| 556 | try testing.expect(bytes.len == length); | |
| 557 | 557 | return utf8Decode(bytes); |
| 558 | 558 | } |
| 559 | 559 | |
| ... | ... | @@ -615,7 +615,7 @@ test "utf16leToUtf8" { |
| 615 | 615 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a'); |
| 616 | 616 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 617 | 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 | } |
| 620 | 620 | |
| 621 | 621 | { |
| ... | ... | @@ -623,7 +623,7 @@ test "utf16leToUtf8" { |
| 623 | 623 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff); |
| 624 | 624 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 625 | 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 | } |
| 628 | 628 | |
| 629 | 629 | { |
| ... | ... | @@ -632,7 +632,7 @@ test "utf16leToUtf8" { |
| 632 | 632 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000); |
| 633 | 633 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 634 | 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 | } |
| 637 | 637 | |
| 638 | 638 | { |
| ... | ... | @@ -641,7 +641,7 @@ test "utf16leToUtf8" { |
| 641 | 641 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); |
| 642 | 642 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 643 | 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 | } |
| 646 | 646 | |
| 647 | 647 | { |
| ... | ... | @@ -650,7 +650,7 @@ test "utf16leToUtf8" { |
| 650 | 650 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff); |
| 651 | 651 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 652 | 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 | } |
| 655 | 655 | |
| 656 | 656 | { |
| ... | ... | @@ -658,7 +658,7 @@ test "utf16leToUtf8" { |
| 658 | 658 | mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00); |
| 659 | 659 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 660 | 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 | } |
| 664 | 664 | |
| ... | ... | @@ -717,13 +717,13 @@ test "utf8ToUtf16Le" { |
| 717 | 717 | var utf16le: [2]u16 = [_]u16{0} ** 2; |
| 718 | 718 | { |
| 719 | 719 | const length = try utf8ToUtf16Le(utf16le[0..], "𐐷"); |
| 720 | testing.expectEqual(@as(usize, 2), length); | |
| 721 | testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..])); | |
| 720 | try testing.expectEqual(@as(usize, 2), length); | |
| 721 | try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16le[0..])); | |
| 722 | 722 | } |
| 723 | 723 | { |
| 724 | 724 | const length = try utf8ToUtf16Le(utf16le[0..], "\u{10FFFF}"); |
| 725 | testing.expectEqual(@as(usize, 2), length); | |
| 726 | testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..])); | |
| 725 | try testing.expectEqual(@as(usize, 2), length); | |
| 726 | try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16le[0..])); | |
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | |
| ... | ... | @@ -731,14 +731,14 @@ test "utf8ToUtf16LeWithNull" { |
| 731 | 731 | { |
| 732 | 732 | const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "𐐷"); |
| 733 | 733 | defer testing.allocator.free(utf16); |
| 734 | testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..])); | |
| 735 | testing.expect(utf16[2] == 0); | |
| 734 | try testing.expectEqualSlices(u8, "\x01\xd8\x37\xdc", mem.sliceAsBytes(utf16[0..])); | |
| 735 | try testing.expect(utf16[2] == 0); | |
| 736 | 736 | } |
| 737 | 737 | { |
| 738 | 738 | const utf16 = try utf8ToUtf16LeWithNull(testing.allocator, "\u{10FFFF}"); |
| 739 | 739 | defer testing.allocator.free(utf16); |
| 740 | testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..])); | |
| 741 | testing.expect(utf16[2] == 0); | |
| 740 | try testing.expectEqualSlices(u8, "\xff\xdb\xff\xdf", mem.sliceAsBytes(utf16[0..])); | |
| 741 | try testing.expect(utf16[2] == 0); | |
| 742 | 742 | } |
| 743 | 743 | } |
| 744 | 744 | |
| ... | ... | @@ -776,8 +776,8 @@ test "utf8ToUtf16LeStringLiteral" { |
| 776 | 776 | mem.nativeToLittle(u16, 0x41), |
| 777 | 777 | }; |
| 778 | 778 | const utf16 = utf8ToUtf16LeStringLiteral("A"); |
| 779 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 780 | testing.expect(utf16[1] == 0); | |
| 779 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 780 | try testing.expect(utf16[1] == 0); | |
| 781 | 781 | } |
| 782 | 782 | { |
| 783 | 783 | const bytes = [_:0]u16{ |
| ... | ... | @@ -785,32 +785,32 @@ test "utf8ToUtf16LeStringLiteral" { |
| 785 | 785 | mem.nativeToLittle(u16, 0xDC37), |
| 786 | 786 | }; |
| 787 | 787 | const utf16 = utf8ToUtf16LeStringLiteral("𐐷"); |
| 788 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 789 | testing.expect(utf16[2] == 0); | |
| 788 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 789 | try testing.expect(utf16[2] == 0); | |
| 790 | 790 | } |
| 791 | 791 | { |
| 792 | 792 | const bytes = [_:0]u16{ |
| 793 | 793 | mem.nativeToLittle(u16, 0x02FF), |
| 794 | 794 | }; |
| 795 | 795 | const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); |
| 796 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 797 | testing.expect(utf16[1] == 0); | |
| 796 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 797 | try testing.expect(utf16[1] == 0); | |
| 798 | 798 | } |
| 799 | 799 | { |
| 800 | 800 | const bytes = [_:0]u16{ |
| 801 | 801 | mem.nativeToLittle(u16, 0x7FF), |
| 802 | 802 | }; |
| 803 | 803 | const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); |
| 804 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 805 | testing.expect(utf16[1] == 0); | |
| 804 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 805 | try testing.expect(utf16[1] == 0); | |
| 806 | 806 | } |
| 807 | 807 | { |
| 808 | 808 | const bytes = [_:0]u16{ |
| 809 | 809 | mem.nativeToLittle(u16, 0x801), |
| 810 | 810 | }; |
| 811 | 811 | const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); |
| 812 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 813 | testing.expect(utf16[1] == 0); | |
| 812 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 813 | try testing.expect(utf16[1] == 0); | |
| 814 | 814 | } |
| 815 | 815 | { |
| 816 | 816 | const bytes = [_:0]u16{ |
| ... | ... | @@ -818,35 +818,35 @@ test "utf8ToUtf16LeStringLiteral" { |
| 818 | 818 | mem.nativeToLittle(u16, 0xDFFF), |
| 819 | 819 | }; |
| 820 | 820 | const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}"); |
| 821 | testing.expectEqualSlices(u16, &bytes, utf16); | |
| 822 | testing.expect(utf16[2] == 0); | |
| 821 | try testing.expectEqualSlices(u16, &bytes, utf16); | |
| 822 | try testing.expect(utf16[2] == 0); | |
| 823 | 823 | } |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | fn testUtf8CountCodepoints() !void { |
| 827 | testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij")); | |
| 828 | testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö")); | |
| 829 | testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは")); | |
| 827 | try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("abcdefghij")); | |
| 828 | try testing.expectEqual(@as(usize, 10), try utf8CountCodepoints("äåéëþüúíóö")); | |
| 829 | try testing.expectEqual(@as(usize, 5), try utf8CountCodepoints("こんにちは")); | |
| 830 | 830 | // testing.expectError(error.Utf8EncodesSurrogateHalf, utf8CountCodepoints("\xED\xA0\x80")); |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | test "utf8 count codepoints" { |
| 834 | 834 | try testUtf8CountCodepoints(); |
| 835 | comptime testUtf8CountCodepoints() catch unreachable; | |
| 835 | comptime try testUtf8CountCodepoints(); | |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | fn testUtf8ValidCodepoint() !void { |
| 839 | testing.expect(utf8ValidCodepoint('e')); | |
| 840 | testing.expect(utf8ValidCodepoint('ë')); | |
| 841 | testing.expect(utf8ValidCodepoint('は')); | |
| 842 | testing.expect(utf8ValidCodepoint(0xe000)); | |
| 843 | testing.expect(utf8ValidCodepoint(0x10ffff)); | |
| 844 | testing.expect(!utf8ValidCodepoint(0xd800)); | |
| 845 | testing.expect(!utf8ValidCodepoint(0xdfff)); | |
| 846 | testing.expect(!utf8ValidCodepoint(0x110000)); | |
| 839 | try testing.expect(utf8ValidCodepoint('e')); | |
| 840 | try testing.expect(utf8ValidCodepoint('ë')); | |
| 841 | try testing.expect(utf8ValidCodepoint('は')); | |
| 842 | try testing.expect(utf8ValidCodepoint(0xe000)); | |
| 843 | try testing.expect(utf8ValidCodepoint(0x10ffff)); | |
| 844 | try testing.expect(!utf8ValidCodepoint(0xd800)); | |
| 845 | try testing.expect(!utf8ValidCodepoint(0xdfff)); | |
| 846 | try testing.expect(!utf8ValidCodepoint(0x110000)); | |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | test "utf8 valid codepoint" { |
| 850 | 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 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "countLeaks" { |
| 152 | testing.expectEqual( | |
| 152 | try testing.expectEqual( | |
| 153 | 153 | @as(CountResult, .{ |
| 154 | 154 | .leaked = 0, |
| 155 | 155 | .dubious = 0, |
| ... | ... | @@ -179,7 +179,7 @@ pub fn countLeakBlocks() CountResult { |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | test "countLeakBlocks" { |
| 182 | testing.expectEqual( | |
| 182 | try testing.expectEqual( | |
| 183 | 183 | @as(CountResult, .{ |
| 184 | 184 | .leaked = 0, |
| 185 | 185 | .dubious = 0, |
lib/std/wasm.zig+9-9| ... | ... | @@ -200,11 +200,11 @@ test "Wasm - opcodes" { |
| 200 | 200 | const local_get = opcode(.local_get); |
| 201 | 201 | const i64_extend32_s = opcode(.i64_extend32_s); |
| 202 | 202 | |
| 203 | testing.expectEqual(@as(u16, 0x41), i32_const); | |
| 204 | testing.expectEqual(@as(u16, 0x0B), end); | |
| 205 | testing.expectEqual(@as(u16, 0x1A), drop); | |
| 206 | testing.expectEqual(@as(u16, 0x20), local_get); | |
| 207 | testing.expectEqual(@as(u16, 0xC4), i64_extend32_s); | |
| 203 | try testing.expectEqual(@as(u16, 0x41), i32_const); | |
| 204 | try testing.expectEqual(@as(u16, 0x0B), end); | |
| 205 | try testing.expectEqual(@as(u16, 0x1A), drop); | |
| 206 | try testing.expectEqual(@as(u16, 0x20), local_get); | |
| 207 | try testing.expectEqual(@as(u16, 0xC4), i64_extend32_s); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /// Enum representing all Wasm value types as per spec: |
| ... | ... | @@ -227,10 +227,10 @@ test "Wasm - valtypes" { |
| 227 | 227 | const _f32 = valtype(.f32); |
| 228 | 228 | const _f64 = valtype(.f64); |
| 229 | 229 | |
| 230 | testing.expectEqual(@as(u8, 0x7F), _i32); | |
| 231 | testing.expectEqual(@as(u8, 0x7E), _i64); | |
| 232 | testing.expectEqual(@as(u8, 0x7D), _f32); | |
| 233 | testing.expectEqual(@as(u8, 0x7C), _f64); | |
| 230 | try testing.expectEqual(@as(u8, 0x7F), _i32); | |
| 231 | try testing.expectEqual(@as(u8, 0x7E), _i64); | |
| 232 | try testing.expectEqual(@as(u8, 0x7D), _f32); | |
| 233 | try testing.expectEqual(@as(u8, 0x7C), _f64); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 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 | 322 | defer conn.deinit(); |
| 323 | 323 | |
| 324 | 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 | } |
| 327 | 327 | |
| 328 | 328 | test "tcp/listener: bind to unspecified ipv4 address" { |
| ... | ... | @@ -335,7 +335,7 @@ test "tcp/listener: bind to unspecified ipv4 address" { |
| 335 | 335 | try listener.listen(128); |
| 336 | 336 | |
| 337 | 337 | const address = try listener.getLocalAddress(); |
| 338 | testing.expect(address == .ipv4); | |
| 338 | try testing.expect(address == .ipv4); | |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | test "tcp/listener: bind to unspecified ipv6 address" { |
| ... | ... | @@ -348,5 +348,5 @@ test "tcp/listener: bind to unspecified ipv6 address" { |
| 348 | 348 | try listener.listen(128); |
| 349 | 349 | |
| 350 | 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 | 499 | |
| 500 | 500 | test "ip: convert to and from ipv6" { |
| 501 | 501 | try testing.expectFmt("::7f00:1", "{}", .{IPv4.localhost.toIPv6()}); |
| 502 | testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4()); | |
| 502 | try testing.expect(!IPv4.localhost.toIPv6().mapsToIPv4()); | |
| 503 | 503 | |
| 504 | 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()); | |
| 506 | 506 | |
| 507 | testing.expect(IPv4.localhost.toIPv6().toIPv4() == null); | |
| 507 | try testing.expect(IPv4.localhost.toIPv6().toIPv4() == null); | |
| 508 | 508 | try testing.expectFmt("127.0.0.1", "{}", .{IPv4.localhost.mapToIPv6().toIPv4()}); |
| 509 | 509 | } |
| 510 | 510 |
lib/std/zig.zig+19-19| ... | ... | @@ -253,26 +253,26 @@ pub fn parseCharLiteral( |
| 253 | 253 | |
| 254 | 254 | test "parseCharLiteral" { |
| 255 | 255 | var bad_index: usize = undefined; |
| 256 | std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a'); | |
| 257 | std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä'); | |
| 258 | std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0); | |
| 259 | std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f); | |
| 260 | std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f); | |
| 261 | std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041); | |
| 262 | std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0); | |
| 263 | std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041); | |
| 264 | std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f); | |
| 265 | std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF); | |
| 256 | try std.testing.expectEqual(try parseCharLiteral("'a'", &bad_index), 'a'); | |
| 257 | try std.testing.expectEqual(try parseCharLiteral("'ä'", &bad_index), 'ä'); | |
| 258 | try std.testing.expectEqual(try parseCharLiteral("'\\x00'", &bad_index), 0); | |
| 259 | try std.testing.expectEqual(try parseCharLiteral("'\\x4f'", &bad_index), 0x4f); | |
| 260 | try std.testing.expectEqual(try parseCharLiteral("'\\x4F'", &bad_index), 0x4f); | |
| 261 | try std.testing.expectEqual(try parseCharLiteral("'ぁ'", &bad_index), 0x3041); | |
| 262 | try std.testing.expectEqual(try parseCharLiteral("'\\u{0}'", &bad_index), 0); | |
| 263 | try std.testing.expectEqual(try parseCharLiteral("'\\u{3041}'", &bad_index), 0x3041); | |
| 264 | try std.testing.expectEqual(try parseCharLiteral("'\\u{7f}'", &bad_index), 0x7f); | |
| 265 | try std.testing.expectEqual(try parseCharLiteral("'\\u{7FFF}'", &bad_index), 0x7FFF); | |
| 266 | 266 | |
| 267 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index)); | |
| 268 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index)); | |
| 269 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index)); | |
| 270 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index)); | |
| 271 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index)); | |
| 272 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index)); | |
| 273 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index)); | |
| 274 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index)); | |
| 275 | std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index)); | |
| 267 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x0'", &bad_index)); | |
| 268 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\x000'", &bad_index)); | |
| 269 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\y'", &bad_index)); | |
| 270 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u'", &bad_index)); | |
| 271 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\uFFFF'", &bad_index)); | |
| 272 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{}'", &bad_index)); | |
| 273 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFFFF}'", &bad_index)); | |
| 274 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF'", &bad_index)); | |
| 275 | try std.testing.expectError(error.InvalidCharacter, parseCharLiteral("'\\u{FFFF}x'", &bad_index)); | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | test { |
lib/std/zig/cross_target.zig+38-38| ... | ... | @@ -800,7 +800,7 @@ test "CrossTarget.parse" { |
| 800 | 800 | .{@tagName(std.Target.current.abi)}, |
| 801 | 801 | ) catch unreachable; |
| 802 | 802 | |
| 803 | std.testing.expectEqualSlices(u8, triple, text); | |
| 803 | try std.testing.expectEqualSlices(u8, triple, text); | |
| 804 | 804 | } |
| 805 | 805 | { |
| 806 | 806 | const cross_target = try CrossTarget.parse(.{ |
| ... | ... | @@ -808,18 +808,18 @@ test "CrossTarget.parse" { |
| 808 | 808 | .cpu_features = "native", |
| 809 | 809 | }); |
| 810 | 810 | |
| 811 | std.testing.expect(cross_target.cpu_arch.? == .aarch64); | |
| 812 | std.testing.expect(cross_target.cpu_model == .native); | |
| 811 | try std.testing.expect(cross_target.cpu_arch.? == .aarch64); | |
| 812 | try std.testing.expect(cross_target.cpu_model == .native); | |
| 813 | 813 | } |
| 814 | 814 | { |
| 815 | 815 | const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); |
| 816 | 816 | |
| 817 | std.testing.expect(cross_target.cpu_arch == null); | |
| 818 | std.testing.expect(cross_target.isNative()); | |
| 817 | try std.testing.expect(cross_target.cpu_arch == null); | |
| 818 | try std.testing.expect(cross_target.isNative()); | |
| 819 | 819 | |
| 820 | 820 | const text = try cross_target.zigTriple(std.testing.allocator); |
| 821 | 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 | 825 | const cross_target = try CrossTarget.parse(.{ |
| ... | ... | @@ -828,23 +828,23 @@ test "CrossTarget.parse" { |
| 828 | 828 | }); |
| 829 | 829 | const target = cross_target.toTarget(); |
| 830 | 830 | |
| 831 | std.testing.expect(target.os.tag == .linux); | |
| 832 | std.testing.expect(target.abi == .gnu); | |
| 833 | std.testing.expect(target.cpu.arch == .x86_64); | |
| 834 | std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse)); | |
| 835 | std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx)); | |
| 836 | std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8)); | |
| 837 | std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov)); | |
| 838 | std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr)); | |
| 831 | try std.testing.expect(target.os.tag == .linux); | |
| 832 | try std.testing.expect(target.abi == .gnu); | |
| 833 | try std.testing.expect(target.cpu.arch == .x86_64); | |
| 834 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .sse)); | |
| 835 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .avx)); | |
| 836 | try std.testing.expect(!Target.x86.featureSetHas(target.cpu.features, .cx8)); | |
| 837 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .cmov)); | |
| 838 | try std.testing.expect(Target.x86.featureSetHas(target.cpu.features, .fxsr)); | |
| 839 | 839 | |
| 840 | std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })); | |
| 841 | std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx })); | |
| 842 | std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 })); | |
| 843 | std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse })); | |
| 840 | try std.testing.expect(Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })); | |
| 841 | try std.testing.expect(!Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx })); | |
| 842 | try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 })); | |
| 843 | try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse })); | |
| 844 | 844 | |
| 845 | 845 | const text = try cross_target.zigTriple(std.testing.allocator); |
| 846 | 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 | 850 | const cross_target = try CrossTarget.parse(.{ |
| ... | ... | @@ -853,15 +853,15 @@ test "CrossTarget.parse" { |
| 853 | 853 | }); |
| 854 | 854 | const target = cross_target.toTarget(); |
| 855 | 855 | |
| 856 | std.testing.expect(target.os.tag == .linux); | |
| 857 | std.testing.expect(target.abi == .musleabihf); | |
| 858 | std.testing.expect(target.cpu.arch == .arm); | |
| 859 | std.testing.expect(target.cpu.model == &Target.arm.cpu.generic); | |
| 860 | std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a)); | |
| 856 | try std.testing.expect(target.os.tag == .linux); | |
| 857 | try std.testing.expect(target.abi == .musleabihf); | |
| 858 | try std.testing.expect(target.cpu.arch == .arm); | |
| 859 | try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic); | |
| 860 | try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a)); | |
| 861 | 861 | |
| 862 | 862 | const text = try cross_target.zigTriple(std.testing.allocator); |
| 863 | 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 | 867 | const cross_target = try CrossTarget.parse(.{ |
| ... | ... | @@ -870,21 +870,21 @@ test "CrossTarget.parse" { |
| 870 | 870 | }); |
| 871 | 871 | const target = cross_target.toTarget(); |
| 872 | 872 | |
| 873 | std.testing.expect(target.cpu.arch == .aarch64); | |
| 874 | std.testing.expect(target.os.tag == .linux); | |
| 875 | std.testing.expect(target.os.version_range.linux.range.min.major == 3); | |
| 876 | std.testing.expect(target.os.version_range.linux.range.min.minor == 10); | |
| 877 | std.testing.expect(target.os.version_range.linux.range.min.patch == 0); | |
| 878 | std.testing.expect(target.os.version_range.linux.range.max.major == 4); | |
| 879 | std.testing.expect(target.os.version_range.linux.range.max.minor == 4); | |
| 880 | std.testing.expect(target.os.version_range.linux.range.max.patch == 1); | |
| 881 | std.testing.expect(target.os.version_range.linux.glibc.major == 2); | |
| 882 | std.testing.expect(target.os.version_range.linux.glibc.minor == 27); | |
| 883 | std.testing.expect(target.os.version_range.linux.glibc.patch == 0); | |
| 884 | std.testing.expect(target.abi == .gnu); | |
| 873 | try std.testing.expect(target.cpu.arch == .aarch64); | |
| 874 | try std.testing.expect(target.os.tag == .linux); | |
| 875 | try std.testing.expect(target.os.version_range.linux.range.min.major == 3); | |
| 876 | try std.testing.expect(target.os.version_range.linux.range.min.minor == 10); | |
| 877 | try std.testing.expect(target.os.version_range.linux.range.min.patch == 0); | |
| 878 | try std.testing.expect(target.os.version_range.linux.range.max.major == 4); | |
| 879 | try std.testing.expect(target.os.version_range.linux.range.max.minor == 4); | |
| 880 | try std.testing.expect(target.os.version_range.linux.range.max.patch == 1); | |
| 881 | try std.testing.expect(target.os.version_range.linux.glibc.major == 2); | |
| 882 | try std.testing.expect(target.os.version_range.linux.glibc.minor == 27); | |
| 883 | try std.testing.expect(target.os.version_range.linux.glibc.patch == 0); | |
| 884 | try std.testing.expect(target.abi == .gnu); | |
| 885 | 885 | |
| 886 | 886 | const text = try cross_target.zigTriple(std.testing.allocator); |
| 887 | 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 | 988 | \\ const result = while (returnError()) |value| { |
| 989 | 989 | \\ break value; |
| 990 | 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 | 5135 | |
| 5136 | 5136 | const std = @import("std"); |
| 5137 | 5137 | const mem = std.mem; |
| 5138 | const warn = std.debug.warn; | |
| 5138 | const print = std.debug.print; | |
| 5139 | 5139 | const io = std.io; |
| 5140 | 5140 | const maxInt = std.math.maxInt; |
| 5141 | 5141 | |
| ... | ... | @@ -5177,13 +5177,13 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 5177 | 5177 | var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize)); |
| 5178 | 5178 | var anything_changed: bool = undefined; |
| 5179 | 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 | 5181 | const changes_expected = source.ptr != expected_source.ptr; |
| 5182 | 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 | 5184 | return error.TestFailed; |
| 5185 | 5185 | } |
| 5186 | std.testing.expect(anything_changed == changes_expected); | |
| 5186 | try std.testing.expect(anything_changed == changes_expected); | |
| 5187 | 5187 | failing_allocator.allocator.free(result_source); |
| 5188 | 5188 | break :x failing_allocator.index; |
| 5189 | 5189 | }; |
| ... | ... | @@ -5198,7 +5198,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 5198 | 5198 | } else |err| switch (err) { |
| 5199 | 5199 | error.OutOfMemory => { |
| 5200 | 5200 | if (failing_allocator.allocated_bytes != failing_allocator.freed_bytes) { |
| 5201 | warn( | |
| 5201 | print( | |
| 5202 | 5202 | "\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\n", |
| 5203 | 5203 | .{ |
| 5204 | 5204 | fail_index, |
| ... | ... | @@ -5212,8 +5212,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 5212 | 5212 | return error.MemoryLeakDetected; |
| 5213 | 5213 | } |
| 5214 | 5214 | }, |
| 5215 | error.ParseError => @panic("test failed"), | |
| 5216 | else => @panic("test failed"), | |
| 5215 | else => return err, | |
| 5217 | 5216 | } |
| 5218 | 5217 | } |
| 5219 | 5218 | } |
| ... | ... | @@ -5227,8 +5226,8 @@ fn testError(source: []const u8, expected_errors: []const Error) !void { |
| 5227 | 5226 | var tree = try std.zig.parse(std.testing.allocator, source); |
| 5228 | 5227 | defer tree.deinit(std.testing.allocator); |
| 5229 | 5228 | |
| 5230 | std.testing.expectEqual(expected_errors.len, tree.errors.len); | |
| 5229 | try std.testing.expectEqual(expected_errors.len, tree.errors.len); | |
| 5231 | 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 | 153 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]); |
| 154 | 154 | var alloc = &fixed_buf_alloc.allocator; |
| 155 | 155 | |
| 156 | expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\""))); | |
| 157 | expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\""))); | |
| 158 | expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\""))); | |
| 156 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\""))); | |
| 157 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\""))); | |
| 158 | try expect(eql(u8, "f💯", try parseAlloc(alloc, "\"f\u{1f4af}\""))); | |
| 159 | 159 | } |
lib/std/zig/system/linux.zig+2-2| ... | ... | @@ -414,8 +414,8 @@ fn testParser( |
| 414 | 414 | ) !void { |
| 415 | 415 | var fbs = io.fixedBufferStream(input); |
| 416 | 416 | const result = try parser.parse(arch, fbs.reader()); |
| 417 | testing.expectEqual(expected_model, result.?.model); | |
| 418 | testing.expect(expected_model.features.eql(result.?.features)); | |
| 417 | try testing.expectEqual(expected_model, result.?.model); | |
| 418 | try testing.expect(expected_model.features.eql(result.?.features)); | |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 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 | 402 | var b_got: [64]u8 = undefined; |
| 403 | 403 | const s_got: []const u8 = try std.fmt.bufPrint(b_got[0..], "{}", .{got}); |
| 404 | 404 | |
| 405 | testing.expectEqualStrings(s_expected, s_got); | |
| 405 | try testing.expectEqualStrings(s_expected, s_got); | |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /// Detect SDK path on Darwin. |
lib/std/zig/tokenizer.zig+294-294| ... | ... | @@ -1503,11 +1503,11 @@ pub const Tokenizer = struct { |
| 1503 | 1503 | }; |
| 1504 | 1504 | |
| 1505 | 1505 | test "tokenizer" { |
| 1506 | testTokenize("test", &.{.keyword_test}); | |
| 1506 | try testTokenize("test", &.{.keyword_test}); | |
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | test "line comment followed by top-level comptime" { |
| 1510 | testTokenize( | |
| 1510 | try testTokenize( | |
| 1511 | 1511 | \\// line comment |
| 1512 | 1512 | \\comptime {} |
| 1513 | 1513 | \\ |
| ... | ... | @@ -1519,7 +1519,7 @@ test "line comment followed by top-level comptime" { |
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | test "tokenizer - unknown length pointer and then c pointer" { |
| 1522 | testTokenize( | |
| 1522 | try testTokenize( | |
| 1523 | 1523 | \\[*]u8 |
| 1524 | 1524 | \\[*c]u8 |
| 1525 | 1525 | , &.{ |
| ... | ... | @@ -1536,72 +1536,72 @@ test "tokenizer - unknown length pointer and then c pointer" { |
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | 1538 | test "tokenizer - code point literal with hex escape" { |
| 1539 | testTokenize( | |
| 1539 | try testTokenize( | |
| 1540 | 1540 | \\'\x1b' |
| 1541 | 1541 | , &.{.char_literal}); |
| 1542 | testTokenize( | |
| 1542 | try testTokenize( | |
| 1543 | 1543 | \\'\x1' |
| 1544 | 1544 | , &.{ .invalid, .invalid }); |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | test "tokenizer - code point literal with unicode escapes" { |
| 1548 | 1548 | // Valid unicode escapes |
| 1549 | testTokenize( | |
| 1549 | try testTokenize( | |
| 1550 | 1550 | \\'\u{3}' |
| 1551 | 1551 | , &.{.char_literal}); |
| 1552 | testTokenize( | |
| 1552 | try testTokenize( | |
| 1553 | 1553 | \\'\u{01}' |
| 1554 | 1554 | , &.{.char_literal}); |
| 1555 | testTokenize( | |
| 1555 | try testTokenize( | |
| 1556 | 1556 | \\'\u{2a}' |
| 1557 | 1557 | , &.{.char_literal}); |
| 1558 | testTokenize( | |
| 1558 | try testTokenize( | |
| 1559 | 1559 | \\'\u{3f9}' |
| 1560 | 1560 | , &.{.char_literal}); |
| 1561 | testTokenize( | |
| 1561 | try testTokenize( | |
| 1562 | 1562 | \\'\u{6E09aBc1523}' |
| 1563 | 1563 | , &.{.char_literal}); |
| 1564 | testTokenize( | |
| 1564 | try testTokenize( | |
| 1565 | 1565 | \\"\u{440}" |
| 1566 | 1566 | , &.{.string_literal}); |
| 1567 | 1567 | |
| 1568 | 1568 | // Invalid unicode escapes |
| 1569 | testTokenize( | |
| 1569 | try testTokenize( | |
| 1570 | 1570 | \\'\u' |
| 1571 | 1571 | , &.{.invalid}); |
| 1572 | testTokenize( | |
| 1572 | try testTokenize( | |
| 1573 | 1573 | \\'\u{{' |
| 1574 | 1574 | , &.{ .invalid, .invalid }); |
| 1575 | testTokenize( | |
| 1575 | try testTokenize( | |
| 1576 | 1576 | \\'\u{}' |
| 1577 | 1577 | , &.{ .invalid, .invalid }); |
| 1578 | testTokenize( | |
| 1578 | try testTokenize( | |
| 1579 | 1579 | \\'\u{s}' |
| 1580 | 1580 | , &.{ .invalid, .invalid }); |
| 1581 | testTokenize( | |
| 1581 | try testTokenize( | |
| 1582 | 1582 | \\'\u{2z}' |
| 1583 | 1583 | , &.{ .invalid, .invalid }); |
| 1584 | testTokenize( | |
| 1584 | try testTokenize( | |
| 1585 | 1585 | \\'\u{4a' |
| 1586 | 1586 | , &.{.invalid}); |
| 1587 | 1587 | |
| 1588 | 1588 | // Test old-style unicode literals |
| 1589 | testTokenize( | |
| 1589 | try testTokenize( | |
| 1590 | 1590 | \\'\u0333' |
| 1591 | 1591 | , &.{ .invalid, .invalid }); |
| 1592 | testTokenize( | |
| 1592 | try testTokenize( | |
| 1593 | 1593 | \\'\U0333' |
| 1594 | 1594 | , &.{ .invalid, .integer_literal, .invalid }); |
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | test "tokenizer - code point literal with unicode code point" { |
| 1598 | testTokenize( | |
| 1598 | try testTokenize( | |
| 1599 | 1599 | \\'💩' |
| 1600 | 1600 | , &.{.char_literal}); |
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | 1603 | test "tokenizer - float literal e exponent" { |
| 1604 | testTokenize("a = 4.94065645841246544177e-324;\n", &.{ | |
| 1604 | try testTokenize("a = 4.94065645841246544177e-324;\n", &.{ | |
| 1605 | 1605 | .identifier, |
| 1606 | 1606 | .equal, |
| 1607 | 1607 | .float_literal, |
| ... | ... | @@ -1610,7 +1610,7 @@ test "tokenizer - float literal e exponent" { |
| 1610 | 1610 | } |
| 1611 | 1611 | |
| 1612 | 1612 | test "tokenizer - float literal p exponent" { |
| 1613 | testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{ | |
| 1613 | try testTokenize("a = 0x1.a827999fcef32p+1022;\n", &.{ | |
| 1614 | 1614 | .identifier, |
| 1615 | 1615 | .equal, |
| 1616 | 1616 | .float_literal, |
| ... | ... | @@ -1619,84 +1619,84 @@ test "tokenizer - float literal p exponent" { |
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | test "tokenizer - chars" { |
| 1622 | testTokenize("'c'", &.{.char_literal}); | |
| 1622 | try testTokenize("'c'", &.{.char_literal}); | |
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | test "tokenizer - invalid token characters" { |
| 1626 | testTokenize("#", &.{.invalid}); | |
| 1627 | testTokenize("`", &.{.invalid}); | |
| 1628 | testTokenize("'c", &.{.invalid}); | |
| 1629 | testTokenize("'", &.{.invalid}); | |
| 1630 | testTokenize("''", &.{ .invalid, .invalid }); | |
| 1626 | try testTokenize("#", &.{.invalid}); | |
| 1627 | try testTokenize("`", &.{.invalid}); | |
| 1628 | try testTokenize("'c", &.{.invalid}); | |
| 1629 | try testTokenize("'", &.{.invalid}); | |
| 1630 | try testTokenize("''", &.{ .invalid, .invalid }); | |
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | test "tokenizer - invalid literal/comment characters" { |
| 1634 | testTokenize("\"\x00\"", &.{ | |
| 1634 | try testTokenize("\"\x00\"", &.{ | |
| 1635 | 1635 | .string_literal, |
| 1636 | 1636 | .invalid, |
| 1637 | 1637 | }); |
| 1638 | testTokenize("//\x00", &.{ | |
| 1638 | try testTokenize("//\x00", &.{ | |
| 1639 | 1639 | .invalid, |
| 1640 | 1640 | }); |
| 1641 | testTokenize("//\x1f", &.{ | |
| 1641 | try testTokenize("//\x1f", &.{ | |
| 1642 | 1642 | .invalid, |
| 1643 | 1643 | }); |
| 1644 | testTokenize("//\x7f", &.{ | |
| 1644 | try testTokenize("//\x7f", &.{ | |
| 1645 | 1645 | .invalid, |
| 1646 | 1646 | }); |
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | test "tokenizer - utf8" { |
| 1650 | testTokenize("//\xc2\x80", &.{}); | |
| 1651 | testTokenize("//\xf4\x8f\xbf\xbf", &.{}); | |
| 1650 | try testTokenize("//\xc2\x80", &.{}); | |
| 1651 | try testTokenize("//\xf4\x8f\xbf\xbf", &.{}); | |
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | test "tokenizer - invalid utf8" { |
| 1655 | testTokenize("//\x80", &.{ | |
| 1655 | try testTokenize("//\x80", &.{ | |
| 1656 | 1656 | .invalid, |
| 1657 | 1657 | }); |
| 1658 | testTokenize("//\xbf", &.{ | |
| 1658 | try testTokenize("//\xbf", &.{ | |
| 1659 | 1659 | .invalid, |
| 1660 | 1660 | }); |
| 1661 | testTokenize("//\xf8", &.{ | |
| 1661 | try testTokenize("//\xf8", &.{ | |
| 1662 | 1662 | .invalid, |
| 1663 | 1663 | }); |
| 1664 | testTokenize("//\xff", &.{ | |
| 1664 | try testTokenize("//\xff", &.{ | |
| 1665 | 1665 | .invalid, |
| 1666 | 1666 | }); |
| 1667 | testTokenize("//\xc2\xc0", &.{ | |
| 1667 | try testTokenize("//\xc2\xc0", &.{ | |
| 1668 | 1668 | .invalid, |
| 1669 | 1669 | }); |
| 1670 | testTokenize("//\xe0", &.{ | |
| 1670 | try testTokenize("//\xe0", &.{ | |
| 1671 | 1671 | .invalid, |
| 1672 | 1672 | }); |
| 1673 | testTokenize("//\xf0", &.{ | |
| 1673 | try testTokenize("//\xf0", &.{ | |
| 1674 | 1674 | .invalid, |
| 1675 | 1675 | }); |
| 1676 | testTokenize("//\xf0\x90\x80\xc0", &.{ | |
| 1676 | try testTokenize("//\xf0\x90\x80\xc0", &.{ | |
| 1677 | 1677 | .invalid, |
| 1678 | 1678 | }); |
| 1679 | 1679 | } |
| 1680 | 1680 | |
| 1681 | 1681 | test "tokenizer - illegal unicode codepoints" { |
| 1682 | 1682 | // unicode newline characters.U+0085, U+2028, U+2029 |
| 1683 | testTokenize("//\xc2\x84", &.{}); | |
| 1684 | testTokenize("//\xc2\x85", &.{ | |
| 1683 | try testTokenize("//\xc2\x84", &.{}); | |
| 1684 | try testTokenize("//\xc2\x85", &.{ | |
| 1685 | 1685 | .invalid, |
| 1686 | 1686 | }); |
| 1687 | testTokenize("//\xc2\x86", &.{}); | |
| 1688 | testTokenize("//\xe2\x80\xa7", &.{}); | |
| 1689 | testTokenize("//\xe2\x80\xa8", &.{ | |
| 1687 | try testTokenize("//\xc2\x86", &.{}); | |
| 1688 | try testTokenize("//\xe2\x80\xa7", &.{}); | |
| 1689 | try testTokenize("//\xe2\x80\xa8", &.{ | |
| 1690 | 1690 | .invalid, |
| 1691 | 1691 | }); |
| 1692 | testTokenize("//\xe2\x80\xa9", &.{ | |
| 1692 | try testTokenize("//\xe2\x80\xa9", &.{ | |
| 1693 | 1693 | .invalid, |
| 1694 | 1694 | }); |
| 1695 | testTokenize("//\xe2\x80\xaa", &.{}); | |
| 1695 | try testTokenize("//\xe2\x80\xaa", &.{}); | |
| 1696 | 1696 | } |
| 1697 | 1697 | |
| 1698 | 1698 | test "tokenizer - string identifier and builtin fns" { |
| 1699 | testTokenize( | |
| 1699 | try testTokenize( | |
| 1700 | 1700 | \\const @"if" = @import("std"); |
| 1701 | 1701 | , &.{ |
| 1702 | 1702 | .keyword_const, |
| ... | ... | @@ -1711,7 +1711,7 @@ test "tokenizer - string identifier and builtin fns" { |
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | test "tokenizer - multiline string literal with literal tab" { |
| 1714 | testTokenize( | |
| 1714 | try testTokenize( | |
| 1715 | 1715 | \\\\foo	bar |
| 1716 | 1716 | , &.{ |
| 1717 | 1717 | .multiline_string_literal_line, |
| ... | ... | @@ -1719,7 +1719,7 @@ test "tokenizer - multiline string literal with literal tab" { |
| 1719 | 1719 | } |
| 1720 | 1720 | |
| 1721 | 1721 | test "tokenizer - comments with literal tab" { |
| 1722 | testTokenize( | |
| 1722 | try testTokenize( | |
| 1723 | 1723 | \\//foo	bar |
| 1724 | 1724 | \\//!foo	bar |
| 1725 | 1725 | \\///foo	bar |
| ... | ... | @@ -1735,25 +1735,25 @@ test "tokenizer - comments with literal tab" { |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | 1737 | test "tokenizer - pipe and then invalid" { |
| 1738 | testTokenize("||=", &.{ | |
| 1738 | try testTokenize("||=", &.{ | |
| 1739 | 1739 | .pipe_pipe, |
| 1740 | 1740 | .equal, |
| 1741 | 1741 | }); |
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | 1744 | test "tokenizer - line comment and doc comment" { |
| 1745 | testTokenize("//", &.{}); | |
| 1746 | testTokenize("// a / b", &.{}); | |
| 1747 | testTokenize("// /", &.{}); | |
| 1748 | testTokenize("/// a", &.{.doc_comment}); | |
| 1749 | testTokenize("///", &.{.doc_comment}); | |
| 1750 | testTokenize("////", &.{}); | |
| 1751 | testTokenize("//!", &.{.container_doc_comment}); | |
| 1752 | testTokenize("//!!", &.{.container_doc_comment}); | |
| 1745 | try testTokenize("//", &.{}); | |
| 1746 | try testTokenize("// a / b", &.{}); | |
| 1747 | try testTokenize("// /", &.{}); | |
| 1748 | try testTokenize("/// a", &.{.doc_comment}); | |
| 1749 | try testTokenize("///", &.{.doc_comment}); | |
| 1750 | try testTokenize("////", &.{}); | |
| 1751 | try testTokenize("//!", &.{.container_doc_comment}); | |
| 1752 | try testTokenize("//!!", &.{.container_doc_comment}); | |
| 1753 | 1753 | } |
| 1754 | 1754 | |
| 1755 | 1755 | test "tokenizer - line comment followed by identifier" { |
| 1756 | testTokenize( | |
| 1756 | try testTokenize( | |
| 1757 | 1757 | \\ Unexpected, |
| 1758 | 1758 | \\ // another |
| 1759 | 1759 | \\ Another, |
| ... | ... | @@ -1766,14 +1766,14 @@ test "tokenizer - line comment followed by identifier" { |
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | test "tokenizer - UTF-8 BOM is recognized and skipped" { |
| 1769 | testTokenize("\xEF\xBB\xBFa;\n", &.{ | |
| 1769 | try testTokenize("\xEF\xBB\xBFa;\n", &.{ | |
| 1770 | 1770 | .identifier, |
| 1771 | 1771 | .semicolon, |
| 1772 | 1772 | }); |
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | 1775 | test "correctly parse pointer assignment" { |
| 1776 | testTokenize("b.*=3;\n", &.{ | |
| 1776 | try testTokenize("b.*=3;\n", &.{ | |
| 1777 | 1777 | .identifier, |
| 1778 | 1778 | .period_asterisk, |
| 1779 | 1779 | .equal, |
| ... | ... | @@ -1783,14 +1783,14 @@ test "correctly parse pointer assignment" { |
| 1783 | 1783 | } |
| 1784 | 1784 | |
| 1785 | 1785 | test "correctly parse pointer dereference followed by asterisk" { |
| 1786 | testTokenize("\"b\".* ** 10", &.{ | |
| 1786 | try testTokenize("\"b\".* ** 10", &.{ | |
| 1787 | 1787 | .string_literal, |
| 1788 | 1788 | .period_asterisk, |
| 1789 | 1789 | .asterisk_asterisk, |
| 1790 | 1790 | .integer_literal, |
| 1791 | 1791 | }); |
| 1792 | 1792 | |
| 1793 | testTokenize("(\"b\".*)** 10", &.{ | |
| 1793 | try testTokenize("(\"b\".*)** 10", &.{ | |
| 1794 | 1794 | .l_paren, |
| 1795 | 1795 | .string_literal, |
| 1796 | 1796 | .period_asterisk, |
| ... | ... | @@ -1799,7 +1799,7 @@ test "correctly parse pointer dereference followed by asterisk" { |
| 1799 | 1799 | .integer_literal, |
| 1800 | 1800 | }); |
| 1801 | 1801 | |
| 1802 | testTokenize("\"b\".*** 10", &.{ | |
| 1802 | try testTokenize("\"b\".*** 10", &.{ | |
| 1803 | 1803 | .string_literal, |
| 1804 | 1804 | .invalid_periodasterisks, |
| 1805 | 1805 | .asterisk_asterisk, |
| ... | ... | @@ -1808,245 +1808,245 @@ test "correctly parse pointer dereference followed by asterisk" { |
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | 1810 | test "tokenizer - range literals" { |
| 1811 | testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1812 | testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal }); | |
| 1813 | testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1814 | testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1815 | testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1811 | try testTokenize("0...9", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1812 | try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal }); | |
| 1813 | try testTokenize("0x00...0x09", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1814 | try testTokenize("0b00...0b11", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1815 | try testTokenize("0o00...0o11", &.{ .integer_literal, .ellipsis3, .integer_literal }); | |
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | 1818 | test "tokenizer - number literals decimal" { |
| 1819 | testTokenize("0", &.{.integer_literal}); | |
| 1820 | testTokenize("1", &.{.integer_literal}); | |
| 1821 | testTokenize("2", &.{.integer_literal}); | |
| 1822 | testTokenize("3", &.{.integer_literal}); | |
| 1823 | testTokenize("4", &.{.integer_literal}); | |
| 1824 | testTokenize("5", &.{.integer_literal}); | |
| 1825 | testTokenize("6", &.{.integer_literal}); | |
| 1826 | testTokenize("7", &.{.integer_literal}); | |
| 1827 | testTokenize("8", &.{.integer_literal}); | |
| 1828 | testTokenize("9", &.{.integer_literal}); | |
| 1829 | testTokenize("1..", &.{ .integer_literal, .ellipsis2 }); | |
| 1830 | testTokenize("0a", &.{ .invalid, .identifier }); | |
| 1831 | testTokenize("9b", &.{ .invalid, .identifier }); | |
| 1832 | testTokenize("1z", &.{ .invalid, .identifier }); | |
| 1833 | testTokenize("1z_1", &.{ .invalid, .identifier }); | |
| 1834 | testTokenize("9z3", &.{ .invalid, .identifier }); | |
| 1835 | ||
| 1836 | testTokenize("0_0", &.{.integer_literal}); | |
| 1837 | testTokenize("0001", &.{.integer_literal}); | |
| 1838 | testTokenize("01234567890", &.{.integer_literal}); | |
| 1839 | testTokenize("012_345_6789_0", &.{.integer_literal}); | |
| 1840 | testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal}); | |
| 1841 | ||
| 1842 | testTokenize("00_", &.{.invalid}); | |
| 1843 | testTokenize("0_0_", &.{.invalid}); | |
| 1844 | testTokenize("0__0", &.{ .invalid, .identifier }); | |
| 1845 | testTokenize("0_0f", &.{ .invalid, .identifier }); | |
| 1846 | testTokenize("0_0_f", &.{ .invalid, .identifier }); | |
| 1847 | testTokenize("0_0_f_00", &.{ .invalid, .identifier }); | |
| 1848 | testTokenize("1_,", &.{ .invalid, .comma }); | |
| 1849 | ||
| 1850 | testTokenize("1.", &.{.float_literal}); | |
| 1851 | testTokenize("0.0", &.{.float_literal}); | |
| 1852 | testTokenize("1.0", &.{.float_literal}); | |
| 1853 | testTokenize("10.0", &.{.float_literal}); | |
| 1854 | testTokenize("0e0", &.{.float_literal}); | |
| 1855 | testTokenize("1e0", &.{.float_literal}); | |
| 1856 | testTokenize("1e100", &.{.float_literal}); | |
| 1857 | testTokenize("1.e100", &.{.float_literal}); | |
| 1858 | testTokenize("1.0e100", &.{.float_literal}); | |
| 1859 | testTokenize("1.0e+100", &.{.float_literal}); | |
| 1860 | testTokenize("1.0e-100", &.{.float_literal}); | |
| 1861 | testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal}); | |
| 1862 | testTokenize("1.+", &.{ .float_literal, .plus }); | |
| 1863 | ||
| 1864 | testTokenize("1e", &.{.invalid}); | |
| 1865 | testTokenize("1.0e1f0", &.{ .invalid, .identifier }); | |
| 1866 | testTokenize("1.0p100", &.{ .invalid, .identifier }); | |
| 1867 | testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal }); | |
| 1868 | testTokenize("1.0p1f0", &.{ .invalid, .identifier }); | |
| 1869 | testTokenize("1.0_,", &.{ .invalid, .comma }); | |
| 1870 | testTokenize("1_.0", &.{ .invalid, .period, .integer_literal }); | |
| 1871 | testTokenize("1._", &.{ .invalid, .identifier }); | |
| 1872 | testTokenize("1.a", &.{ .invalid, .identifier }); | |
| 1873 | testTokenize("1.z", &.{ .invalid, .identifier }); | |
| 1874 | testTokenize("1._0", &.{ .invalid, .identifier }); | |
| 1875 | testTokenize("1._+", &.{ .invalid, .identifier, .plus }); | |
| 1876 | testTokenize("1._e", &.{ .invalid, .identifier }); | |
| 1877 | testTokenize("1.0e", &.{.invalid}); | |
| 1878 | testTokenize("1.0e,", &.{ .invalid, .comma }); | |
| 1879 | testTokenize("1.0e_", &.{ .invalid, .identifier }); | |
| 1880 | testTokenize("1.0e+_", &.{ .invalid, .identifier }); | |
| 1881 | testTokenize("1.0e-_", &.{ .invalid, .identifier }); | |
| 1882 | testTokenize("1.0e0_+", &.{ .invalid, .plus }); | |
| 1819 | try testTokenize("0", &.{.integer_literal}); | |
| 1820 | try testTokenize("1", &.{.integer_literal}); | |
| 1821 | try testTokenize("2", &.{.integer_literal}); | |
| 1822 | try testTokenize("3", &.{.integer_literal}); | |
| 1823 | try testTokenize("4", &.{.integer_literal}); | |
| 1824 | try testTokenize("5", &.{.integer_literal}); | |
| 1825 | try testTokenize("6", &.{.integer_literal}); | |
| 1826 | try testTokenize("7", &.{.integer_literal}); | |
| 1827 | try testTokenize("8", &.{.integer_literal}); | |
| 1828 | try testTokenize("9", &.{.integer_literal}); | |
| 1829 | try testTokenize("1..", &.{ .integer_literal, .ellipsis2 }); | |
| 1830 | try testTokenize("0a", &.{ .invalid, .identifier }); | |
| 1831 | try testTokenize("9b", &.{ .invalid, .identifier }); | |
| 1832 | try testTokenize("1z", &.{ .invalid, .identifier }); | |
| 1833 | try testTokenize("1z_1", &.{ .invalid, .identifier }); | |
| 1834 | try testTokenize("9z3", &.{ .invalid, .identifier }); | |
| 1835 | ||
| 1836 | try testTokenize("0_0", &.{.integer_literal}); | |
| 1837 | try testTokenize("0001", &.{.integer_literal}); | |
| 1838 | try testTokenize("01234567890", &.{.integer_literal}); | |
| 1839 | try testTokenize("012_345_6789_0", &.{.integer_literal}); | |
| 1840 | try testTokenize("0_1_2_3_4_5_6_7_8_9_0", &.{.integer_literal}); | |
| 1841 | ||
| 1842 | try testTokenize("00_", &.{.invalid}); | |
| 1843 | try testTokenize("0_0_", &.{.invalid}); | |
| 1844 | try testTokenize("0__0", &.{ .invalid, .identifier }); | |
| 1845 | try testTokenize("0_0f", &.{ .invalid, .identifier }); | |
| 1846 | try testTokenize("0_0_f", &.{ .invalid, .identifier }); | |
| 1847 | try testTokenize("0_0_f_00", &.{ .invalid, .identifier }); | |
| 1848 | try testTokenize("1_,", &.{ .invalid, .comma }); | |
| 1849 | ||
| 1850 | try testTokenize("1.", &.{.float_literal}); | |
| 1851 | try testTokenize("0.0", &.{.float_literal}); | |
| 1852 | try testTokenize("1.0", &.{.float_literal}); | |
| 1853 | try testTokenize("10.0", &.{.float_literal}); | |
| 1854 | try testTokenize("0e0", &.{.float_literal}); | |
| 1855 | try testTokenize("1e0", &.{.float_literal}); | |
| 1856 | try testTokenize("1e100", &.{.float_literal}); | |
| 1857 | try testTokenize("1.e100", &.{.float_literal}); | |
| 1858 | try testTokenize("1.0e100", &.{.float_literal}); | |
| 1859 | try testTokenize("1.0e+100", &.{.float_literal}); | |
| 1860 | try testTokenize("1.0e-100", &.{.float_literal}); | |
| 1861 | try testTokenize("1_0_0_0.0_0_0_0_0_1e1_0_0_0", &.{.float_literal}); | |
| 1862 | try testTokenize("1.+", &.{ .float_literal, .plus }); | |
| 1863 | ||
| 1864 | try testTokenize("1e", &.{.invalid}); | |
| 1865 | try testTokenize("1.0e1f0", &.{ .invalid, .identifier }); | |
| 1866 | try testTokenize("1.0p100", &.{ .invalid, .identifier }); | |
| 1867 | try testTokenize("1.0p-100", &.{ .invalid, .identifier, .minus, .integer_literal }); | |
| 1868 | try testTokenize("1.0p1f0", &.{ .invalid, .identifier }); | |
| 1869 | try testTokenize("1.0_,", &.{ .invalid, .comma }); | |
| 1870 | try testTokenize("1_.0", &.{ .invalid, .period, .integer_literal }); | |
| 1871 | try testTokenize("1._", &.{ .invalid, .identifier }); | |
| 1872 | try testTokenize("1.a", &.{ .invalid, .identifier }); | |
| 1873 | try testTokenize("1.z", &.{ .invalid, .identifier }); | |
| 1874 | try testTokenize("1._0", &.{ .invalid, .identifier }); | |
| 1875 | try testTokenize("1._+", &.{ .invalid, .identifier, .plus }); | |
| 1876 | try testTokenize("1._e", &.{ .invalid, .identifier }); | |
| 1877 | try testTokenize("1.0e", &.{.invalid}); | |
| 1878 | try testTokenize("1.0e,", &.{ .invalid, .comma }); | |
| 1879 | try testTokenize("1.0e_", &.{ .invalid, .identifier }); | |
| 1880 | try testTokenize("1.0e+_", &.{ .invalid, .identifier }); | |
| 1881 | try testTokenize("1.0e-_", &.{ .invalid, .identifier }); | |
| 1882 | try testTokenize("1.0e0_+", &.{ .invalid, .plus }); | |
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | test "tokenizer - number literals binary" { |
| 1886 | testTokenize("0b0", &.{.integer_literal}); | |
| 1887 | testTokenize("0b1", &.{.integer_literal}); | |
| 1888 | testTokenize("0b2", &.{ .invalid, .integer_literal }); | |
| 1889 | testTokenize("0b3", &.{ .invalid, .integer_literal }); | |
| 1890 | testTokenize("0b4", &.{ .invalid, .integer_literal }); | |
| 1891 | testTokenize("0b5", &.{ .invalid, .integer_literal }); | |
| 1892 | testTokenize("0b6", &.{ .invalid, .integer_literal }); | |
| 1893 | testTokenize("0b7", &.{ .invalid, .integer_literal }); | |
| 1894 | testTokenize("0b8", &.{ .invalid, .integer_literal }); | |
| 1895 | testTokenize("0b9", &.{ .invalid, .integer_literal }); | |
| 1896 | testTokenize("0ba", &.{ .invalid, .identifier }); | |
| 1897 | testTokenize("0bb", &.{ .invalid, .identifier }); | |
| 1898 | testTokenize("0bc", &.{ .invalid, .identifier }); | |
| 1899 | testTokenize("0bd", &.{ .invalid, .identifier }); | |
| 1900 | testTokenize("0be", &.{ .invalid, .identifier }); | |
| 1901 | testTokenize("0bf", &.{ .invalid, .identifier }); | |
| 1902 | testTokenize("0bz", &.{ .invalid, .identifier }); | |
| 1903 | ||
| 1904 | testTokenize("0b0000_0000", &.{.integer_literal}); | |
| 1905 | testTokenize("0b1111_1111", &.{.integer_literal}); | |
| 1906 | testTokenize("0b10_10_10_10", &.{.integer_literal}); | |
| 1907 | testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal}); | |
| 1908 | testTokenize("0b1.", &.{ .integer_literal, .period }); | |
| 1909 | testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal }); | |
| 1910 | ||
| 1911 | testTokenize("0B0", &.{ .invalid, .identifier }); | |
| 1912 | testTokenize("0b_", &.{ .invalid, .identifier }); | |
| 1913 | testTokenize("0b_0", &.{ .invalid, .identifier }); | |
| 1914 | testTokenize("0b1_", &.{.invalid}); | |
| 1915 | testTokenize("0b0__1", &.{ .invalid, .identifier }); | |
| 1916 | testTokenize("0b0_1_", &.{.invalid}); | |
| 1917 | testTokenize("0b1e", &.{ .invalid, .identifier }); | |
| 1918 | testTokenize("0b1p", &.{ .invalid, .identifier }); | |
| 1919 | testTokenize("0b1e0", &.{ .invalid, .identifier }); | |
| 1920 | testTokenize("0b1p0", &.{ .invalid, .identifier }); | |
| 1921 | testTokenize("0b1_,", &.{ .invalid, .comma }); | |
| 1886 | try testTokenize("0b0", &.{.integer_literal}); | |
| 1887 | try testTokenize("0b1", &.{.integer_literal}); | |
| 1888 | try testTokenize("0b2", &.{ .invalid, .integer_literal }); | |
| 1889 | try testTokenize("0b3", &.{ .invalid, .integer_literal }); | |
| 1890 | try testTokenize("0b4", &.{ .invalid, .integer_literal }); | |
| 1891 | try testTokenize("0b5", &.{ .invalid, .integer_literal }); | |
| 1892 | try testTokenize("0b6", &.{ .invalid, .integer_literal }); | |
| 1893 | try testTokenize("0b7", &.{ .invalid, .integer_literal }); | |
| 1894 | try testTokenize("0b8", &.{ .invalid, .integer_literal }); | |
| 1895 | try testTokenize("0b9", &.{ .invalid, .integer_literal }); | |
| 1896 | try testTokenize("0ba", &.{ .invalid, .identifier }); | |
| 1897 | try testTokenize("0bb", &.{ .invalid, .identifier }); | |
| 1898 | try testTokenize("0bc", &.{ .invalid, .identifier }); | |
| 1899 | try testTokenize("0bd", &.{ .invalid, .identifier }); | |
| 1900 | try testTokenize("0be", &.{ .invalid, .identifier }); | |
| 1901 | try testTokenize("0bf", &.{ .invalid, .identifier }); | |
| 1902 | try testTokenize("0bz", &.{ .invalid, .identifier }); | |
| 1903 | ||
| 1904 | try testTokenize("0b0000_0000", &.{.integer_literal}); | |
| 1905 | try testTokenize("0b1111_1111", &.{.integer_literal}); | |
| 1906 | try testTokenize("0b10_10_10_10", &.{.integer_literal}); | |
| 1907 | try testTokenize("0b0_1_0_1_0_1_0_1", &.{.integer_literal}); | |
| 1908 | try testTokenize("0b1.", &.{ .integer_literal, .period }); | |
| 1909 | try testTokenize("0b1.0", &.{ .integer_literal, .period, .integer_literal }); | |
| 1910 | ||
| 1911 | try testTokenize("0B0", &.{ .invalid, .identifier }); | |
| 1912 | try testTokenize("0b_", &.{ .invalid, .identifier }); | |
| 1913 | try testTokenize("0b_0", &.{ .invalid, .identifier }); | |
| 1914 | try testTokenize("0b1_", &.{.invalid}); | |
| 1915 | try testTokenize("0b0__1", &.{ .invalid, .identifier }); | |
| 1916 | try testTokenize("0b0_1_", &.{.invalid}); | |
| 1917 | try testTokenize("0b1e", &.{ .invalid, .identifier }); | |
| 1918 | try testTokenize("0b1p", &.{ .invalid, .identifier }); | |
| 1919 | try testTokenize("0b1e0", &.{ .invalid, .identifier }); | |
| 1920 | try testTokenize("0b1p0", &.{ .invalid, .identifier }); | |
| 1921 | try testTokenize("0b1_,", &.{ .invalid, .comma }); | |
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | 1924 | test "tokenizer - number literals octal" { |
| 1925 | testTokenize("0o0", &.{.integer_literal}); | |
| 1926 | testTokenize("0o1", &.{.integer_literal}); | |
| 1927 | testTokenize("0o2", &.{.integer_literal}); | |
| 1928 | testTokenize("0o3", &.{.integer_literal}); | |
| 1929 | testTokenize("0o4", &.{.integer_literal}); | |
| 1930 | testTokenize("0o5", &.{.integer_literal}); | |
| 1931 | testTokenize("0o6", &.{.integer_literal}); | |
| 1932 | testTokenize("0o7", &.{.integer_literal}); | |
| 1933 | testTokenize("0o8", &.{ .invalid, .integer_literal }); | |
| 1934 | testTokenize("0o9", &.{ .invalid, .integer_literal }); | |
| 1935 | testTokenize("0oa", &.{ .invalid, .identifier }); | |
| 1936 | testTokenize("0ob", &.{ .invalid, .identifier }); | |
| 1937 | testTokenize("0oc", &.{ .invalid, .identifier }); | |
| 1938 | testTokenize("0od", &.{ .invalid, .identifier }); | |
| 1939 | testTokenize("0oe", &.{ .invalid, .identifier }); | |
| 1940 | testTokenize("0of", &.{ .invalid, .identifier }); | |
| 1941 | testTokenize("0oz", &.{ .invalid, .identifier }); | |
| 1942 | ||
| 1943 | testTokenize("0o01234567", &.{.integer_literal}); | |
| 1944 | testTokenize("0o0123_4567", &.{.integer_literal}); | |
| 1945 | testTokenize("0o01_23_45_67", &.{.integer_literal}); | |
| 1946 | testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal}); | |
| 1947 | testTokenize("0o7.", &.{ .integer_literal, .period }); | |
| 1948 | testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal }); | |
| 1949 | ||
| 1950 | testTokenize("0O0", &.{ .invalid, .identifier }); | |
| 1951 | testTokenize("0o_", &.{ .invalid, .identifier }); | |
| 1952 | testTokenize("0o_0", &.{ .invalid, .identifier }); | |
| 1953 | testTokenize("0o1_", &.{.invalid}); | |
| 1954 | testTokenize("0o0__1", &.{ .invalid, .identifier }); | |
| 1955 | testTokenize("0o0_1_", &.{.invalid}); | |
| 1956 | testTokenize("0o1e", &.{ .invalid, .identifier }); | |
| 1957 | testTokenize("0o1p", &.{ .invalid, .identifier }); | |
| 1958 | testTokenize("0o1e0", &.{ .invalid, .identifier }); | |
| 1959 | testTokenize("0o1p0", &.{ .invalid, .identifier }); | |
| 1960 | testTokenize("0o_,", &.{ .invalid, .identifier, .comma }); | |
| 1925 | try testTokenize("0o0", &.{.integer_literal}); | |
| 1926 | try testTokenize("0o1", &.{.integer_literal}); | |
| 1927 | try testTokenize("0o2", &.{.integer_literal}); | |
| 1928 | try testTokenize("0o3", &.{.integer_literal}); | |
| 1929 | try testTokenize("0o4", &.{.integer_literal}); | |
| 1930 | try testTokenize("0o5", &.{.integer_literal}); | |
| 1931 | try testTokenize("0o6", &.{.integer_literal}); | |
| 1932 | try testTokenize("0o7", &.{.integer_literal}); | |
| 1933 | try testTokenize("0o8", &.{ .invalid, .integer_literal }); | |
| 1934 | try testTokenize("0o9", &.{ .invalid, .integer_literal }); | |
| 1935 | try testTokenize("0oa", &.{ .invalid, .identifier }); | |
| 1936 | try testTokenize("0ob", &.{ .invalid, .identifier }); | |
| 1937 | try testTokenize("0oc", &.{ .invalid, .identifier }); | |
| 1938 | try testTokenize("0od", &.{ .invalid, .identifier }); | |
| 1939 | try testTokenize("0oe", &.{ .invalid, .identifier }); | |
| 1940 | try testTokenize("0of", &.{ .invalid, .identifier }); | |
| 1941 | try testTokenize("0oz", &.{ .invalid, .identifier }); | |
| 1942 | ||
| 1943 | try testTokenize("0o01234567", &.{.integer_literal}); | |
| 1944 | try testTokenize("0o0123_4567", &.{.integer_literal}); | |
| 1945 | try testTokenize("0o01_23_45_67", &.{.integer_literal}); | |
| 1946 | try testTokenize("0o0_1_2_3_4_5_6_7", &.{.integer_literal}); | |
| 1947 | try testTokenize("0o7.", &.{ .integer_literal, .period }); | |
| 1948 | try testTokenize("0o7.0", &.{ .integer_literal, .period, .integer_literal }); | |
| 1949 | ||
| 1950 | try testTokenize("0O0", &.{ .invalid, .identifier }); | |
| 1951 | try testTokenize("0o_", &.{ .invalid, .identifier }); | |
| 1952 | try testTokenize("0o_0", &.{ .invalid, .identifier }); | |
| 1953 | try testTokenize("0o1_", &.{.invalid}); | |
| 1954 | try testTokenize("0o0__1", &.{ .invalid, .identifier }); | |
| 1955 | try testTokenize("0o0_1_", &.{.invalid}); | |
| 1956 | try testTokenize("0o1e", &.{ .invalid, .identifier }); | |
| 1957 | try testTokenize("0o1p", &.{ .invalid, .identifier }); | |
| 1958 | try testTokenize("0o1e0", &.{ .invalid, .identifier }); | |
| 1959 | try testTokenize("0o1p0", &.{ .invalid, .identifier }); | |
| 1960 | try testTokenize("0o_,", &.{ .invalid, .identifier, .comma }); | |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | 1963 | test "tokenizer - number literals hexadeciaml" { |
| 1964 | testTokenize("0x0", &.{.integer_literal}); | |
| 1965 | testTokenize("0x1", &.{.integer_literal}); | |
| 1966 | testTokenize("0x2", &.{.integer_literal}); | |
| 1967 | testTokenize("0x3", &.{.integer_literal}); | |
| 1968 | testTokenize("0x4", &.{.integer_literal}); | |
| 1969 | testTokenize("0x5", &.{.integer_literal}); | |
| 1970 | testTokenize("0x6", &.{.integer_literal}); | |
| 1971 | testTokenize("0x7", &.{.integer_literal}); | |
| 1972 | testTokenize("0x8", &.{.integer_literal}); | |
| 1973 | testTokenize("0x9", &.{.integer_literal}); | |
| 1974 | testTokenize("0xa", &.{.integer_literal}); | |
| 1975 | testTokenize("0xb", &.{.integer_literal}); | |
| 1976 | testTokenize("0xc", &.{.integer_literal}); | |
| 1977 | testTokenize("0xd", &.{.integer_literal}); | |
| 1978 | testTokenize("0xe", &.{.integer_literal}); | |
| 1979 | testTokenize("0xf", &.{.integer_literal}); | |
| 1980 | testTokenize("0xA", &.{.integer_literal}); | |
| 1981 | testTokenize("0xB", &.{.integer_literal}); | |
| 1982 | testTokenize("0xC", &.{.integer_literal}); | |
| 1983 | testTokenize("0xD", &.{.integer_literal}); | |
| 1984 | testTokenize("0xE", &.{.integer_literal}); | |
| 1985 | testTokenize("0xF", &.{.integer_literal}); | |
| 1986 | testTokenize("0x0z", &.{ .invalid, .identifier }); | |
| 1987 | testTokenize("0xz", &.{ .invalid, .identifier }); | |
| 1988 | ||
| 1989 | testTokenize("0x0123456789ABCDEF", &.{.integer_literal}); | |
| 1990 | testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal}); | |
| 1991 | testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal}); | |
| 1992 | testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal}); | |
| 1993 | ||
| 1994 | testTokenize("0X0", &.{ .invalid, .identifier }); | |
| 1995 | testTokenize("0x_", &.{ .invalid, .identifier }); | |
| 1996 | testTokenize("0x_1", &.{ .invalid, .identifier }); | |
| 1997 | testTokenize("0x1_", &.{.invalid}); | |
| 1998 | testTokenize("0x0__1", &.{ .invalid, .identifier }); | |
| 1999 | testTokenize("0x0_1_", &.{.invalid}); | |
| 2000 | testTokenize("0x_,", &.{ .invalid, .identifier, .comma }); | |
| 2001 | ||
| 2002 | testTokenize("0x1.", &.{.float_literal}); | |
| 2003 | testTokenize("0x1.0", &.{.float_literal}); | |
| 2004 | testTokenize("0xF.", &.{.float_literal}); | |
| 2005 | testTokenize("0xF.0", &.{.float_literal}); | |
| 2006 | testTokenize("0xF.F", &.{.float_literal}); | |
| 2007 | testTokenize("0xF.Fp0", &.{.float_literal}); | |
| 2008 | testTokenize("0xF.FP0", &.{.float_literal}); | |
| 2009 | testTokenize("0x1p0", &.{.float_literal}); | |
| 2010 | testTokenize("0xfp0", &.{.float_literal}); | |
| 2011 | testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal }); | |
| 2012 | ||
| 2013 | testTokenize("0x0123456.789ABCDEF", &.{.float_literal}); | |
| 2014 | testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal}); | |
| 2015 | testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal}); | |
| 2016 | testTokenize("0x0p0", &.{.float_literal}); | |
| 2017 | testTokenize("0x0.0p0", &.{.float_literal}); | |
| 2018 | testTokenize("0xff.ffp10", &.{.float_literal}); | |
| 2019 | testTokenize("0xff.ffP10", &.{.float_literal}); | |
| 2020 | testTokenize("0xff.p10", &.{.float_literal}); | |
| 2021 | testTokenize("0xffp10", &.{.float_literal}); | |
| 2022 | testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal}); | |
| 2023 | testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal}); | |
| 2024 | testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal}); | |
| 2025 | ||
| 2026 | testTokenize("0x1e", &.{.integer_literal}); | |
| 2027 | testTokenize("0x1e0", &.{.integer_literal}); | |
| 2028 | testTokenize("0x1p", &.{.invalid}); | |
| 2029 | testTokenize("0xfp0z1", &.{ .invalid, .identifier }); | |
| 2030 | testTokenize("0xff.ffpff", &.{ .invalid, .identifier }); | |
| 2031 | testTokenize("0x0.p", &.{.invalid}); | |
| 2032 | testTokenize("0x0.z", &.{ .invalid, .identifier }); | |
| 2033 | testTokenize("0x0._", &.{ .invalid, .identifier }); | |
| 2034 | testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal }); | |
| 2035 | testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal }); | |
| 2036 | testTokenize("0x0._0", &.{ .invalid, .identifier }); | |
| 2037 | testTokenize("0x0.0_", &.{.invalid}); | |
| 2038 | testTokenize("0x0_p0", &.{ .invalid, .identifier }); | |
| 2039 | testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier }); | |
| 2040 | testTokenize("0x0._p0", &.{ .invalid, .identifier }); | |
| 2041 | testTokenize("0x0.0_p0", &.{ .invalid, .identifier }); | |
| 2042 | testTokenize("0x0._0p0", &.{ .invalid, .identifier }); | |
| 2043 | testTokenize("0x0.0p_0", &.{ .invalid, .identifier }); | |
| 2044 | testTokenize("0x0.0p+_0", &.{ .invalid, .identifier }); | |
| 2045 | testTokenize("0x0.0p-_0", &.{ .invalid, .identifier }); | |
| 2046 | testTokenize("0x0.0p0_", &.{ .invalid, .eof }); | |
| 1964 | try testTokenize("0x0", &.{.integer_literal}); | |
| 1965 | try testTokenize("0x1", &.{.integer_literal}); | |
| 1966 | try testTokenize("0x2", &.{.integer_literal}); | |
| 1967 | try testTokenize("0x3", &.{.integer_literal}); | |
| 1968 | try testTokenize("0x4", &.{.integer_literal}); | |
| 1969 | try testTokenize("0x5", &.{.integer_literal}); | |
| 1970 | try testTokenize("0x6", &.{.integer_literal}); | |
| 1971 | try testTokenize("0x7", &.{.integer_literal}); | |
| 1972 | try testTokenize("0x8", &.{.integer_literal}); | |
| 1973 | try testTokenize("0x9", &.{.integer_literal}); | |
| 1974 | try testTokenize("0xa", &.{.integer_literal}); | |
| 1975 | try testTokenize("0xb", &.{.integer_literal}); | |
| 1976 | try testTokenize("0xc", &.{.integer_literal}); | |
| 1977 | try testTokenize("0xd", &.{.integer_literal}); | |
| 1978 | try testTokenize("0xe", &.{.integer_literal}); | |
| 1979 | try testTokenize("0xf", &.{.integer_literal}); | |
| 1980 | try testTokenize("0xA", &.{.integer_literal}); | |
| 1981 | try testTokenize("0xB", &.{.integer_literal}); | |
| 1982 | try testTokenize("0xC", &.{.integer_literal}); | |
| 1983 | try testTokenize("0xD", &.{.integer_literal}); | |
| 1984 | try testTokenize("0xE", &.{.integer_literal}); | |
| 1985 | try testTokenize("0xF", &.{.integer_literal}); | |
| 1986 | try testTokenize("0x0z", &.{ .invalid, .identifier }); | |
| 1987 | try testTokenize("0xz", &.{ .invalid, .identifier }); | |
| 1988 | ||
| 1989 | try testTokenize("0x0123456789ABCDEF", &.{.integer_literal}); | |
| 1990 | try testTokenize("0x0123_4567_89AB_CDEF", &.{.integer_literal}); | |
| 1991 | try testTokenize("0x01_23_45_67_89AB_CDE_F", &.{.integer_literal}); | |
| 1992 | try testTokenize("0x0_1_2_3_4_5_6_7_8_9_A_B_C_D_E_F", &.{.integer_literal}); | |
| 1993 | ||
| 1994 | try testTokenize("0X0", &.{ .invalid, .identifier }); | |
| 1995 | try testTokenize("0x_", &.{ .invalid, .identifier }); | |
| 1996 | try testTokenize("0x_1", &.{ .invalid, .identifier }); | |
| 1997 | try testTokenize("0x1_", &.{.invalid}); | |
| 1998 | try testTokenize("0x0__1", &.{ .invalid, .identifier }); | |
| 1999 | try testTokenize("0x0_1_", &.{.invalid}); | |
| 2000 | try testTokenize("0x_,", &.{ .invalid, .identifier, .comma }); | |
| 2001 | ||
| 2002 | try testTokenize("0x1.", &.{.float_literal}); | |
| 2003 | try testTokenize("0x1.0", &.{.float_literal}); | |
| 2004 | try testTokenize("0xF.", &.{.float_literal}); | |
| 2005 | try testTokenize("0xF.0", &.{.float_literal}); | |
| 2006 | try testTokenize("0xF.F", &.{.float_literal}); | |
| 2007 | try testTokenize("0xF.Fp0", &.{.float_literal}); | |
| 2008 | try testTokenize("0xF.FP0", &.{.float_literal}); | |
| 2009 | try testTokenize("0x1p0", &.{.float_literal}); | |
| 2010 | try testTokenize("0xfp0", &.{.float_literal}); | |
| 2011 | try testTokenize("0x1.+0xF.", &.{ .float_literal, .plus, .float_literal }); | |
| 2012 | ||
| 2013 | try testTokenize("0x0123456.789ABCDEF", &.{.float_literal}); | |
| 2014 | try testTokenize("0x0_123_456.789_ABC_DEF", &.{.float_literal}); | |
| 2015 | try testTokenize("0x0_1_2_3_4_5_6.7_8_9_A_B_C_D_E_F", &.{.float_literal}); | |
| 2016 | try testTokenize("0x0p0", &.{.float_literal}); | |
| 2017 | try testTokenize("0x0.0p0", &.{.float_literal}); | |
| 2018 | try testTokenize("0xff.ffp10", &.{.float_literal}); | |
| 2019 | try testTokenize("0xff.ffP10", &.{.float_literal}); | |
| 2020 | try testTokenize("0xff.p10", &.{.float_literal}); | |
| 2021 | try testTokenize("0xffp10", &.{.float_literal}); | |
| 2022 | try testTokenize("0xff_ff.ff_ffp1_0_0_0", &.{.float_literal}); | |
| 2023 | try testTokenize("0xf_f_f_f.f_f_f_fp+1_000", &.{.float_literal}); | |
| 2024 | try testTokenize("0xf_f_f_f.f_f_f_fp-1_00_0", &.{.float_literal}); | |
| 2025 | ||
| 2026 | try testTokenize("0x1e", &.{.integer_literal}); | |
| 2027 | try testTokenize("0x1e0", &.{.integer_literal}); | |
| 2028 | try testTokenize("0x1p", &.{.invalid}); | |
| 2029 | try testTokenize("0xfp0z1", &.{ .invalid, .identifier }); | |
| 2030 | try testTokenize("0xff.ffpff", &.{ .invalid, .identifier }); | |
| 2031 | try testTokenize("0x0.p", &.{.invalid}); | |
| 2032 | try testTokenize("0x0.z", &.{ .invalid, .identifier }); | |
| 2033 | try testTokenize("0x0._", &.{ .invalid, .identifier }); | |
| 2034 | try testTokenize("0x0_.0", &.{ .invalid, .period, .integer_literal }); | |
| 2035 | try testTokenize("0x0_.0.0", &.{ .invalid, .period, .float_literal }); | |
| 2036 | try testTokenize("0x0._0", &.{ .invalid, .identifier }); | |
| 2037 | try testTokenize("0x0.0_", &.{.invalid}); | |
| 2038 | try testTokenize("0x0_p0", &.{ .invalid, .identifier }); | |
| 2039 | try testTokenize("0x0_.p0", &.{ .invalid, .period, .identifier }); | |
| 2040 | try testTokenize("0x0._p0", &.{ .invalid, .identifier }); | |
| 2041 | try testTokenize("0x0.0_p0", &.{ .invalid, .identifier }); | |
| 2042 | try testTokenize("0x0._0p0", &.{ .invalid, .identifier }); | |
| 2043 | try testTokenize("0x0.0p_0", &.{ .invalid, .identifier }); | |
| 2044 | try testTokenize("0x0.0p+_0", &.{ .invalid, .identifier }); | |
| 2045 | try testTokenize("0x0.0p-_0", &.{ .invalid, .identifier }); | |
| 2046 | try testTokenize("0x0.0p0_", &.{ .invalid, .eof }); | |
| 2047 | 2047 | } |
| 2048 | 2048 | |
| 2049 | fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void { | |
| 2049 | fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) !void { | |
| 2050 | 2050 | var tokenizer = Tokenizer.init(source); |
| 2051 | 2051 | for (expected_tokens) |expected_token_id| { |
| 2052 | 2052 | const token = tokenizer.next(); |
| ... | ... | @@ -2055,6 +2055,6 @@ fn testTokenize(source: []const u8, expected_tokens: []const Token.Tag) void { |
| 2055 | 2055 | } |
| 2056 | 2056 | } |
| 2057 | 2057 | const last_token = tokenizer.next(); |
| 2058 | std.testing.expect(last_token.tag == .eof); | |
| 2059 | std.testing.expect(last_token.loc.start == source.len); | |
| 2058 | try std.testing.expect(last_token.tag == .eof); | |
| 2059 | try std.testing.expect(last_token.loc.start == source.len); | |
| 2060 | 2060 | } |
src/Cache.zig+18-18| ... | ... | @@ -727,7 +727,7 @@ test "cache file and then recall it" { |
| 727 | 727 | _ = try ch.addFile(temp_file, null); |
| 728 | 728 | |
| 729 | 729 | // There should be nothing in the cache |
| 730 | testing.expectEqual(false, try ch.hit()); | |
| 730 | try testing.expectEqual(false, try ch.hit()); | |
| 731 | 731 | |
| 732 | 732 | digest1 = ch.final(); |
| 733 | 733 | try ch.writeManifest(); |
| ... | ... | @@ -742,13 +742,13 @@ test "cache file and then recall it" { |
| 742 | 742 | _ = try ch.addFile(temp_file, null); |
| 743 | 743 | |
| 744 | 744 | // Cache hit! We just "built" the same file |
| 745 | testing.expect(try ch.hit()); | |
| 745 | try testing.expect(try ch.hit()); | |
| 746 | 746 | digest2 = ch.final(); |
| 747 | 747 | |
| 748 | 748 | try ch.writeManifest(); |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | testing.expectEqual(digest1, digest2); | |
| 751 | try testing.expectEqual(digest1, digest2); | |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | try cwd.deleteTree(temp_manifest_dir); |
| ... | ... | @@ -760,11 +760,11 @@ test "give problematic timestamp" { |
| 760 | 760 | // to make it problematic, we make it only accurate to the second |
| 761 | 761 | fs_clock = @divTrunc(fs_clock, std.time.ns_per_s); |
| 762 | 762 | fs_clock *= std.time.ns_per_s; |
| 763 | testing.expect(isProblematicTimestamp(fs_clock)); | |
| 763 | try testing.expect(isProblematicTimestamp(fs_clock)); | |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | test "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 | } |
| 769 | 769 | |
| 770 | 770 | test "check that changing a file makes cache fail" { |
| ... | ... | @@ -807,9 +807,9 @@ test "check that changing a file makes cache fail" { |
| 807 | 807 | const temp_file_idx = try ch.addFile(temp_file, 100); |
| 808 | 808 | |
| 809 | 809 | // There should be nothing in the cache |
| 810 | testing.expectEqual(false, try ch.hit()); | |
| 810 | try testing.expectEqual(false, try ch.hit()); | |
| 811 | 811 | |
| 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.?)); | |
| 813 | 813 | |
| 814 | 814 | digest1 = ch.final(); |
| 815 | 815 | |
| ... | ... | @@ -826,17 +826,17 @@ test "check that changing a file makes cache fail" { |
| 826 | 826 | const temp_file_idx = try ch.addFile(temp_file, 100); |
| 827 | 827 | |
| 828 | 828 | // 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()); | |
| 830 | 830 | |
| 831 | 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); | |
| 833 | 833 | |
| 834 | 834 | digest2 = ch.final(); |
| 835 | 835 | |
| 836 | 836 | try ch.writeManifest(); |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | testing.expect(!mem.eql(u8, digest1[0..], digest2[0..])); | |
| 839 | try testing.expect(!mem.eql(u8, digest1[0..], digest2[0..])); | |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | try cwd.deleteTree(temp_manifest_dir); |
| ... | ... | @@ -868,7 +868,7 @@ test "no file inputs" { |
| 868 | 868 | ch.hash.addBytes("1234"); |
| 869 | 869 | |
| 870 | 870 | // There should be nothing in the cache |
| 871 | testing.expectEqual(false, try ch.hit()); | |
| 871 | try testing.expectEqual(false, try ch.hit()); | |
| 872 | 872 | |
| 873 | 873 | digest1 = ch.final(); |
| 874 | 874 | |
| ... | ... | @@ -880,12 +880,12 @@ test "no file inputs" { |
| 880 | 880 | |
| 881 | 881 | ch.hash.addBytes("1234"); |
| 882 | 882 | |
| 883 | testing.expect(try ch.hit()); | |
| 883 | try testing.expect(try ch.hit()); | |
| 884 | 884 | digest2 = ch.final(); |
| 885 | 885 | try ch.writeManifest(); |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | testing.expectEqual(digest1, digest2); | |
| 888 | try testing.expectEqual(digest1, digest2); | |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | test "Manifest with files added after initial hash work" { |
| ... | ... | @@ -926,7 +926,7 @@ test "Manifest with files added after initial hash work" { |
| 926 | 926 | _ = try ch.addFile(temp_file1, null); |
| 927 | 927 | |
| 928 | 928 | // There should be nothing in the cache |
| 929 | testing.expectEqual(false, try ch.hit()); | |
| 929 | try testing.expectEqual(false, try ch.hit()); | |
| 930 | 930 | |
| 931 | 931 | _ = try ch.addFilePost(temp_file2); |
| 932 | 932 | |
| ... | ... | @@ -940,12 +940,12 @@ test "Manifest with files added after initial hash work" { |
| 940 | 940 | ch.hash.addBytes("1234"); |
| 941 | 941 | _ = try ch.addFile(temp_file1, null); |
| 942 | 942 | |
| 943 | testing.expect(try ch.hit()); | |
| 943 | try testing.expect(try ch.hit()); | |
| 944 | 944 | digest2 = ch.final(); |
| 945 | 945 | |
| 946 | 946 | try ch.writeManifest(); |
| 947 | 947 | } |
| 948 | testing.expect(mem.eql(u8, &digest1, &digest2)); | |
| 948 | try testing.expect(mem.eql(u8, &digest1, &digest2)); | |
| 949 | 949 | |
| 950 | 950 | // Modify the file added after initial hash |
| 951 | 951 | const ts2 = std.time.nanoTimestamp(); |
| ... | ... | @@ -963,7 +963,7 @@ test "Manifest with files added after initial hash work" { |
| 963 | 963 | _ = try ch.addFile(temp_file1, null); |
| 964 | 964 | |
| 965 | 965 | // 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()); | |
| 967 | 967 | |
| 968 | 968 | _ = try ch.addFilePost(temp_file2); |
| 969 | 969 | |
| ... | ... | @@ -972,7 +972,7 @@ test "Manifest with files added after initial hash work" { |
| 972 | 972 | try ch.writeManifest(); |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | testing.expect(!mem.eql(u8, &digest1, &digest3)); | |
| 975 | try testing.expect(!mem.eql(u8, &digest1, &digest3)); | |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | try cwd.deleteTree(temp_manifest_dir); |
src/Compilation.zig+8-8| ... | ... | @@ -2852,14 +2852,14 @@ pub fn classifyFileExt(filename: []const u8) FileExt { |
| 2852 | 2852 | } |
| 2853 | 2853 | |
| 2854 | 2854 | test "classifyFileExt" { |
| 2855 | std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc")); | |
| 2856 | std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim")); | |
| 2857 | std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so")); | |
| 2858 | std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1")); | |
| 2859 | std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2")); | |
| 2860 | std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3")); | |
| 2861 | std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~")); | |
| 2862 | std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig")); | |
| 2855 | try std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc")); | |
| 2856 | try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim")); | |
| 2857 | try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so")); | |
| 2858 | try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1")); | |
| 2859 | try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2")); | |
| 2860 | try std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3")); | |
| 2861 | try std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~")); | |
| 2862 | try std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig")); | |
| 2863 | 2863 | } |
| 2864 | 2864 | |
| 2865 | 2865 | fn haveFramePointer(comp: *const Compilation) bool { |
src/DepTokenizer.zig+2-2| ... | ... | @@ -918,7 +918,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { |
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | if (std.mem.eql(u8, expect, buffer.items)) { |
| 921 | testing.expect(true); | |
| 921 | try testing.expect(true); | |
| 922 | 922 | return; |
| 923 | 923 | } |
| 924 | 924 | |
| ... | ... | @@ -930,7 +930,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { |
| 930 | 930 | try printSection(out, ">>>> got", buffer.items); |
| 931 | 931 | try printRuler(out); |
| 932 | 932 | |
| 933 | testing.expect(false); | |
| 933 | try testing.expect(false); | |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | fn 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 | 67 | pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 }; |
| 68 | 68 | |
| 69 | 69 | test "Register.id" { |
| 70 | testing.expectEqual(@as(u5, 0), Register.x0.id()); | |
| 71 | testing.expectEqual(@as(u5, 0), Register.w0.id()); | |
| 70 | try testing.expectEqual(@as(u5, 0), Register.x0.id()); | |
| 71 | try testing.expectEqual(@as(u5, 0), Register.w0.id()); | |
| 72 | 72 | |
| 73 | testing.expectEqual(@as(u5, 31), Register.xzr.id()); | |
| 74 | testing.expectEqual(@as(u5, 31), Register.wzr.id()); | |
| 73 | try testing.expectEqual(@as(u5, 31), Register.xzr.id()); | |
| 74 | try testing.expectEqual(@as(u5, 31), Register.wzr.id()); | |
| 75 | 75 | |
| 76 | testing.expectEqual(@as(u5, 31), Register.sp.id()); | |
| 77 | testing.expectEqual(@as(u5, 31), Register.sp.id()); | |
| 76 | try testing.expectEqual(@as(u5, 31), Register.sp.id()); | |
| 77 | try testing.expectEqual(@as(u5, 31), Register.sp.id()); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "Register.size" { |
| 81 | testing.expectEqual(@as(u7, 64), Register.x19.size()); | |
| 82 | testing.expectEqual(@as(u7, 32), Register.w3.size()); | |
| 81 | try testing.expectEqual(@as(u7, 64), Register.x19.size()); | |
| 82 | try testing.expectEqual(@as(u7, 32), Register.w3.size()); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "Register.to64/to32" { |
| 86 | testing.expectEqual(Register.x0, Register.w0.to64()); | |
| 87 | testing.expectEqual(Register.x0, Register.x0.to64()); | |
| 86 | try testing.expectEqual(Register.x0, Register.w0.to64()); | |
| 87 | try testing.expectEqual(Register.x0, Register.x0.to64()); | |
| 88 | 88 | |
| 89 | testing.expectEqual(Register.w3, Register.w3.to32()); | |
| 90 | testing.expectEqual(Register.w3, Register.x3.to32()); | |
| 89 | try testing.expectEqual(Register.w3, Register.w3.to32()); | |
| 90 | try testing.expectEqual(Register.w3, Register.x3.to32()); | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // zig fmt: off |
| ... | ... | @@ -169,33 +169,33 @@ pub const FloatingPointRegister = enum(u8) { |
| 169 | 169 | // zig fmt: on |
| 170 | 170 | |
| 171 | 171 | test "FloatingPointRegister.id" { |
| 172 | testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id()); | |
| 173 | testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id()); | |
| 174 | testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id()); | |
| 175 | testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id()); | |
| 176 | testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id()); | |
| 177 | ||
| 178 | testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id()); | |
| 179 | testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id()); | |
| 172 | try testing.expectEqual(@as(u5, 0), FloatingPointRegister.b0.id()); | |
| 173 | try testing.expectEqual(@as(u5, 0), FloatingPointRegister.h0.id()); | |
| 174 | try testing.expectEqual(@as(u5, 0), FloatingPointRegister.s0.id()); | |
| 175 | try testing.expectEqual(@as(u5, 0), FloatingPointRegister.d0.id()); | |
| 176 | try testing.expectEqual(@as(u5, 0), FloatingPointRegister.q0.id()); | |
| 177 | ||
| 178 | try testing.expectEqual(@as(u5, 2), FloatingPointRegister.q2.id()); | |
| 179 | try testing.expectEqual(@as(u5, 31), FloatingPointRegister.d31.id()); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | test "FloatingPointRegister.size" { |
| 183 | testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size()); | |
| 184 | testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size()); | |
| 185 | testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size()); | |
| 186 | testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size()); | |
| 187 | testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size()); | |
| 183 | try testing.expectEqual(@as(u8, 128), FloatingPointRegister.q1.size()); | |
| 184 | try testing.expectEqual(@as(u8, 64), FloatingPointRegister.d2.size()); | |
| 185 | try testing.expectEqual(@as(u8, 32), FloatingPointRegister.s3.size()); | |
| 186 | try testing.expectEqual(@as(u8, 16), FloatingPointRegister.h4.size()); | |
| 187 | try testing.expectEqual(@as(u8, 8), FloatingPointRegister.b5.size()); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "FloatingPointRegister.toX" { |
| 191 | testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128()); | |
| 192 | testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128()); | |
| 193 | testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128()); | |
| 194 | ||
| 195 | testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64()); | |
| 196 | testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32()); | |
| 197 | testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16()); | |
| 198 | testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8()); | |
| 191 | try testing.expectEqual(FloatingPointRegister.q1, FloatingPointRegister.q1.to128()); | |
| 192 | try testing.expectEqual(FloatingPointRegister.q2, FloatingPointRegister.b2.to128()); | |
| 193 | try testing.expectEqual(FloatingPointRegister.q3, FloatingPointRegister.h3.to128()); | |
| 194 | ||
| 195 | try testing.expectEqual(FloatingPointRegister.d0, FloatingPointRegister.q0.to64()); | |
| 196 | try testing.expectEqual(FloatingPointRegister.s1, FloatingPointRegister.d1.to32()); | |
| 197 | try testing.expectEqual(FloatingPointRegister.h2, FloatingPointRegister.s2.to16()); | |
| 198 | try testing.expectEqual(FloatingPointRegister.b3, FloatingPointRegister.h3.to8()); | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /// Represents an instruction in the AArch64 instruction set |
| ... | ... | @@ -1225,6 +1225,6 @@ test "serialize instructions" { |
| 1225 | 1225 | |
| 1226 | 1226 | for (testcases) |case| { |
| 1227 | 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 | 88 | }; |
| 89 | 89 | |
| 90 | 90 | test "condition from CompareOperator" { |
| 91 | testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq)); | |
| 92 | testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq)); | |
| 91 | try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorSigned(.eq)); | |
| 92 | try testing.expectEqual(@as(Condition, .eq), Condition.fromCompareOperatorUnsigned(.eq)); | |
| 93 | 93 | |
| 94 | testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt)); | |
| 95 | testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt)); | |
| 94 | try testing.expectEqual(@as(Condition, .gt), Condition.fromCompareOperatorSigned(.gt)); | |
| 95 | try testing.expectEqual(@as(Condition, .hi), Condition.fromCompareOperatorUnsigned(.gt)); | |
| 96 | 96 | |
| 97 | testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte)); | |
| 98 | testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte)); | |
| 97 | try testing.expectEqual(@as(Condition, .le), Condition.fromCompareOperatorSigned(.lte)); | |
| 98 | try testing.expectEqual(@as(Condition, .ls), Condition.fromCompareOperatorUnsigned(.lte)); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | test "negate condition" { |
| 102 | testing.expectEqual(@as(Condition, .eq), Condition.ne.negate()); | |
| 103 | testing.expectEqual(@as(Condition, .ne), Condition.eq.negate()); | |
| 102 | try testing.expectEqual(@as(Condition, .eq), Condition.ne.negate()); | |
| 103 | try testing.expectEqual(@as(Condition, .ne), Condition.eq.negate()); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /// Represents a register in the ARM instruction set architecture |
| ... | ... | @@ -175,8 +175,8 @@ pub const Register = enum(u5) { |
| 175 | 175 | }; |
| 176 | 176 | |
| 177 | 177 | test "Register.id" { |
| 178 | testing.expectEqual(@as(u4, 15), Register.r15.id()); | |
| 179 | testing.expectEqual(@as(u4, 15), Register.pc.id()); | |
| 178 | try testing.expectEqual(@as(u4, 15), Register.r15.id()); | |
| 179 | try testing.expectEqual(@as(u4, 15), Register.pc.id()); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /// Program status registers containing flags, mode bits and other |
| ... | ... | @@ -1225,7 +1225,7 @@ test "serialize instructions" { |
| 1225 | 1225 | |
| 1226 | 1226 | for (testcases) |case| { |
| 1227 | 1227 | const actual = case.inst.toU32(); |
| 1228 | testing.expectEqual(case.expected, actual); | |
| 1228 | try testing.expectEqual(case.expected, actual); | |
| 1229 | 1229 | } |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| ... | ... | @@ -1265,6 +1265,6 @@ test "aliases" { |
| 1265 | 1265 | }; |
| 1266 | 1266 | |
| 1267 | 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 | 465 | |
| 466 | 466 | for (testcases) |case| { |
| 467 | 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 | 463 | const i64_extend32_s = buildOpcode(.{ .op = .extend, .valtype1 = .i64, .width = 32, .signedness = .signed }); |
| 464 | 464 | const f64_reinterpret_i64 = buildOpcode(.{ .op = .reinterpret, .valtype1 = .f64, .valtype2 = .i64 }); |
| 465 | 465 | |
| 466 | testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const); | |
| 467 | testing.expectEqual(@as(wasm.Opcode, .end), end); | |
| 468 | testing.expectEqual(@as(wasm.Opcode, .local_get), local_get); | |
| 469 | testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s); | |
| 470 | testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64); | |
| 466 | try testing.expectEqual(@as(wasm.Opcode, .i32_const), i32_const); | |
| 467 | try testing.expectEqual(@as(wasm.Opcode, .end), end); | |
| 468 | try testing.expectEqual(@as(wasm.Opcode, .local_get), local_get); | |
| 469 | try testing.expectEqual(@as(wasm.Opcode, .i64_extend32_s), i64_extend32_s); | |
| 470 | try testing.expectEqual(@as(wasm.Opcode, .f64_reinterpret_i64), f64_reinterpret_i64); | |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | pub const Result = union(enum) { |
src/link/MachO/CodeSignature.zig+1-1| ... | ... | @@ -182,7 +182,7 @@ test "CodeSignature header" { |
| 182 | 182 | try code_sig.writeHeader(stream.writer()); |
| 183 | 183 | |
| 184 | 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 | } |
| 187 | 187 | |
| 188 | 188 | pub 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 | 404 | var trie = Trie.init(gpa); |
| 405 | 405 | defer trie.deinit(); |
| 406 | 406 | |
| 407 | testing.expectEqual(trie.node_count, 0); | |
| 408 | testing.expect(trie.root == null); | |
| 407 | try testing.expectEqual(trie.node_count, 0); | |
| 408 | try testing.expect(trie.root == null); | |
| 409 | 409 | |
| 410 | 410 | try trie.put(.{ |
| 411 | 411 | .name = "_main", |
| 412 | 412 | .vmaddr_offset = 0, |
| 413 | 413 | .export_flags = 0, |
| 414 | 414 | }); |
| 415 | testing.expectEqual(trie.node_count, 2); | |
| 415 | try testing.expectEqual(trie.node_count, 2); | |
| 416 | 416 | |
| 417 | 417 | // Inserting the same node shouldn't update the trie. |
| 418 | 418 | try trie.put(.{ |
| ... | ... | @@ -420,14 +420,14 @@ test "Trie node count" { |
| 420 | 420 | .vmaddr_offset = 0, |
| 421 | 421 | .export_flags = 0, |
| 422 | 422 | }); |
| 423 | testing.expectEqual(trie.node_count, 2); | |
| 423 | try testing.expectEqual(trie.node_count, 2); | |
| 424 | 424 | |
| 425 | 425 | try trie.put(.{ |
| 426 | 426 | .name = "__mh_execute_header", |
| 427 | 427 | .vmaddr_offset = 0x1000, |
| 428 | 428 | .export_flags = 0, |
| 429 | 429 | }); |
| 430 | testing.expectEqual(trie.node_count, 4); | |
| 430 | try testing.expectEqual(trie.node_count, 4); | |
| 431 | 431 | |
| 432 | 432 | // Inserting the same node shouldn't update the trie. |
| 433 | 433 | try trie.put(.{ |
| ... | ... | @@ -435,13 +435,13 @@ test "Trie node count" { |
| 435 | 435 | .vmaddr_offset = 0x1000, |
| 436 | 436 | .export_flags = 0, |
| 437 | 437 | }); |
| 438 | testing.expectEqual(trie.node_count, 4); | |
| 438 | try testing.expectEqual(trie.node_count, 4); | |
| 439 | 439 | try trie.put(.{ |
| 440 | 440 | .name = "_main", |
| 441 | 441 | .vmaddr_offset = 0, |
| 442 | 442 | .export_flags = 0, |
| 443 | 443 | }); |
| 444 | testing.expectEqual(trie.node_count, 4); | |
| 444 | try testing.expectEqual(trie.node_count, 4); | |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | test "Trie basic" { |
| ... | ... | @@ -455,8 +455,8 @@ test "Trie basic" { |
| 455 | 455 | .vmaddr_offset = 0, |
| 456 | 456 | .export_flags = 0, |
| 457 | 457 | }); |
| 458 | testing.expect(trie.root.?.edges.items.len == 1); | |
| 459 | testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st")); | |
| 458 | try testing.expect(trie.root.?.edges.items.len == 1); | |
| 459 | try testing.expect(mem.eql(u8, trie.root.?.edges.items[0].label, "_st")); | |
| 460 | 460 | |
| 461 | 461 | { |
| 462 | 462 | // root --- _st ---> node --- art ---> node |
| ... | ... | @@ -465,12 +465,12 @@ test "Trie basic" { |
| 465 | 465 | .vmaddr_offset = 0, |
| 466 | 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); | |
| 469 | 469 | |
| 470 | 470 | const nextEdge = &trie.root.?.edges.items[0]; |
| 471 | testing.expect(mem.eql(u8, nextEdge.label, "_st")); | |
| 472 | testing.expect(nextEdge.to.edges.items.len == 1); | |
| 473 | testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art")); | |
| 471 | try testing.expect(mem.eql(u8, nextEdge.label, "_st")); | |
| 472 | try testing.expect(nextEdge.to.edges.items.len == 1); | |
| 473 | try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "art")); | |
| 474 | 474 | } |
| 475 | 475 | { |
| 476 | 476 | // root --- _ ---> node --- st ---> node --- art ---> node |
| ... | ... | @@ -481,16 +481,16 @@ test "Trie basic" { |
| 481 | 481 | .vmaddr_offset = 0, |
| 482 | 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); | |
| 485 | 485 | |
| 486 | 486 | const nextEdge = &trie.root.?.edges.items[0]; |
| 487 | testing.expect(mem.eql(u8, nextEdge.label, "_")); | |
| 488 | testing.expect(nextEdge.to.edges.items.len == 2); | |
| 489 | testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st")); | |
| 490 | testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main")); | |
| 487 | try testing.expect(mem.eql(u8, nextEdge.label, "_")); | |
| 488 | try testing.expect(nextEdge.to.edges.items.len == 2); | |
| 489 | try testing.expect(mem.eql(u8, nextEdge.to.edges.items[0].label, "st")); | |
| 490 | try testing.expect(mem.eql(u8, nextEdge.to.edges.items[1].label, "main")); | |
| 491 | 491 | |
| 492 | 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 | } |
| 496 | 496 | |
| ... | ... | @@ -529,15 +529,15 @@ test "write Trie to a byte stream" { |
| 529 | 529 | var stream = std.io.fixedBufferStream(buffer); |
| 530 | 530 | { |
| 531 | 531 | const nwritten = try trie.write(stream.writer()); |
| 532 | testing.expect(nwritten == trie.size); | |
| 533 | testing.expect(mem.eql(u8, buffer, &exp_buffer)); | |
| 532 | try testing.expect(nwritten == trie.size); | |
| 533 | try testing.expect(mem.eql(u8, buffer, &exp_buffer)); | |
| 534 | 534 | } |
| 535 | 535 | { |
| 536 | 536 | // Writing finalized trie again should yield the same result. |
| 537 | 537 | try stream.seekTo(0); |
| 538 | 538 | const nwritten = try trie.write(stream.writer()); |
| 539 | testing.expect(nwritten == trie.size); | |
| 540 | testing.expect(mem.eql(u8, buffer, &exp_buffer)); | |
| 539 | try testing.expect(nwritten == trie.size); | |
| 540 | try testing.expect(mem.eql(u8, buffer, &exp_buffer)); | |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| ... | ... | @@ -560,7 +560,7 @@ test "parse Trie from byte stream" { |
| 560 | 560 | defer trie.deinit(); |
| 561 | 561 | const nread = try trie.read(in_stream.reader()); |
| 562 | 562 | |
| 563 | testing.expect(nread == in_buffer.len); | |
| 563 | try testing.expect(nread == in_buffer.len); | |
| 564 | 564 | |
| 565 | 565 | try trie.finalize(); |
| 566 | 566 | |
| ... | ... | @@ -569,6 +569,6 @@ test "parse Trie from byte stream" { |
| 569 | 569 | var out_stream = std.io.fixedBufferStream(out_buffer); |
| 570 | 570 | const nwritten = try trie.write(out_stream.writer()); |
| 571 | 571 | |
| 572 | testing.expect(nwritten == trie.size); | |
| 573 | testing.expect(mem.eql(u8, &in_buffer, out_buffer)); | |
| 572 | try testing.expect(nwritten == trie.size); | |
| 573 | try testing.expect(mem.eql(u8, &in_buffer, out_buffer)); | |
| 574 | 574 | } |
src/link/MachO/commands.zig+2-2| ... | ... | @@ -286,13 +286,13 @@ fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void |
| 286 | 286 | var stream = io.fixedBufferStream(buffer); |
| 287 | 287 | var given = try LoadCommand.read(allocator, stream.reader()); |
| 288 | 288 | defer given.deinit(allocator); |
| 289 | testing.expect(expected.eql(given)); | |
| 289 | try testing.expect(expected.eql(given)); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | fn testWrite(buffer: []u8, cmd: LoadCommand, expected: []const u8) !void { |
| 293 | 293 | var stream = io.fixedBufferStream(buffer); |
| 294 | 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 | } |
| 297 | 297 | |
| 298 | 298 | test "read-write segment command" { |
src/register_manager.zig+24-24| ... | ... | @@ -267,21 +267,21 @@ test "tryAllocReg: no spilling" { |
| 267 | 267 | .src = .unneeded, |
| 268 | 268 | }; |
| 269 | 269 | |
| 270 | std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 271 | std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 270 | try std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 271 | try std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 272 | 272 | |
| 273 | std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 274 | std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 275 | std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 273 | try std.testing.expectEqual(@as(?MockRegister, .r2), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 274 | try std.testing.expectEqual(@as(?MockRegister, .r3), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 275 | try std.testing.expectEqual(@as(?MockRegister, null), function.register_manager.tryAllocReg(&mock_instruction)); | |
| 276 | 276 | |
| 277 | std.testing.expect(function.register_manager.isRegAllocated(.r2)); | |
| 278 | std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 277 | try std.testing.expect(function.register_manager.isRegAllocated(.r2)); | |
| 278 | try std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 279 | 279 | |
| 280 | 280 | function.register_manager.freeReg(.r2); |
| 281 | 281 | function.register_manager.freeReg(.r3); |
| 282 | 282 | |
| 283 | std.testing.expect(function.register_manager.isRegAllocated(.r2)); | |
| 284 | std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 283 | try std.testing.expect(function.register_manager.isRegAllocated(.r2)); | |
| 284 | try std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | test "allocReg: spilling" { |
| ... | ... | @@ -298,20 +298,20 @@ test "allocReg: spilling" { |
| 298 | 298 | .src = .unneeded, |
| 299 | 299 | }; |
| 300 | 300 | |
| 301 | std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 302 | std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 301 | try std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 302 | try std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 303 | 303 | |
| 304 | std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction)); | |
| 305 | std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction)); | |
| 304 | try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction)); | |
| 305 | try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction)); | |
| 306 | 306 | |
| 307 | 307 | // Spill a register |
| 308 | std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction)); | |
| 309 | std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items); | |
| 308 | try std.testing.expectEqual(@as(?MockRegister, .r2), try function.register_manager.allocReg(&mock_instruction)); | |
| 309 | try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items); | |
| 310 | 310 | |
| 311 | 311 | // No spilling necessary |
| 312 | 312 | function.register_manager.freeReg(.r3); |
| 313 | std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction)); | |
| 314 | std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items); | |
| 313 | try std.testing.expectEqual(@as(?MockRegister, .r3), try function.register_manager.allocReg(&mock_instruction)); | |
| 314 | try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r2}, function.spilled.items); | |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | test "getReg" { |
| ... | ... | @@ -328,18 +328,18 @@ test "getReg" { |
| 328 | 328 | .src = .unneeded, |
| 329 | 329 | }; |
| 330 | 330 | |
| 331 | std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 332 | std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 331 | try std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 332 | try std.testing.expect(!function.register_manager.isRegAllocated(.r3)); | |
| 333 | 333 | |
| 334 | 334 | try function.register_manager.getReg(.r3, &mock_instruction); |
| 335 | 335 | |
| 336 | std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 337 | std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 336 | try std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 337 | try std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 338 | 338 | |
| 339 | 339 | // Spill r3 |
| 340 | 340 | try function.register_manager.getReg(.r3, &mock_instruction); |
| 341 | 341 | |
| 342 | std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 343 | std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 344 | std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items); | |
| 342 | try std.testing.expect(!function.register_manager.isRegAllocated(.r2)); | |
| 343 | try std.testing.expect(function.register_manager.isRegAllocated(.r3)); | |
| 344 | try std.testing.expectEqualSlices(MockRegister, &[_]MockRegister{.r3}, function.spilled.items); | |
| 345 | 345 | } |
src/test.zig+3-3| ... | ... | @@ -705,14 +705,14 @@ pub const TestContext = struct { |
| 705 | 705 | defer file.close(); |
| 706 | 706 | const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024); |
| 707 | 707 | |
| 708 | std.testing.expectEqualStrings(expected_output, out); | |
| 708 | try std.testing.expectEqualStrings(expected_output, out); | |
| 709 | 709 | }, |
| 710 | 710 | .CompareObjectFile => |expected_output| { |
| 711 | 711 | var file = try tmp.dir.openFile(bin_name, .{ .read = true }); |
| 712 | 712 | defer file.close(); |
| 713 | 713 | const out = try file.reader().readAllAlloc(arena, 5 * 1024 * 1024); |
| 714 | 714 | |
| 715 | std.testing.expectEqualStrings(expected_output, out); | |
| 715 | try std.testing.expectEqualStrings(expected_output, out); | |
| 716 | 716 | }, |
| 717 | 717 | .Error => |case_error_list| { |
| 718 | 718 | var test_node = update_node.start("assert", 0); |
| ... | ... | @@ -939,7 +939,7 @@ pub const TestContext = struct { |
| 939 | 939 | return error.ZigTestFailed; |
| 940 | 940 | }, |
| 941 | 941 | } |
| 942 | std.testing.expectEqualStrings(expected_stdout, exec_result.stdout); | |
| 942 | try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout); | |
| 943 | 943 | // We allow stderr to have garbage in it because wasmtime prints a |
| 944 | 944 | // warning about --invoke even though we don't pass it. |
| 945 | 945 | //std.testing.expectEqualStrings("", exec_result.stderr); |
src/value.zig+3-3| ... | ... | @@ -1456,19 +1456,19 @@ test "hash same value different representation" { |
| 1456 | 1456 | .data = 0, |
| 1457 | 1457 | }; |
| 1458 | 1458 | const zero_2 = Value.initPayload(&payload_1.base); |
| 1459 | std.testing.expectEqual(zero_1.hash(), zero_2.hash()); | |
| 1459 | try std.testing.expectEqual(zero_1.hash(), zero_2.hash()); | |
| 1460 | 1460 | |
| 1461 | 1461 | var payload_2 = Value.Payload.I64{ |
| 1462 | 1462 | .base = .{ .tag = .int_i64 }, |
| 1463 | 1463 | .data = 0, |
| 1464 | 1464 | }; |
| 1465 | 1465 | const zero_3 = Value.initPayload(&payload_2.base); |
| 1466 | std.testing.expectEqual(zero_2.hash(), zero_3.hash()); | |
| 1466 | try std.testing.expectEqual(zero_2.hash(), zero_3.hash()); | |
| 1467 | 1467 | |
| 1468 | 1468 | var payload_3 = Value.Payload.BigInt{ |
| 1469 | 1469 | .base = .{ .tag = .int_big_negative }, |
| 1470 | 1470 | .data = &[_]std.math.big.Limb{0}, |
| 1471 | 1471 | }; |
| 1472 | 1472 | const zero_4 = Value.initPayload(&payload_3.base); |
| 1473 | std.testing.expectEqual(zero_3.hash(), zero_4.hash()); | |
| 1473 | try std.testing.expectEqual(zero_3.hash(), zero_4.hash()); | |
| 1474 | 1474 | } |
test/cli.zig+14-14| ... | ... | @@ -29,7 +29,7 @@ pub fn main() !void { |
| 29 | 29 | |
| 30 | 30 | const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" }); |
| 31 | 31 | defer fs.cwd().deleteTree(dir_path) catch {}; |
| 32 | ||
| 32 | ||
| 33 | 33 | const TestFn = fn ([]const u8, []const u8) anyerror!void; |
| 34 | 34 | const test_fns = [_]TestFn{ |
| 35 | 35 | testZigInitLib, |
| ... | ... | @@ -94,13 +94,13 @@ fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess |
| 94 | 94 | fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void { |
| 95 | 95 | _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" }); |
| 96 | 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 | } |
| 99 | 99 | |
| 100 | 100 | fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void { |
| 101 | 101 | _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" }); |
| 102 | 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 | } |
| 105 | 105 | |
| 106 | 106 | 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 | 136 | _ = try exec(dir_path, true, args.items); |
| 137 | 137 | |
| 138 | 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); | |
| 140 | testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null); | |
| 141 | testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null); | |
| 139 | try testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null); | |
| 140 | try testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null); | |
| 141 | try testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | 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 | 149 | const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg }); |
| 150 | 150 | const s = std.fs.path.sep_str; |
| 151 | 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 | } |
| 154 | 154 | |
| 155 | 155 | 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 { |
| 162 | 162 | |
| 163 | 163 | const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path }); |
| 164 | 164 | // stderr should be file path + \n |
| 165 | testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path)); | |
| 166 | testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n'); | |
| 165 | try testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path)); | |
| 166 | try testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n'); | |
| 167 | 167 | |
| 168 | 168 | const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" }); |
| 169 | 169 | try fs.cwd().writeFile(fmt2_zig_path, unformatted_code); |
| 170 | 170 | |
| 171 | 171 | const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path }); |
| 172 | 172 | // running it on the dir, only the new file should be changed |
| 173 | testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path)); | |
| 174 | testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n'); | |
| 173 | try testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path)); | |
| 174 | try testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n'); | |
| 175 | 175 | |
| 176 | 176 | const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path }); |
| 177 | 177 | // 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); | |
| 179 | 179 | |
| 180 | 180 | // Check UTF-16 decoding |
| 181 | 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 | 183 | try fs.cwd().writeFile(fmt4_zig_path, unformatted_code_utf16); |
| 184 | 184 | |
| 185 | 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)); | |
| 187 | testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n'); | |
| 186 | try testing.expect(std.mem.startsWith(u8, run_result4.stdout, fmt4_zig_path)); | |
| 187 | try testing.expect(run_result4.stdout.len == fmt4_zig_path.len + 1 and run_result4.stdout[run_result4.stdout.len - 1] == '\n'); | |
| 188 | 188 | } |
test/compile_errors.zig+1-1| ... | ... | @@ -230,7 +230,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 230 | 230 | |
| 231 | 231 | cases.add("array in c exported function", |
| 232 | 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 | 236 | \\export fn zig_return_array() [10]u8 { |
test/stack_traces.zig+17-17| ... | ... | @@ -5,13 +5,13 @@ const tests = @import("tests.zig"); |
| 5 | 5 | pub fn addCases(cases: *tests.StackTracesContext) void { |
| 6 | 6 | cases.addCase(.{ |
| 7 | 7 | .name = "return", |
| 8 | .source = | |
| 8 | .source = | |
| 9 | 9 | \\pub fn main() !void { |
| 10 | 10 | \\ return error.TheSkyIsFalling; |
| 11 | 11 | \\} |
| 12 | 12 | , |
| 13 | 13 | .Debug = .{ |
| 14 | .expect = | |
| 14 | .expect = | |
| 15 | 15 | \\error: TheSkyIsFalling |
| 16 | 16 | \\source.zig:2:5: [address] in main (test) |
| 17 | 17 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -23,7 +23,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 23 | 23 | .exclude_os = .{ |
| 24 | 24 | .windows, // segfault |
| 25 | 25 | }, |
| 26 | .expect = | |
| 26 | .expect = | |
| 27 | 27 | \\error: TheSkyIsFalling |
| 28 | 28 | \\source.zig:2:5: [address] in [function] |
| 29 | 29 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -32,13 +32,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 32 | 32 | , |
| 33 | 33 | }, |
| 34 | 34 | .ReleaseFast = .{ |
| 35 | .expect = | |
| 35 | .expect = | |
| 36 | 36 | \\error: TheSkyIsFalling |
| 37 | 37 | \\ |
| 38 | 38 | , |
| 39 | 39 | }, |
| 40 | 40 | .ReleaseSmall = .{ |
| 41 | .expect = | |
| 41 | .expect = | |
| 42 | 42 | \\error: TheSkyIsFalling |
| 43 | 43 | \\ |
| 44 | 44 | , |
| ... | ... | @@ -47,7 +47,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 47 | 47 | |
| 48 | 48 | cases.addCase(.{ |
| 49 | 49 | .name = "try return", |
| 50 | .source = | |
| 50 | .source = | |
| 51 | 51 | \\fn foo() !void { |
| 52 | 52 | \\ return error.TheSkyIsFalling; |
| 53 | 53 | \\} |
| ... | ... | @@ -57,7 +57,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 57 | 57 | \\} |
| 58 | 58 | , |
| 59 | 59 | .Debug = .{ |
| 60 | .expect = | |
| 60 | .expect = | |
| 61 | 61 | \\error: TheSkyIsFalling |
| 62 | 62 | \\source.zig:2:5: [address] in foo (test) |
| 63 | 63 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -72,7 +72,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 72 | 72 | .exclude_os = .{ |
| 73 | 73 | .windows, // segfault |
| 74 | 74 | }, |
| 75 | .expect = | |
| 75 | .expect = | |
| 76 | 76 | \\error: TheSkyIsFalling |
| 77 | 77 | \\source.zig:2:5: [address] in [function] |
| 78 | 78 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -84,13 +84,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 84 | 84 | , |
| 85 | 85 | }, |
| 86 | 86 | .ReleaseFast = .{ |
| 87 | .expect = | |
| 87 | .expect = | |
| 88 | 88 | \\error: TheSkyIsFalling |
| 89 | 89 | \\ |
| 90 | 90 | , |
| 91 | 91 | }, |
| 92 | 92 | .ReleaseSmall = .{ |
| 93 | .expect = | |
| 93 | .expect = | |
| 94 | 94 | \\error: TheSkyIsFalling |
| 95 | 95 | \\ |
| 96 | 96 | , |
| ... | ... | @@ -99,7 +99,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 99 | 99 | |
| 100 | 100 | cases.addCase(.{ |
| 101 | 101 | .name = "try try return return", |
| 102 | .source = | |
| 102 | .source = | |
| 103 | 103 | \\fn foo() !void { |
| 104 | 104 | \\ try bar(); |
| 105 | 105 | \\} |
| ... | ... | @@ -117,7 +117,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 117 | 117 | \\} |
| 118 | 118 | , |
| 119 | 119 | .Debug = .{ |
| 120 | .expect = | |
| 120 | .expect = | |
| 121 | 121 | \\error: TheSkyIsFalling |
| 122 | 122 | \\source.zig:10:5: [address] in make_error (test) |
| 123 | 123 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -138,7 +138,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 138 | 138 | .exclude_os = .{ |
| 139 | 139 | .windows, // segfault |
| 140 | 140 | }, |
| 141 | .expect = | |
| 141 | .expect = | |
| 142 | 142 | \\error: TheSkyIsFalling |
| 143 | 143 | \\source.zig:10:5: [address] in [function] |
| 144 | 144 | \\ return error.TheSkyIsFalling; |
| ... | ... | @@ -156,13 +156,13 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 156 | 156 | , |
| 157 | 157 | }, |
| 158 | 158 | .ReleaseFast = .{ |
| 159 | .expect = | |
| 159 | .expect = | |
| 160 | 160 | \\error: TheSkyIsFalling |
| 161 | 161 | \\ |
| 162 | 162 | , |
| 163 | 163 | }, |
| 164 | 164 | .ReleaseSmall = .{ |
| 165 | .expect = | |
| 165 | .expect = | |
| 166 | 166 | \\error: TheSkyIsFalling |
| 167 | 167 | \\ |
| 168 | 168 | , |
| ... | ... | @@ -174,7 +174,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 174 | 174 | .windows, |
| 175 | 175 | }, |
| 176 | 176 | .name = "dumpCurrentStackTrace", |
| 177 | .source = | |
| 177 | .source = | |
| 178 | 178 | \\const std = @import("std"); |
| 179 | 179 | \\ |
| 180 | 180 | \\fn bar() void { |
| ... | ... | @@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.StackTracesContext) void { |
| 189 | 189 | \\} |
| 190 | 190 | , |
| 191 | 191 | .Debug = .{ |
| 192 | .expect = | |
| 192 | .expect = | |
| 193 | 193 | \\source.zig:7:8: [address] in foo (test) |
| 194 | 194 | \\ bar(); |
| 195 | 195 | \\ ^ |
test/stage1/behavior/align.zig+66-66| ... | ... | @@ -5,16 +5,16 @@ const builtin = @import("builtin"); |
| 5 | 5 | var foo: u8 align(4) = 100; |
| 6 | 6 | |
| 7 | 7 | test "global variable alignment" { |
| 8 | comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 9 | comptime expect(@TypeOf(&foo) == *align(4) u8); | |
| 8 | comptime try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 9 | comptime try expect(@TypeOf(&foo) == *align(4) u8); | |
| 10 | 10 | { |
| 11 | 11 | const slice = @as(*[1]u8, &foo)[0..]; |
| 12 | comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 12 | comptime try expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 13 | 13 | } |
| 14 | 14 | { |
| 15 | 15 | var runtime_zero: usize = 0; |
| 16 | 16 | const slice = @as(*[1]u8, &foo)[runtime_zero..]; |
| 17 | comptime expect(@TypeOf(slice) == []align(4) u8); | |
| 17 | comptime try expect(@TypeOf(slice) == []align(4) u8); | |
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
| ... | ... | @@ -28,9 +28,9 @@ test "function alignment" { |
| 28 | 28 | // function alignment is a compile error on wasm32/wasm64 |
| 29 | 29 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 30 | 30 | |
| 31 | expect(derp() == 1234); | |
| 32 | expect(@TypeOf(noop1) == fn () align(1) void); | |
| 33 | expect(@TypeOf(noop4) == fn () align(4) void); | |
| 31 | try expect(derp() == 1234); | |
| 32 | try expect(@TypeOf(noop1) == fn () align(1) void); | |
| 33 | try expect(@TypeOf(noop4) == fn () align(4) void); | |
| 34 | 34 | noop1(); |
| 35 | 35 | noop4(); |
| 36 | 36 | } |
| ... | ... | @@ -41,7 +41,7 @@ var baz: packed struct { |
| 41 | 41 | } = undefined; |
| 42 | 42 | |
| 43 | 43 | test "packed struct alignment" { |
| 44 | expect(@TypeOf(&baz.b) == *align(1) u32); | |
| 44 | try expect(@TypeOf(&baz.b) == *align(1) u32); | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | const blah: packed struct { |
| ... | ... | @@ -51,17 +51,17 @@ const blah: packed struct { |
| 51 | 51 | } = undefined; |
| 52 | 52 | |
| 53 | 53 | test "bit field alignment" { |
| 54 | expect(@TypeOf(&blah.b) == *align(1:3:1) const u3); | |
| 54 | try expect(@TypeOf(&blah.b) == *align(1:3:1) const u3); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "default alignment allows unspecified in type syntax" { |
| 58 | expect(*u32 == *align(@alignOf(u32)) u32); | |
| 58 | try expect(*u32 == *align(@alignOf(u32)) u32); | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | test "implicitly decreasing pointer alignment" { |
| 62 | 62 | const a: u32 align(4) = 3; |
| 63 | 63 | const b: u32 align(8) = 4; |
| 64 | expect(addUnaligned(&a, &b) == 7); | |
| 64 | try expect(addUnaligned(&a, &b) == 7); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| ... | ... | @@ -71,16 +71,16 @@ fn addUnaligned(a: *align(1) const u32, b: *align(1) const u32) u32 { |
| 71 | 71 | test "implicitly decreasing slice alignment" { |
| 72 | 72 | const a: u32 align(4) = 3; |
| 73 | 73 | const b: u32 align(8) = 4; |
| 74 | expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7); | |
| 74 | try expect(addUnalignedSlice(@as(*const [1]u32, &a)[0..], @as(*const [1]u32, &b)[0..]) == 7); | |
| 75 | 75 | } |
| 76 | 76 | fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) u32 { |
| 77 | 77 | return a[0] + b[0]; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "specifying alignment allows pointer cast" { |
| 81 | testBytesAlign(0x33); | |
| 81 | try testBytesAlign(0x33); | |
| 82 | 82 | } |
| 83 | fn testBytesAlign(b: u8) void { | |
| 83 | fn testBytesAlign(b: u8) !void { | |
| 84 | 84 | var bytes align(4) = [_]u8{ |
| 85 | 85 | b, |
| 86 | 86 | b, |
| ... | ... | @@ -88,13 +88,13 @@ fn testBytesAlign(b: u8) void { |
| 88 | 88 | b, |
| 89 | 89 | }; |
| 90 | 90 | const ptr = @ptrCast(*u32, &bytes[0]); |
| 91 | expect(ptr.* == 0x33333333); | |
| 91 | try expect(ptr.* == 0x33333333); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | test "@alignCast pointers" { |
| 95 | 95 | var x: u32 align(4) = 1; |
| 96 | 96 | expectsOnly1(&x); |
| 97 | expect(x == 2); | |
| 97 | try expect(x == 2); | |
| 98 | 98 | } |
| 99 | 99 | fn expectsOnly1(x: *align(1) u32) void { |
| 100 | 100 | expects4(@alignCast(4, x)); |
| ... | ... | @@ -110,7 +110,7 @@ test "@alignCast slices" { |
| 110 | 110 | }; |
| 111 | 111 | const slice = array[0..]; |
| 112 | 112 | sliceExpectsOnly1(slice); |
| 113 | expect(slice[0] == 2); | |
| 113 | try expect(slice[0] == 2); | |
| 114 | 114 | } |
| 115 | 115 | fn sliceExpectsOnly1(slice: []align(1) u32) void { |
| 116 | 116 | sliceExpects4(@alignCast(4, slice)); |
| ... | ... | @@ -123,12 +123,12 @@ test "implicitly decreasing fn alignment" { |
| 123 | 123 | // function alignment is a compile error on wasm32/wasm64 |
| 124 | 124 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 125 | 125 | |
| 126 | testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | |
| 127 | testImplicitlyDecreaseFnAlign(alignedBig, 5678); | |
| 126 | try testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | |
| 127 | try testImplicitlyDecreaseFnAlign(alignedBig, 5678); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) void { | |
| 131 | expect(ptr() == answer); | |
| 130 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) i32, answer: i32) !void { | |
| 131 | try expect(ptr() == answer); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | fn alignedSmall() align(8) i32 { |
| ... | ... | @@ -143,7 +143,7 @@ test "@alignCast functions" { |
| 143 | 143 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 144 | 144 | if (builtin.arch == .thumb) return error.SkipZigTest; |
| 145 | 145 | |
| 146 | expect(fnExpectsOnly1(simple4) == 0x19); | |
| 146 | try expect(fnExpectsOnly1(simple4) == 0x19); | |
| 147 | 147 | } |
| 148 | 148 | fn fnExpectsOnly1(ptr: fn () align(1) i32) i32 { |
| 149 | 149 | return fnExpects4(@alignCast(4, ptr)); |
| ... | ... | @@ -160,9 +160,9 @@ test "generic function with align param" { |
| 160 | 160 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 161 | 161 | if (builtin.arch == .thumb) return error.SkipZigTest; |
| 162 | 162 | |
| 163 | expect(whyWouldYouEverDoThis(1) == 0x1); | |
| 164 | expect(whyWouldYouEverDoThis(4) == 0x1); | |
| 165 | expect(whyWouldYouEverDoThis(8) == 0x1); | |
| 163 | try expect(whyWouldYouEverDoThis(1) == 0x1); | |
| 164 | try expect(whyWouldYouEverDoThis(4) == 0x1); | |
| 165 | try expect(whyWouldYouEverDoThis(8) == 0x1); | |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { |
| ... | ... | @@ -172,49 +172,49 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { |
| 172 | 172 | test "@ptrCast preserves alignment of bigger source" { |
| 173 | 173 | var x: u32 align(16) = 1234; |
| 174 | 174 | const ptr = @ptrCast(*u8, &x); |
| 175 | expect(@TypeOf(ptr) == *align(16) u8); | |
| 175 | try expect(@TypeOf(ptr) == *align(16) u8); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | test "runtime known array index has best alignment possible" { |
| 179 | 179 | // take full advantage of over-alignment |
| 180 | 180 | var array align(4) = [_]u8{ 1, 2, 3, 4 }; |
| 181 | expect(@TypeOf(&array[0]) == *align(4) u8); | |
| 182 | expect(@TypeOf(&array[1]) == *u8); | |
| 183 | expect(@TypeOf(&array[2]) == *align(2) u8); | |
| 184 | expect(@TypeOf(&array[3]) == *u8); | |
| 181 | try expect(@TypeOf(&array[0]) == *align(4) u8); | |
| 182 | try expect(@TypeOf(&array[1]) == *u8); | |
| 183 | try expect(@TypeOf(&array[2]) == *align(2) u8); | |
| 184 | try expect(@TypeOf(&array[3]) == *u8); | |
| 185 | 185 | |
| 186 | 186 | // because align is too small but we still figure out to use 2 |
| 187 | 187 | var bigger align(2) = [_]u64{ 1, 2, 3, 4 }; |
| 188 | expect(@TypeOf(&bigger[0]) == *align(2) u64); | |
| 189 | expect(@TypeOf(&bigger[1]) == *align(2) u64); | |
| 190 | expect(@TypeOf(&bigger[2]) == *align(2) u64); | |
| 191 | expect(@TypeOf(&bigger[3]) == *align(2) u64); | |
| 188 | try expect(@TypeOf(&bigger[0]) == *align(2) u64); | |
| 189 | try expect(@TypeOf(&bigger[1]) == *align(2) u64); | |
| 190 | try expect(@TypeOf(&bigger[2]) == *align(2) u64); | |
| 191 | try expect(@TypeOf(&bigger[3]) == *align(2) u64); | |
| 192 | 192 | |
| 193 | 193 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 |
| 194 | 194 | var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; |
| 195 | 195 | var runtime_zero: usize = 0; |
| 196 | comptime expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); | |
| 197 | comptime expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); | |
| 198 | testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); | |
| 199 | testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32); | |
| 200 | testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32); | |
| 201 | testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32); | |
| 196 | comptime try expect(@TypeOf(smaller[runtime_zero..]) == []align(2) u32); | |
| 197 | comptime try expect(@TypeOf(smaller[runtime_zero..].ptr) == [*]align(2) u32); | |
| 198 | try testIndex(smaller[runtime_zero..].ptr, 0, *align(2) u32); | |
| 199 | try testIndex(smaller[runtime_zero..].ptr, 1, *align(2) u32); | |
| 200 | try testIndex(smaller[runtime_zero..].ptr, 2, *align(2) u32); | |
| 201 | try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32); | |
| 202 | 202 | |
| 203 | 203 | // has to use ABI alignment because index known at runtime only |
| 204 | testIndex2(array[runtime_zero..].ptr, 0, *u8); | |
| 205 | testIndex2(array[runtime_zero..].ptr, 1, *u8); | |
| 206 | testIndex2(array[runtime_zero..].ptr, 2, *u8); | |
| 207 | testIndex2(array[runtime_zero..].ptr, 3, *u8); | |
| 204 | try testIndex2(array[runtime_zero..].ptr, 0, *u8); | |
| 205 | try testIndex2(array[runtime_zero..].ptr, 1, *u8); | |
| 206 | try testIndex2(array[runtime_zero..].ptr, 2, *u8); | |
| 207 | try testIndex2(array[runtime_zero..].ptr, 3, *u8); | |
| 208 | 208 | } |
| 209 | fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void { | |
| 210 | comptime expect(@TypeOf(&smaller[index]) == T); | |
| 209 | fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void { | |
| 210 | comptime try expect(@TypeOf(&smaller[index]) == T); | |
| 211 | 211 | } |
| 212 | fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void { | |
| 213 | comptime expect(@TypeOf(&ptr[index]) == T); | |
| 212 | fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void { | |
| 213 | comptime try expect(@TypeOf(&ptr[index]) == T); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | test "alignstack" { |
| 217 | expect(fnWithAlignedStack() == 1234); | |
| 217 | try expect(fnWithAlignedStack() == 1234); | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | fn fnWithAlignedStack() i32 { |
| ... | ... | @@ -223,7 +223,7 @@ fn fnWithAlignedStack() i32 { |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | test "alignment of structs" { |
| 226 | expect(@alignOf(struct { | |
| 226 | try expect(@alignOf(struct { | |
| 227 | 227 | a: i32, |
| 228 | 228 | b: *i32, |
| 229 | 229 | }) == @alignOf(usize)); |
| ... | ... | @@ -239,37 +239,37 @@ test "alignment of function with c calling convention" { |
| 239 | 239 | fn nothing() callconv(.C) void {} |
| 240 | 240 | |
| 241 | 241 | test "return error union with 128-bit integer" { |
| 242 | expect(3 == try give()); | |
| 242 | try expect(3 == try give()); | |
| 243 | 243 | } |
| 244 | 244 | fn give() anyerror!u128 { |
| 245 | 245 | return 3; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | test "alignment of >= 128-bit integer type" { |
| 249 | expect(@alignOf(u128) == 16); | |
| 250 | expect(@alignOf(u129) == 16); | |
| 249 | try expect(@alignOf(u128) == 16); | |
| 250 | try expect(@alignOf(u129) == 16); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | test "alignment of struct with 128-bit field" { |
| 254 | expect(@alignOf(struct { | |
| 254 | try expect(@alignOf(struct { | |
| 255 | 255 | x: u128, |
| 256 | 256 | }) == 16); |
| 257 | 257 | |
| 258 | 258 | comptime { |
| 259 | expect(@alignOf(struct { | |
| 259 | try expect(@alignOf(struct { | |
| 260 | 260 | x: u128, |
| 261 | 261 | }) == 16); |
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | test "size of extern struct with 128-bit field" { |
| 266 | expect(@sizeOf(extern struct { | |
| 266 | try expect(@sizeOf(extern struct { | |
| 267 | 267 | x: u128, |
| 268 | 268 | y: u8, |
| 269 | 269 | }) == 32); |
| 270 | 270 | |
| 271 | 271 | comptime { |
| 272 | expect(@sizeOf(extern struct { | |
| 272 | try expect(@sizeOf(extern struct { | |
| 273 | 273 | x: u128, |
| 274 | 274 | y: u8, |
| 275 | 275 | }) == 32); |
| ... | ... | @@ -286,8 +286,8 @@ test "read 128-bit field from default aligned struct in stack memory" { |
| 286 | 286 | .nevermind = 1, |
| 287 | 287 | .badguy = 12, |
| 288 | 288 | }; |
| 289 | expect((@ptrToInt(&default_aligned.badguy) % 16) == 0); | |
| 290 | expect(12 == default_aligned.badguy); | |
| 289 | try expect((@ptrToInt(&default_aligned.badguy) % 16) == 0); | |
| 290 | try expect(12 == default_aligned.badguy); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | var default_aligned_global = DefaultAligned{ |
| ... | ... | @@ -296,8 +296,8 @@ var default_aligned_global = DefaultAligned{ |
| 296 | 296 | }; |
| 297 | 297 | |
| 298 | 298 | test "read 128-bit field from default aligned struct in global memory" { |
| 299 | expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0); | |
| 300 | expect(12 == default_aligned_global.badguy); | |
| 299 | try expect((@ptrToInt(&default_aligned_global.badguy) % 16) == 0); | |
| 300 | try expect(12 == default_aligned_global.badguy); | |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | test "struct field explicit alignment" { |
| ... | ... | @@ -310,9 +310,9 @@ test "struct field explicit alignment" { |
| 310 | 310 | |
| 311 | 311 | var node: S.Node = undefined; |
| 312 | 312 | node.massive_byte = 100; |
| 313 | expect(node.massive_byte == 100); | |
| 314 | comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8); | |
| 315 | expect(@ptrToInt(&node.massive_byte) % 64 == 0); | |
| 313 | try expect(node.massive_byte == 100); | |
| 314 | comptime try expect(@TypeOf(&node.massive_byte) == *align(64) u8); | |
| 315 | try expect(@ptrToInt(&node.massive_byte) % 64 == 0); | |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | test "align(@alignOf(T)) T does not force resolution of T" { |
| ... | ... | @@ -334,7 +334,7 @@ test "align(@alignOf(T)) T does not force resolution of T" { |
| 334 | 334 | var ok = false; |
| 335 | 335 | }; |
| 336 | 336 | _ = async S.doTheTest(); |
| 337 | expect(S.ok); | |
| 337 | try expect(S.ok); | |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | test "align(N) on functions" { |
| ... | ... | @@ -342,7 +342,7 @@ test "align(N) on functions" { |
| 342 | 342 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 343 | 343 | if (builtin.arch == .thumb) return error.SkipZigTest; |
| 344 | 344 | |
| 345 | expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0); | |
| 345 | try expect((@ptrToInt(overaligned_fn) & (0x1000 - 1)) == 0); | |
| 346 | 346 | } |
| 347 | 347 | fn overaligned_fn() align(0x1000) i32 { |
| 348 | 348 | return 42; |
test/stage1/behavior/alignof.zig+14-14| ... | ... | @@ -10,29 +10,29 @@ const Foo = struct { |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | test "@alignOf(T) before referencing T" { |
| 13 | comptime expect(@alignOf(Foo) != maxInt(usize)); | |
| 13 | comptime try expect(@alignOf(Foo) != maxInt(usize)); | |
| 14 | 14 | if (builtin.arch == builtin.Arch.x86_64) { |
| 15 | comptime expect(@alignOf(Foo) == 4); | |
| 15 | comptime try expect(@alignOf(Foo) == 4); | |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "comparison of @alignOf(T) against zero" { |
| 20 | 20 | { |
| 21 | 21 | const T = struct { x: u32 }; |
| 22 | expect(!(@alignOf(T) == 0)); | |
| 23 | expect(@alignOf(T) != 0); | |
| 24 | expect(!(@alignOf(T) < 0)); | |
| 25 | expect(!(@alignOf(T) <= 0)); | |
| 26 | expect(@alignOf(T) > 0); | |
| 27 | expect(@alignOf(T) >= 0); | |
| 22 | try expect(!(@alignOf(T) == 0)); | |
| 23 | try expect(@alignOf(T) != 0); | |
| 24 | try expect(!(@alignOf(T) < 0)); | |
| 25 | try expect(!(@alignOf(T) <= 0)); | |
| 26 | try expect(@alignOf(T) > 0); | |
| 27 | try expect(@alignOf(T) >= 0); | |
| 28 | 28 | } |
| 29 | 29 | { |
| 30 | 30 | const T = struct {}; |
| 31 | expect(@alignOf(T) == 0); | |
| 32 | expect(!(@alignOf(T) != 0)); | |
| 33 | expect(!(@alignOf(T) < 0)); | |
| 34 | expect(@alignOf(T) <= 0); | |
| 35 | expect(!(@alignOf(T) > 0)); | |
| 36 | expect(@alignOf(T) >= 0); | |
| 31 | try expect(@alignOf(T) == 0); | |
| 32 | try expect(!(@alignOf(T) != 0)); | |
| 33 | try expect(!(@alignOf(T) < 0)); | |
| 34 | try expect(@alignOf(T) <= 0); | |
| 35 | try expect(!(@alignOf(T) > 0)); | |
| 36 | try expect(@alignOf(T) >= 0); | |
| 37 | 37 | } |
| 38 | 38 | } |
test/stage1/behavior/array.zig+141-141| ... | ... | @@ -21,8 +21,8 @@ test "arrays" { |
| 21 | 21 | i += 1; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | expect(accumulator == 15); | |
| 25 | expect(getArrayLen(&array) == 5); | |
| 24 | try expect(accumulator == 15); | |
| 25 | try expect(getArrayLen(&array) == 5); | |
| 26 | 26 | } |
| 27 | 27 | fn getArrayLen(a: []const u32) usize { |
| 28 | 28 | return a.len; |
| ... | ... | @@ -30,37 +30,37 @@ fn getArrayLen(a: []const u32) usize { |
| 30 | 30 | |
| 31 | 31 | test "array with sentinels" { |
| 32 | 32 | const S = struct { |
| 33 | fn doTheTest(is_ct: bool) void { | |
| 33 | fn doTheTest(is_ct: bool) !void { | |
| 34 | 34 | if (is_ct) { |
| 35 | 35 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; |
| 36 | 36 | // Disabled at runtime because of |
| 37 | 37 | // 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 | 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 | 42 | var arr: [3:0x55]u8 = undefined; |
| 43 | 43 | // Make sure the sentinel pointer is pointing after the last element |
| 44 | 44 | if (!is_ct) { |
| 45 | 45 | const sentinel_ptr = @ptrToInt(&arr[3]); |
| 46 | 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 | 49 | // Make sure the sentinel is writeable |
| 50 | 50 | arr[3] = 0x55; |
| 51 | 51 | } |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | S.doTheTest(false); | |
| 55 | comptime S.doTheTest(true); | |
| 54 | try S.doTheTest(false); | |
| 55 | comptime try S.doTheTest(true); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | test "void arrays" { |
| 59 | 59 | var array: [4]void = undefined; |
| 60 | 60 | array[0] = void{}; |
| 61 | 61 | array[1] = array[2]; |
| 62 | expect(@sizeOf(@TypeOf(array)) == 0); | |
| 63 | expect(array.len == 4); | |
| 62 | try expect(@sizeOf(@TypeOf(array)) == 0); | |
| 63 | try expect(array.len == 4); | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | test "array literal" { |
| ... | ... | @@ -71,12 +71,12 @@ test "array literal" { |
| 71 | 71 | 1, |
| 72 | 72 | }; |
| 73 | 73 | |
| 74 | expect(hex_mult.len == 4); | |
| 75 | expect(hex_mult[1] == 256); | |
| 74 | try expect(hex_mult.len == 4); | |
| 75 | try expect(hex_mult[1] == 256); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "array dot len const expr" { |
| 79 | expect(comptime x: { | |
| 79 | try expect(comptime x: { | |
| 80 | 80 | break :x some_array.len == 4; |
| 81 | 81 | }); |
| 82 | 82 | } |
| ... | ... | @@ -100,11 +100,11 @@ test "nested arrays" { |
| 100 | 100 | "thing", |
| 101 | 101 | }; |
| 102 | 102 | for (array_of_strings) |s, i| { |
| 103 | if (i == 0) expect(mem.eql(u8, s, "hello")); | |
| 104 | if (i == 1) expect(mem.eql(u8, s, "this")); | |
| 105 | if (i == 2) expect(mem.eql(u8, s, "is")); | |
| 106 | if (i == 3) expect(mem.eql(u8, s, "my")); | |
| 107 | if (i == 4) expect(mem.eql(u8, s, "thing")); | |
| 103 | if (i == 0) try expect(mem.eql(u8, s, "hello")); | |
| 104 | if (i == 1) try expect(mem.eql(u8, s, "this")); | |
| 105 | if (i == 2) try expect(mem.eql(u8, s, "is")); | |
| 106 | if (i == 3) try expect(mem.eql(u8, s, "my")); | |
| 107 | if (i == 4) try expect(mem.eql(u8, s, "thing")); | |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| ... | ... | @@ -122,9 +122,9 @@ test "set global var array via slice embedded in struct" { |
| 122 | 122 | s.a[1].b = 2; |
| 123 | 123 | s.a[2].b = 3; |
| 124 | 124 | |
| 125 | expect(s_array[0].b == 1); | |
| 126 | expect(s_array[1].b == 2); | |
| 127 | expect(s_array[2].b == 3); | |
| 125 | try expect(s_array[0].b == 1); | |
| 126 | try expect(s_array[1].b == 2); | |
| 127 | try expect(s_array[2].b == 3); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | test "array literal with specified size" { |
| ... | ... | @@ -132,34 +132,34 @@ test "array literal with specified size" { |
| 132 | 132 | 1, |
| 133 | 133 | 2, |
| 134 | 134 | }; |
| 135 | expect(array[0] == 1); | |
| 136 | expect(array[1] == 2); | |
| 135 | try expect(array[0] == 1); | |
| 136 | try expect(array[1] == 2); | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | test "array len field" { |
| 140 | 140 | var arr = [4]u8{ 0, 0, 0, 0 }; |
| 141 | 141 | var ptr = &arr; |
| 142 | expect(arr.len == 4); | |
| 143 | comptime expect(arr.len == 4); | |
| 144 | expect(ptr.len == 4); | |
| 145 | comptime expect(ptr.len == 4); | |
| 142 | try expect(arr.len == 4); | |
| 143 | comptime try expect(arr.len == 4); | |
| 144 | try expect(ptr.len == 4); | |
| 145 | comptime try expect(ptr.len == 4); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "single-item pointer to array indexing and slicing" { |
| 149 | testSingleItemPtrArrayIndexSlice(); | |
| 150 | comptime testSingleItemPtrArrayIndexSlice(); | |
| 149 | try testSingleItemPtrArrayIndexSlice(); | |
| 150 | comptime try testSingleItemPtrArrayIndexSlice(); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | fn testSingleItemPtrArrayIndexSlice() void { | |
| 153 | fn testSingleItemPtrArrayIndexSlice() !void { | |
| 154 | 154 | { |
| 155 | 155 | var array: [4]u8 = "aaaa".*; |
| 156 | 156 | doSomeMangling(&array); |
| 157 | expect(mem.eql(u8, "azya", &array)); | |
| 157 | try expect(mem.eql(u8, "azya", &array)); | |
| 158 | 158 | } |
| 159 | 159 | { |
| 160 | 160 | var array = "aaaa".*; |
| 161 | 161 | doSomeMangling(&array); |
| 162 | expect(mem.eql(u8, "azya", &array)); | |
| 162 | try expect(mem.eql(u8, "azya", &array)); | |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| ... | ... | @@ -169,15 +169,15 @@ fn doSomeMangling(array: *[4]u8) void { |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "implicit cast single-item pointer" { |
| 172 | testImplicitCastSingleItemPtr(); | |
| 173 | comptime testImplicitCastSingleItemPtr(); | |
| 172 | try testImplicitCastSingleItemPtr(); | |
| 173 | comptime try testImplicitCastSingleItemPtr(); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | fn testImplicitCastSingleItemPtr() void { | |
| 176 | fn testImplicitCastSingleItemPtr() !void { | |
| 177 | 177 | var byte: u8 = 100; |
| 178 | 178 | const slice = @as(*[1]u8, &byte)[0..]; |
| 179 | 179 | slice[0] += 1; |
| 180 | expect(byte == 101); | |
| 180 | try expect(byte == 101); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | fn testArrayByValAtComptime(b: [2]u8) u8 { |
| ... | ... | @@ -192,7 +192,7 @@ test "comptime evalutating function that takes array by value" { |
| 192 | 192 | |
| 193 | 193 | test "implicit comptime in array type size" { |
| 194 | 194 | var arr: [plusOne(10)]bool = undefined; |
| 195 | expect(arr.len == 11); | |
| 195 | try expect(arr.len == 11); | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | fn plusOne(x: u32) u32 { |
| ... | ... | @@ -202,52 +202,52 @@ fn plusOne(x: u32) u32 { |
| 202 | 202 | test "runtime initialize array elem and then implicit cast to slice" { |
| 203 | 203 | var two: i32 = 2; |
| 204 | 204 | const x: []const i32 = &[_]i32{two}; |
| 205 | expect(x[0] == 2); | |
| 205 | try expect(x[0] == 2); | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | test "array literal as argument to function" { |
| 209 | 209 | const S = struct { |
| 210 | fn entry(two: i32) void { | |
| 211 | foo(&[_]i32{ | |
| 210 | fn entry(two: i32) !void { | |
| 211 | try foo(&[_]i32{ | |
| 212 | 212 | 1, |
| 213 | 213 | 2, |
| 214 | 214 | 3, |
| 215 | 215 | }); |
| 216 | foo(&[_]i32{ | |
| 216 | try foo(&[_]i32{ | |
| 217 | 217 | 1, |
| 218 | 218 | two, |
| 219 | 219 | 3, |
| 220 | 220 | }); |
| 221 | foo2(true, &[_]i32{ | |
| 221 | try foo2(true, &[_]i32{ | |
| 222 | 222 | 1, |
| 223 | 223 | 2, |
| 224 | 224 | 3, |
| 225 | 225 | }); |
| 226 | foo2(true, &[_]i32{ | |
| 226 | try foo2(true, &[_]i32{ | |
| 227 | 227 | 1, |
| 228 | 228 | two, |
| 229 | 229 | 3, |
| 230 | 230 | }); |
| 231 | 231 | } |
| 232 | fn foo(x: []const i32) void { | |
| 233 | expect(x[0] == 1); | |
| 234 | expect(x[1] == 2); | |
| 235 | expect(x[2] == 3); | |
| 232 | fn foo(x: []const i32) !void { | |
| 233 | try expect(x[0] == 1); | |
| 234 | try expect(x[1] == 2); | |
| 235 | try expect(x[2] == 3); | |
| 236 | 236 | } |
| 237 | fn foo2(trash: bool, x: []const i32) void { | |
| 238 | expect(trash); | |
| 239 | expect(x[0] == 1); | |
| 240 | expect(x[1] == 2); | |
| 241 | expect(x[2] == 3); | |
| 237 | fn foo2(trash: bool, x: []const i32) !void { | |
| 238 | try expect(trash); | |
| 239 | try expect(x[0] == 1); | |
| 240 | try expect(x[1] == 2); | |
| 241 | try expect(x[2] == 3); | |
| 242 | 242 | } |
| 243 | 243 | }; |
| 244 | S.entry(2); | |
| 245 | comptime S.entry(2); | |
| 244 | try S.entry(2); | |
| 245 | comptime try S.entry(2); | |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | test "double nested array to const slice cast in array literal" { |
| 249 | 249 | const S = struct { |
| 250 | fn entry(two: i32) void { | |
| 250 | fn entry(two: i32) !void { | |
| 251 | 251 | const cases = [_][]const []const i32{ |
| 252 | 252 | &[_][]const i32{&[_]i32{1}}, |
| 253 | 253 | &[_][]const i32{&[_]i32{ 2, 3 }}, |
| ... | ... | @@ -256,18 +256,18 @@ test "double nested array to const slice cast in array literal" { |
| 256 | 256 | &[_]i32{ 5, 6, 7 }, |
| 257 | 257 | }, |
| 258 | 258 | }; |
| 259 | check(&cases); | |
| 259 | try check(&cases); | |
| 260 | 260 | |
| 261 | 261 | const cases2 = [_][]const i32{ |
| 262 | 262 | &[_]i32{1}, |
| 263 | 263 | &[_]i32{ two, 3 }, |
| 264 | 264 | }; |
| 265 | expect(cases2.len == 2); | |
| 266 | expect(cases2[0].len == 1); | |
| 267 | expect(cases2[0][0] == 1); | |
| 268 | expect(cases2[1].len == 2); | |
| 269 | expect(cases2[1][0] == 2); | |
| 270 | expect(cases2[1][1] == 3); | |
| 265 | try expect(cases2.len == 2); | |
| 266 | try expect(cases2[0].len == 1); | |
| 267 | try expect(cases2[0][0] == 1); | |
| 268 | try expect(cases2[1].len == 2); | |
| 269 | try expect(cases2[1][0] == 2); | |
| 270 | try expect(cases2[1][1] == 3); | |
| 271 | 271 | |
| 272 | 272 | const cases3 = [_][]const []const i32{ |
| 273 | 273 | &[_][]const i32{&[_]i32{1}}, |
| ... | ... | @@ -277,37 +277,37 @@ test "double nested array to const slice cast in array literal" { |
| 277 | 277 | &[_]i32{ 5, 6, 7 }, |
| 278 | 278 | }, |
| 279 | 279 | }; |
| 280 | check(&cases3); | |
| 280 | try check(&cases3); | |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | fn check(cases: []const []const []const i32) void { | |
| 284 | expect(cases.len == 3); | |
| 285 | expect(cases[0].len == 1); | |
| 286 | expect(cases[0][0].len == 1); | |
| 287 | expect(cases[0][0][0] == 1); | |
| 288 | expect(cases[1].len == 1); | |
| 289 | expect(cases[1][0].len == 2); | |
| 290 | expect(cases[1][0][0] == 2); | |
| 291 | expect(cases[1][0][1] == 3); | |
| 292 | expect(cases[2].len == 2); | |
| 293 | expect(cases[2][0].len == 1); | |
| 294 | expect(cases[2][0][0] == 4); | |
| 295 | expect(cases[2][1].len == 3); | |
| 296 | expect(cases[2][1][0] == 5); | |
| 297 | expect(cases[2][1][1] == 6); | |
| 298 | expect(cases[2][1][2] == 7); | |
| 283 | fn check(cases: []const []const []const i32) !void { | |
| 284 | try expect(cases.len == 3); | |
| 285 | try expect(cases[0].len == 1); | |
| 286 | try expect(cases[0][0].len == 1); | |
| 287 | try expect(cases[0][0][0] == 1); | |
| 288 | try expect(cases[1].len == 1); | |
| 289 | try expect(cases[1][0].len == 2); | |
| 290 | try expect(cases[1][0][0] == 2); | |
| 291 | try expect(cases[1][0][1] == 3); | |
| 292 | try expect(cases[2].len == 2); | |
| 293 | try expect(cases[2][0].len == 1); | |
| 294 | try expect(cases[2][0][0] == 4); | |
| 295 | try expect(cases[2][1].len == 3); | |
| 296 | try expect(cases[2][1][0] == 5); | |
| 297 | try expect(cases[2][1][1] == 6); | |
| 298 | try expect(cases[2][1][2] == 7); | |
| 299 | 299 | } |
| 300 | 300 | }; |
| 301 | S.entry(2); | |
| 302 | comptime S.entry(2); | |
| 301 | try S.entry(2); | |
| 302 | comptime try S.entry(2); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | test "read/write through global variable array of struct fields initialized via array mult" { |
| 306 | 306 | const S = struct { |
| 307 | fn doTheTest() void { | |
| 308 | expect(storage[0].term == 1); | |
| 307 | fn doTheTest() !void { | |
| 308 | try expect(storage[0].term == 1); | |
| 309 | 309 | storage[0] = MyStruct{ .term = 123 }; |
| 310 | expect(storage[0].term == 123); | |
| 310 | try expect(storage[0].term == 123); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | pub const MyStruct = struct { |
| ... | ... | @@ -316,34 +316,34 @@ test "read/write through global variable array of struct fields initialized via |
| 316 | 316 | |
| 317 | 317 | var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1; |
| 318 | 318 | }; |
| 319 | S.doTheTest(); | |
| 319 | try S.doTheTest(); | |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | test "implicit cast zero sized array ptr to slice" { |
| 323 | 323 | { |
| 324 | 324 | var b = "".*; |
| 325 | 325 | const c: []const u8 = &b; |
| 326 | expect(c.len == 0); | |
| 326 | try expect(c.len == 0); | |
| 327 | 327 | } |
| 328 | 328 | { |
| 329 | 329 | var b: [0]u8 = "".*; |
| 330 | 330 | const c: []const u8 = &b; |
| 331 | expect(c.len == 0); | |
| 331 | try expect(c.len == 0); | |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | test "anonymous list literal syntax" { |
| 336 | 336 | const S = struct { |
| 337 | fn doTheTest() void { | |
| 337 | fn doTheTest() !void { | |
| 338 | 338 | var array: [4]u8 = .{ 1, 2, 3, 4 }; |
| 339 | expect(array[0] == 1); | |
| 340 | expect(array[1] == 2); | |
| 341 | expect(array[2] == 3); | |
| 342 | expect(array[3] == 4); | |
| 339 | try expect(array[0] == 1); | |
| 340 | try expect(array[1] == 2); | |
| 341 | try expect(array[2] == 3); | |
| 342 | try expect(array[3] == 4); | |
| 343 | 343 | } |
| 344 | 344 | }; |
| 345 | S.doTheTest(); | |
| 346 | comptime S.doTheTest(); | |
| 345 | try S.doTheTest(); | |
| 346 | comptime try S.doTheTest(); | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | test "anonymous literal in array" { |
| ... | ... | @@ -352,51 +352,51 @@ test "anonymous literal in array" { |
| 352 | 352 | a: usize = 2, |
| 353 | 353 | b: usize = 4, |
| 354 | 354 | }; |
| 355 | fn doTheTest() void { | |
| 355 | fn doTheTest() !void { | |
| 356 | 356 | var array: [2]Foo = .{ |
| 357 | 357 | .{ .a = 3 }, |
| 358 | 358 | .{ .b = 3 }, |
| 359 | 359 | }; |
| 360 | expect(array[0].a == 3); | |
| 361 | expect(array[0].b == 4); | |
| 362 | expect(array[1].a == 2); | |
| 363 | expect(array[1].b == 3); | |
| 360 | try expect(array[0].a == 3); | |
| 361 | try expect(array[0].b == 4); | |
| 362 | try expect(array[1].a == 2); | |
| 363 | try expect(array[1].b == 3); | |
| 364 | 364 | } |
| 365 | 365 | }; |
| 366 | S.doTheTest(); | |
| 367 | comptime S.doTheTest(); | |
| 366 | try S.doTheTest(); | |
| 367 | comptime try S.doTheTest(); | |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | test "access the null element of a null terminated array" { |
| 371 | 371 | const S = struct { |
| 372 | fn doTheTest() void { | |
| 372 | fn doTheTest() !void { | |
| 373 | 373 | var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; |
| 374 | expect(array[4] == 0); | |
| 374 | try expect(array[4] == 0); | |
| 375 | 375 | var len: usize = 4; |
| 376 | expect(array[len] == 0); | |
| 376 | try expect(array[len] == 0); | |
| 377 | 377 | } |
| 378 | 378 | }; |
| 379 | S.doTheTest(); | |
| 380 | comptime S.doTheTest(); | |
| 379 | try S.doTheTest(); | |
| 380 | comptime try S.doTheTest(); | |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | test "type deduction for array subscript expression" { |
| 384 | 384 | const S = struct { |
| 385 | fn doTheTest() void { | |
| 385 | fn doTheTest() !void { | |
| 386 | 386 | var array = [_]u8{ 0x55, 0xAA }; |
| 387 | 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 | 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(); | |
| 394 | comptime S.doTheTest(); | |
| 393 | try S.doTheTest(); | |
| 394 | comptime try S.doTheTest(); | |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | test "sentinel element count towards the ABI size calculation" { |
| 398 | 398 | const S = struct { |
| 399 | fn doTheTest() void { | |
| 399 | fn doTheTest() !void { | |
| 400 | 400 | const T = packed struct { |
| 401 | 401 | fill_pre: u8 = 0x55, |
| 402 | 402 | data: [0:0]u8 = undefined, |
| ... | ... | @@ -404,14 +404,14 @@ test "sentinel element count towards the ABI size calculation" { |
| 404 | 404 | }; |
| 405 | 405 | var x = T{}; |
| 406 | 406 | var as_slice = mem.asBytes(&x); |
| 407 | expectEqual(@as(usize, 3), as_slice.len); | |
| 408 | expectEqual(@as(u8, 0x55), as_slice[0]); | |
| 409 | expectEqual(@as(u8, 0xAA), as_slice[2]); | |
| 407 | try expectEqual(@as(usize, 3), as_slice.len); | |
| 408 | try expectEqual(@as(u8, 0x55), as_slice[0]); | |
| 409 | try expectEqual(@as(u8, 0xAA), as_slice[2]); | |
| 410 | 410 | } |
| 411 | 411 | }; |
| 412 | 412 | |
| 413 | S.doTheTest(); | |
| 414 | comptime S.doTheTest(); | |
| 413 | try S.doTheTest(); | |
| 414 | comptime try S.doTheTest(); | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | test "zero-sized array with recursive type definition" { |
| ... | ... | @@ -429,61 +429,61 @@ test "zero-sized array with recursive type definition" { |
| 429 | 429 | }; |
| 430 | 430 | |
| 431 | 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 | } |
| 434 | 434 | |
| 435 | 435 | test "type coercion of anon struct literal to array" { |
| 436 | 436 | const S = struct { |
| 437 | const U = union{ | |
| 437 | const U = union { | |
| 438 | 438 | a: u32, |
| 439 | 439 | b: bool, |
| 440 | 440 | c: []const u8, |
| 441 | 441 | }; |
| 442 | 442 | |
| 443 | fn doTheTest() void { | |
| 443 | fn doTheTest() !void { | |
| 444 | 444 | var x1: u8 = 42; |
| 445 | 445 | const t1 = .{ x1, 56, 54 }; |
| 446 | 446 | var arr1: [3]u8 = t1; |
| 447 | expect(arr1[0] == 42); | |
| 448 | expect(arr1[1] == 56); | |
| 449 | expect(arr1[2] == 54); | |
| 450 | ||
| 447 | try expect(arr1[0] == 42); | |
| 448 | try expect(arr1[1] == 56); | |
| 449 | try expect(arr1[2] == 54); | |
| 450 | ||
| 451 | 451 | var x2: U = .{ .a = 42 }; |
| 452 | 452 | const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 453 | 453 | var arr2: [3]U = t2; |
| 454 | expect(arr2[0].a == 42); | |
| 455 | expect(arr2[1].b == true); | |
| 456 | expect(mem.eql(u8, arr2[2].c, "hello")); | |
| 454 | try expect(arr2[0].a == 42); | |
| 455 | try expect(arr2[1].b == true); | |
| 456 | try expect(mem.eql(u8, arr2[2].c, "hello")); | |
| 457 | 457 | } |
| 458 | 458 | }; |
| 459 | S.doTheTest(); | |
| 460 | comptime S.doTheTest(); | |
| 459 | try S.doTheTest(); | |
| 460 | comptime try S.doTheTest(); | |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | test "type coercion of pointer to anon struct literal to pointer to array" { |
| 464 | 464 | const S = struct { |
| 465 | const U = union{ | |
| 465 | const U = union { | |
| 466 | 466 | a: u32, |
| 467 | 467 | b: bool, |
| 468 | 468 | c: []const u8, |
| 469 | 469 | }; |
| 470 | 470 | |
| 471 | fn doTheTest() void { | |
| 471 | fn doTheTest() !void { | |
| 472 | 472 | var x1: u8 = 42; |
| 473 | 473 | const t1 = &.{ x1, 56, 54 }; |
| 474 | var arr1: *const[3]u8 = t1; | |
| 475 | expect(arr1[0] == 42); | |
| 476 | expect(arr1[1] == 56); | |
| 477 | expect(arr1[2] == 54); | |
| 478 | ||
| 474 | var arr1: *const [3]u8 = t1; | |
| 475 | try expect(arr1[0] == 42); | |
| 476 | try expect(arr1[1] == 56); | |
| 477 | try expect(arr1[2] == 54); | |
| 478 | ||
| 479 | 479 | var x2: U = .{ .a = 42 }; |
| 480 | 480 | const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } }; |
| 481 | 481 | var arr2: *const [3]U = t2; |
| 482 | expect(arr2[0].a == 42); | |
| 483 | expect(arr2[1].b == true); | |
| 484 | expect(mem.eql(u8, arr2[2].c, "hello")); | |
| 482 | try expect(arr2[0].a == 42); | |
| 483 | try expect(arr2[1].b == true); | |
| 484 | try expect(mem.eql(u8, arr2[2].c, "hello")); | |
| 485 | 485 | } |
| 486 | 486 | }; |
| 487 | S.doTheTest(); | |
| 488 | comptime S.doTheTest(); | |
| 487 | try S.doTheTest(); | |
| 488 | comptime try S.doTheTest(); | |
| 489 | 489 | } |
test/stage1/behavior/asm.zig+1-1| ... | ... | @@ -15,7 +15,7 @@ comptime { |
| 15 | 15 | |
| 16 | 16 | test "module level assembly" { |
| 17 | 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 | } |
| 21 | 21 |
test/stage1/behavior/async_fn.zig+165-165| ... | ... | @@ -9,12 +9,12 @@ var global_x: i32 = 1; |
| 9 | 9 | |
| 10 | 10 | test "simple coroutine suspend and resume" { |
| 11 | 11 | var frame = async simpleAsyncFn(); |
| 12 | expect(global_x == 2); | |
| 12 | try expect(global_x == 2); | |
| 13 | 13 | resume frame; |
| 14 | expect(global_x == 3); | |
| 14 | try expect(global_x == 3); | |
| 15 | 15 | const af: anyframe->void = &frame; |
| 16 | 16 | resume frame; |
| 17 | expect(global_x == 4); | |
| 17 | try expect(global_x == 4); | |
| 18 | 18 | } |
| 19 | 19 | fn simpleAsyncFn() void { |
| 20 | 20 | global_x += 1; |
| ... | ... | @@ -28,9 +28,9 @@ var global_y: i32 = 1; |
| 28 | 28 | |
| 29 | 29 | test "pass parameter to coroutine" { |
| 30 | 30 | var p = async simpleAsyncFnWithArg(2); |
| 31 | expect(global_y == 3); | |
| 31 | try expect(global_y == 3); | |
| 32 | 32 | resume p; |
| 33 | expect(global_y == 5); | |
| 33 | try expect(global_y == 5); | |
| 34 | 34 | } |
| 35 | 35 | fn simpleAsyncFnWithArg(delta: i32) void { |
| 36 | 36 | global_y += delta; |
| ... | ... | @@ -42,10 +42,10 @@ test "suspend at end of function" { |
| 42 | 42 | const S = struct { |
| 43 | 43 | var x: i32 = 1; |
| 44 | 44 | |
| 45 | fn doTheTest() void { | |
| 46 | expect(x == 1); | |
| 45 | fn doTheTest() !void { | |
| 46 | try expect(x == 1); | |
| 47 | 47 | const p = async suspendAtEnd(); |
| 48 | expect(x == 2); | |
| 48 | try expect(x == 2); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | fn suspendAtEnd() void { |
| ... | ... | @@ -53,23 +53,23 @@ test "suspend at end of function" { |
| 53 | 53 | suspend {} |
| 54 | 54 | } |
| 55 | 55 | }; |
| 56 | S.doTheTest(); | |
| 56 | try S.doTheTest(); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | test "local variable in async function" { |
| 60 | 60 | const S = struct { |
| 61 | 61 | var x: i32 = 0; |
| 62 | 62 | |
| 63 | fn doTheTest() void { | |
| 64 | expect(x == 0); | |
| 63 | fn doTheTest() !void { | |
| 64 | try expect(x == 0); | |
| 65 | 65 | var p = async add(1, 2); |
| 66 | expect(x == 0); | |
| 66 | try expect(x == 0); | |
| 67 | 67 | resume p; |
| 68 | expect(x == 0); | |
| 68 | try expect(x == 0); | |
| 69 | 69 | resume p; |
| 70 | expect(x == 0); | |
| 70 | try expect(x == 0); | |
| 71 | 71 | resume p; |
| 72 | expect(x == 3); | |
| 72 | try expect(x == 3); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | fn add(a: i32, b: i32) void { |
| ... | ... | @@ -82,7 +82,7 @@ test "local variable in async function" { |
| 82 | 82 | x = accum; |
| 83 | 83 | } |
| 84 | 84 | }; |
| 85 | S.doTheTest(); | |
| 85 | try S.doTheTest(); | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | test "calling an inferred async function" { |
| ... | ... | @@ -90,11 +90,11 @@ test "calling an inferred async function" { |
| 90 | 90 | var x: i32 = 1; |
| 91 | 91 | var other_frame: *@Frame(other) = undefined; |
| 92 | 92 | |
| 93 | fn doTheTest() void { | |
| 93 | fn doTheTest() !void { | |
| 94 | 94 | _ = async first(); |
| 95 | expect(x == 1); | |
| 95 | try expect(x == 1); | |
| 96 | 96 | resume other_frame.*; |
| 97 | expect(x == 2); | |
| 97 | try expect(x == 2); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | fn first() void { |
| ... | ... | @@ -106,7 +106,7 @@ test "calling an inferred async function" { |
| 106 | 106 | x += 1; |
| 107 | 107 | } |
| 108 | 108 | }; |
| 109 | S.doTheTest(); | |
| 109 | try S.doTheTest(); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "@frameSize" { |
| ... | ... | @@ -114,16 +114,16 @@ test "@frameSize" { |
| 114 | 114 | return error.SkipZigTest; |
| 115 | 115 | |
| 116 | 116 | const S = struct { |
| 117 | fn doTheTest() void { | |
| 117 | fn doTheTest() !void { | |
| 118 | 118 | { |
| 119 | 119 | var ptr = @ptrCast(fn (i32) callconv(.Async) void, other); |
| 120 | 120 | const size = @frameSize(ptr); |
| 121 | expect(size == @sizeOf(@Frame(other))); | |
| 121 | try expect(size == @sizeOf(@Frame(other))); | |
| 122 | 122 | } |
| 123 | 123 | { |
| 124 | 124 | var ptr = @ptrCast(fn () callconv(.Async) void, first); |
| 125 | 125 | const size = @frameSize(ptr); |
| 126 | expect(size == @sizeOf(@Frame(first))); | |
| 126 | try expect(size == @sizeOf(@Frame(first))); | |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| ... | ... | @@ -135,20 +135,20 @@ test "@frameSize" { |
| 135 | 135 | suspend {} |
| 136 | 136 | } |
| 137 | 137 | }; |
| 138 | S.doTheTest(); | |
| 138 | try S.doTheTest(); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "coroutine suspend, resume" { |
| 142 | 142 | const S = struct { |
| 143 | 143 | var frame: anyframe = undefined; |
| 144 | 144 | |
| 145 | fn doTheTest() void { | |
| 145 | fn doTheTest() !void { | |
| 146 | 146 | _ = async amain(); |
| 147 | 147 | seq('d'); |
| 148 | 148 | resume frame; |
| 149 | 149 | seq('h'); |
| 150 | 150 | |
| 151 | expect(std.mem.eql(u8, &points, "abcdefgh")); | |
| 151 | try expect(std.mem.eql(u8, &points, "abcdefgh")); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | fn amain() void { |
| ... | ... | @@ -176,27 +176,27 @@ test "coroutine suspend, resume" { |
| 176 | 176 | index += 1; |
| 177 | 177 | } |
| 178 | 178 | }; |
| 179 | S.doTheTest(); | |
| 179 | try S.doTheTest(); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | test "coroutine suspend with block" { |
| 183 | 183 | const p = async testSuspendBlock(); |
| 184 | expect(!global_result); | |
| 184 | try expect(!global_result); | |
| 185 | 185 | resume a_promise; |
| 186 | expect(global_result); | |
| 186 | try expect(global_result); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | var a_promise: anyframe = undefined; |
| 190 | 190 | var global_result = false; |
| 191 | 191 | fn testSuspendBlock() callconv(.Async) void { |
| 192 | 192 | suspend { |
| 193 | comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 193 | comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable; | |
| 194 | 194 | a_promise = @frame(); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Test to make sure that @frame() works as advertised (issue #1296) |
| 198 | 198 | // var our_handle: anyframe = @frame(); |
| 199 | expect(a_promise == @as(anyframe, @frame())); | |
| 199 | expect(a_promise == @as(anyframe, @frame())) catch @panic("test failed"); | |
| 200 | 200 | |
| 201 | 201 | global_result = true; |
| 202 | 202 | } |
| ... | ... | @@ -210,8 +210,8 @@ test "coroutine await" { |
| 210 | 210 | await_seq('f'); |
| 211 | 211 | resume await_a_promise; |
| 212 | 212 | await_seq('i'); |
| 213 | expect(await_final_result == 1234); | |
| 214 | expect(std.mem.eql(u8, &await_points, "abcdefghi")); | |
| 213 | try expect(await_final_result == 1234); | |
| 214 | try expect(std.mem.eql(u8, &await_points, "abcdefghi")); | |
| 215 | 215 | } |
| 216 | 216 | fn await_amain() callconv(.Async) void { |
| 217 | 217 | await_seq('b'); |
| ... | ... | @@ -244,8 +244,8 @@ test "coroutine await early return" { |
| 244 | 244 | early_seq('a'); |
| 245 | 245 | var p = async early_amain(); |
| 246 | 246 | early_seq('f'); |
| 247 | expect(early_final_result == 1234); | |
| 248 | expect(std.mem.eql(u8, &early_points, "abcdef")); | |
| 247 | try expect(early_final_result == 1234); | |
| 248 | try expect(std.mem.eql(u8, &early_points, "abcdef")); | |
| 249 | 249 | } |
| 250 | 250 | fn early_amain() callconv(.Async) void { |
| 251 | 251 | early_seq('b'); |
| ... | ... | @@ -276,7 +276,7 @@ test "async function with dot syntax" { |
| 276 | 276 | } |
| 277 | 277 | }; |
| 278 | 278 | const p = async S.foo(); |
| 279 | expect(S.y == 2); | |
| 279 | try expect(S.y == 2); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | test "async fn pointer in a struct field" { |
| ... | ... | @@ -287,12 +287,12 @@ test "async fn pointer in a struct field" { |
| 287 | 287 | var foo = Foo{ .bar = simpleAsyncFn2 }; |
| 288 | 288 | var bytes: [64]u8 align(16) = undefined; |
| 289 | 289 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 290 | comptime expect(@TypeOf(f) == anyframe->void); | |
| 291 | expect(data == 2); | |
| 290 | comptime try expect(@TypeOf(f) == anyframe->void); | |
| 291 | try expect(data == 2); | |
| 292 | 292 | resume f; |
| 293 | expect(data == 4); | |
| 293 | try expect(data == 4); | |
| 294 | 294 | _ = async doTheAwait(f); |
| 295 | expect(data == 4); | |
| 295 | try expect(data == 4); | |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | fn doTheAwait(f: anyframe->void) void { |
| ... | ... | @@ -323,22 +323,22 @@ test "@asyncCall with return type" { |
| 323 | 323 | var bytes: [150]u8 align(16) = undefined; |
| 324 | 324 | var aresult: i32 = 0; |
| 325 | 325 | _ = @asyncCall(&bytes, &aresult, foo.bar, .{}); |
| 326 | expect(aresult == 0); | |
| 326 | try expect(aresult == 0); | |
| 327 | 327 | resume Foo.global_frame; |
| 328 | expect(aresult == 1234); | |
| 328 | try expect(aresult == 1234); | |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | test "async fn with inferred error set" { |
| 332 | 332 | const S = struct { |
| 333 | 333 | var global_frame: anyframe = undefined; |
| 334 | 334 | |
| 335 | fn doTheTest() void { | |
| 335 | fn doTheTest() !void { | |
| 336 | 336 | var frame: [1]@Frame(middle) = undefined; |
| 337 | 337 | var fn_ptr = middle; |
| 338 | 338 | var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; |
| 339 | 339 | _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{}); |
| 340 | 340 | resume global_frame; |
| 341 | std.testing.expectError(error.Fail, result); | |
| 341 | try std.testing.expectError(error.Fail, result); | |
| 342 | 342 | } |
| 343 | 343 | fn middle() callconv(.Async) !void { |
| 344 | 344 | var f = async middle2(); |
| ... | ... | @@ -355,7 +355,7 @@ test "async fn with inferred error set" { |
| 355 | 355 | return error.Fail; |
| 356 | 356 | } |
| 357 | 357 | }; |
| 358 | S.doTheTest(); | |
| 358 | try S.doTheTest(); | |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | test "error return trace across suspend points - early return" { |
| ... | ... | @@ -383,9 +383,9 @@ fn suspendThenFail() callconv(.Async) anyerror!void { |
| 383 | 383 | } |
| 384 | 384 | fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void { |
| 385 | 385 | (await p) catch |e| { |
| 386 | std.testing.expect(e == error.Fail); | |
| 386 | std.testing.expect(e == error.Fail) catch @panic("test failure"); | |
| 387 | 387 | if (@errorReturnTrace()) |trace| { |
| 388 | expect(trace.index == 1); | |
| 388 | expect(trace.index == 1) catch @panic("test failure"); | |
| 389 | 389 | } else switch (builtin.mode) { |
| 390 | 390 | .Debug, .ReleaseSafe => @panic("expected return trace"), |
| 391 | 391 | .ReleaseFast, .ReleaseSmall => {}, |
| ... | ... | @@ -396,7 +396,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void { |
| 396 | 396 | test "break from suspend" { |
| 397 | 397 | var my_result: i32 = 1; |
| 398 | 398 | const p = async testBreakFromSuspend(&my_result); |
| 399 | std.testing.expect(my_result == 2); | |
| 399 | try std.testing.expect(my_result == 2); | |
| 400 | 400 | } |
| 401 | 401 | fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void { |
| 402 | 402 | suspend { |
| ... | ... | @@ -415,11 +415,11 @@ test "heap allocated async function frame" { |
| 415 | 415 | const frame = try std.testing.allocator.create(@Frame(someFunc)); |
| 416 | 416 | defer std.testing.allocator.destroy(frame); |
| 417 | 417 | |
| 418 | expect(x == 42); | |
| 418 | try expect(x == 42); | |
| 419 | 419 | frame.* = async someFunc(); |
| 420 | expect(x == 43); | |
| 420 | try expect(x == 43); | |
| 421 | 421 | resume frame; |
| 422 | expect(x == 44); | |
| 422 | try expect(x == 44); | |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | fn someFunc() void { |
| ... | ... | @@ -436,15 +436,15 @@ test "async function call return value" { |
| 436 | 436 | var frame: anyframe = undefined; |
| 437 | 437 | var pt = Point{ .x = 10, .y = 11 }; |
| 438 | 438 | |
| 439 | fn doTheTest() void { | |
| 440 | expectEqual(pt.x, 10); | |
| 441 | expectEqual(pt.y, 11); | |
| 439 | fn doTheTest() !void { | |
| 440 | try expectEqual(pt.x, 10); | |
| 441 | try expectEqual(pt.y, 11); | |
| 442 | 442 | _ = async first(); |
| 443 | expectEqual(pt.x, 10); | |
| 444 | expectEqual(pt.y, 11); | |
| 443 | try expectEqual(pt.x, 10); | |
| 444 | try expectEqual(pt.y, 11); | |
| 445 | 445 | resume frame; |
| 446 | expectEqual(pt.x, 1); | |
| 447 | expectEqual(pt.y, 2); | |
| 446 | try expectEqual(pt.x, 1); | |
| 447 | try expectEqual(pt.y, 2); | |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | fn first() void { |
| ... | ... | @@ -469,23 +469,23 @@ test "async function call return value" { |
| 469 | 469 | y: i32, |
| 470 | 470 | }; |
| 471 | 471 | }; |
| 472 | S.doTheTest(); | |
| 472 | try S.doTheTest(); | |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | test "suspension points inside branching control flow" { |
| 476 | 476 | const S = struct { |
| 477 | 477 | var result: i32 = 10; |
| 478 | 478 | |
| 479 | fn doTheTest() void { | |
| 480 | expect(10 == result); | |
| 479 | fn doTheTest() !void { | |
| 480 | try expect(10 == result); | |
| 481 | 481 | var frame = async func(true); |
| 482 | expect(10 == result); | |
| 482 | try expect(10 == result); | |
| 483 | 483 | resume frame; |
| 484 | expect(11 == result); | |
| 484 | try expect(11 == result); | |
| 485 | 485 | resume frame; |
| 486 | expect(12 == result); | |
| 486 | try expect(12 == result); | |
| 487 | 487 | resume frame; |
| 488 | expect(13 == result); | |
| 488 | try expect(13 == result); | |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | fn func(b: bool) void { |
| ... | ... | @@ -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 | } |
| 500 | 500 | |
| 501 | 501 | test "call async function which has struct return type" { |
| ... | ... | @@ -509,8 +509,8 @@ test "call async function which has struct return type" { |
| 509 | 509 | |
| 510 | 510 | fn atest() void { |
| 511 | 511 | const result = func(); |
| 512 | expect(result.x == 5); | |
| 513 | expect(result.y == 6); | |
| 512 | expect(result.x == 5) catch @panic("test failed"); | |
| 513 | expect(result.y == 6) catch @panic("test failed"); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | const Point = struct { |
| ... | ... | @@ -536,27 +536,27 @@ test "pass string literal to async function" { |
| 536 | 536 | var frame: anyframe = undefined; |
| 537 | 537 | var ok: bool = false; |
| 538 | 538 | |
| 539 | fn doTheTest() void { | |
| 539 | fn doTheTest() !void { | |
| 540 | 540 | _ = async hello("hello"); |
| 541 | 541 | resume frame; |
| 542 | expect(ok); | |
| 542 | try expect(ok); | |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | fn hello(msg: []const u8) void { |
| 546 | 546 | frame = @frame(); |
| 547 | 547 | suspend {} |
| 548 | expectEqualStrings("hello", msg); | |
| 548 | expectEqualStrings("hello", msg) catch @panic("test failed"); | |
| 549 | 549 | ok = true; |
| 550 | 550 | } |
| 551 | 551 | }; |
| 552 | S.doTheTest(); | |
| 552 | try S.doTheTest(); | |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | test "await inside an errdefer" { |
| 556 | 556 | const S = struct { |
| 557 | 557 | var frame: anyframe = undefined; |
| 558 | 558 | |
| 559 | fn doTheTest() void { | |
| 559 | fn doTheTest() !void { | |
| 560 | 560 | _ = async amainWrap(); |
| 561 | 561 | resume frame; |
| 562 | 562 | } |
| ... | ... | @@ -572,7 +572,7 @@ test "await inside an errdefer" { |
| 572 | 572 | suspend {} |
| 573 | 573 | } |
| 574 | 574 | }; |
| 575 | S.doTheTest(); | |
| 575 | try S.doTheTest(); | |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | 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 | 580 | var frame: anyframe = undefined; |
| 581 | 581 | var ok = false; |
| 582 | 582 | |
| 583 | fn doTheTest() void { | |
| 583 | fn doTheTest() !void { | |
| 584 | 584 | _ = async amain(); |
| 585 | 585 | resume frame; |
| 586 | expect(ok); | |
| 586 | try expect(ok); | |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | fn amain() void { |
| 590 | std.testing.expectError(error.Bad, theProblem()); | |
| 590 | std.testing.expectError(error.Bad, theProblem()) catch @panic("test failed"); | |
| 591 | 591 | ok = true; |
| 592 | 592 | } |
| 593 | 593 | |
| ... | ... | @@ -602,7 +602,7 @@ test "try in an async function with error union and non-zero-bit payload" { |
| 602 | 602 | return error.Bad; |
| 603 | 603 | } |
| 604 | 604 | }; |
| 605 | S.doTheTest(); | |
| 605 | try S.doTheTest(); | |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | test "returning a const error from async function" { |
| ... | ... | @@ -610,10 +610,10 @@ test "returning a const error from async function" { |
| 610 | 610 | var frame: anyframe = undefined; |
| 611 | 611 | var ok = false; |
| 612 | 612 | |
| 613 | fn doTheTest() void { | |
| 613 | fn doTheTest() !void { | |
| 614 | 614 | _ = async amain(); |
| 615 | 615 | resume frame; |
| 616 | expect(ok); | |
| 616 | try expect(ok); | |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | fn amain() !void { |
| ... | ... | @@ -630,7 +630,7 @@ test "returning a const error from async function" { |
| 630 | 630 | return error.OutOfMemory; |
| 631 | 631 | } |
| 632 | 632 | }; |
| 633 | S.doTheTest(); | |
| 633 | try S.doTheTest(); | |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | test "async/await typical usage" { |
| ... | ... | @@ -663,11 +663,11 @@ fn testAsyncAwaitTypicalUsage( |
| 663 | 663 | } |
| 664 | 664 | fn amainWrap() void { |
| 665 | 665 | if (amain()) |_| { |
| 666 | expect(!simulate_fail_download); | |
| 667 | expect(!simulate_fail_file); | |
| 666 | expect(!simulate_fail_download) catch @panic("test failure"); | |
| 667 | expect(!simulate_fail_file) catch @panic("test failure"); | |
| 668 | 668 | } else |e| switch (e) { |
| 669 | error.NoResponse => expect(simulate_fail_download), | |
| 670 | error.FileNotFound => expect(simulate_fail_file), | |
| 669 | error.NoResponse => expect(simulate_fail_download) catch @panic("test failure"), | |
| 670 | error.FileNotFound => expect(simulate_fail_file) catch @panic("test failure"), | |
| 671 | 671 | else => @panic("test failure"), |
| 672 | 672 | } |
| 673 | 673 | } |
| ... | ... | @@ -694,8 +694,8 @@ fn testAsyncAwaitTypicalUsage( |
| 694 | 694 | const file_text = try await file_frame; |
| 695 | 695 | defer allocator.free(file_text); |
| 696 | 696 | |
| 697 | expect(std.mem.eql(u8, "expected download text", download_text)); | |
| 698 | expect(std.mem.eql(u8, "expected file text", file_text)); | |
| 697 | try expect(std.mem.eql(u8, "expected download text", download_text)); | |
| 698 | try expect(std.mem.eql(u8, "expected file text", file_text)); | |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | var global_download_frame: anyframe = undefined; |
| ... | ... | @@ -728,13 +728,13 @@ fn testAsyncAwaitTypicalUsage( |
| 728 | 728 | |
| 729 | 729 | test "alignment of local variables in async functions" { |
| 730 | 730 | const S = struct { |
| 731 | fn doTheTest() void { | |
| 731 | fn doTheTest() !void { | |
| 732 | 732 | var y: u8 = 123; |
| 733 | 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 | } |
| 739 | 739 | |
| 740 | 740 | test "no reason to resolve frame still works" { |
| ... | ... | @@ -746,10 +746,10 @@ fn simpleNothing() void { |
| 746 | 746 | |
| 747 | 747 | test "async call a generic function" { |
| 748 | 748 | const S = struct { |
| 749 | fn doTheTest() void { | |
| 749 | fn doTheTest() !void { | |
| 750 | 750 | var f = async func(i32, 2); |
| 751 | 751 | const result = await f; |
| 752 | expect(result == 3); | |
| 752 | try expect(result == 3); | |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | fn func(comptime T: type, inc: T) T { |
| ... | ... | @@ -766,8 +766,8 @@ test "async call a generic function" { |
| 766 | 766 | |
| 767 | 767 | test "return from suspend block" { |
| 768 | 768 | const S = struct { |
| 769 | fn doTheTest() void { | |
| 770 | expect(func() == 1234); | |
| 769 | fn doTheTest() !void { | |
| 770 | expect(func() == 1234) catch @panic("test failure"); | |
| 771 | 771 | } |
| 772 | 772 | fn func() i32 { |
| 773 | 773 | suspend { |
| ... | ... | @@ -808,7 +808,7 @@ test "struct parameter to async function is copied to the frame" { |
| 808 | 808 | var pt = Point{ .x = 1, .y = 2 }; |
| 809 | 809 | f.* = async foo(pt); |
| 810 | 810 | var result = await f; |
| 811 | expect(result == 1); | |
| 811 | expect(result == 1) catch @panic("test failure"); | |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | fn foo(point: Point) i32 { |
| ... | ... | @@ -833,7 +833,7 @@ test "cast fn to async fn when it is inferred to be async" { |
| 833 | 833 | var result: i32 = undefined; |
| 834 | 834 | const f = @asyncCall(&buf, &result, ptr, .{}); |
| 835 | 835 | _ = await f; |
| 836 | expect(result == 1234); | |
| 836 | expect(result == 1234) catch @panic("test failure"); | |
| 837 | 837 | ok = true; |
| 838 | 838 | } |
| 839 | 839 | |
| ... | ... | @@ -846,7 +846,7 @@ test "cast fn to async fn when it is inferred to be async" { |
| 846 | 846 | }; |
| 847 | 847 | _ = async S.doTheTest(); |
| 848 | 848 | resume S.frame; |
| 849 | expect(S.ok); | |
| 849 | try expect(S.ok); | |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | 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 | 860 | var buf: [100]u8 align(16) = undefined; |
| 861 | 861 | var result: i32 = undefined; |
| 862 | 862 | _ = await @asyncCall(&buf, &result, ptr, .{}); |
| 863 | expect(result == 1234); | |
| 863 | expect(result == 1234) catch @panic("test failure"); | |
| 864 | 864 | ok = true; |
| 865 | 865 | } |
| 866 | 866 | |
| ... | ... | @@ -873,7 +873,7 @@ test "cast fn to async fn when it is inferred to be async, awaited directly" { |
| 873 | 873 | }; |
| 874 | 874 | _ = async S.doTheTest(); |
| 875 | 875 | resume S.frame; |
| 876 | expect(S.ok); | |
| 876 | try expect(S.ok); | |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | 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 | 885 | var x = async S.simple(); |
| 886 | expect(await x == 1234); | |
| 886 | try expect(await x == 1234); | |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | test "recursive async function" { |
| 890 | expect(recursiveAsyncFunctionTest(false).doTheTest() == 55); | |
| 891 | expect(recursiveAsyncFunctionTest(true).doTheTest() == 55); | |
| 890 | try expect(recursiveAsyncFunctionTest(false).doTheTest() == 55); | |
| 891 | try expect(recursiveAsyncFunctionTest(true).doTheTest() == 55); | |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type { |
| ... | ... | @@ -952,12 +952,12 @@ test "@asyncCall with comptime-known function, but not awaited directly" { |
| 952 | 952 | const S = struct { |
| 953 | 953 | var global_frame: anyframe = undefined; |
| 954 | 954 | |
| 955 | fn doTheTest() void { | |
| 955 | fn doTheTest() !void { | |
| 956 | 956 | var frame: [1]@Frame(middle) = undefined; |
| 957 | 957 | var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined; |
| 958 | 958 | _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{}); |
| 959 | 959 | resume global_frame; |
| 960 | std.testing.expectError(error.Fail, result); | |
| 960 | try std.testing.expectError(error.Fail, result); | |
| 961 | 961 | } |
| 962 | 962 | fn middle() callconv(.Async) !void { |
| 963 | 963 | var f = async middle2(); |
| ... | ... | @@ -974,7 +974,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" { |
| 974 | 974 | return error.Fail; |
| 975 | 975 | } |
| 976 | 976 | }; |
| 977 | S.doTheTest(); | |
| 977 | try S.doTheTest(); | |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | test "@asyncCall with actual frame instead of byte buffer" { |
| ... | ... | @@ -988,7 +988,7 @@ test "@asyncCall with actual frame instead of byte buffer" { |
| 988 | 988 | var result: i32 = undefined; |
| 989 | 989 | const ptr = @asyncCall(&frame, &result, S.func, .{}); |
| 990 | 990 | resume ptr; |
| 991 | expect(result == 1234); | |
| 991 | try expect(result == 1234); | |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | test "@asyncCall using the result location inside the frame" { |
| ... | ... | @@ -1010,19 +1010,19 @@ test "@asyncCall using the result location inside the frame" { |
| 1010 | 1010 | var foo = Foo{ .bar = S.simple2 }; |
| 1011 | 1011 | var bytes: [64]u8 align(16) = undefined; |
| 1012 | 1012 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 1013 | comptime expect(@TypeOf(f) == anyframe->i32); | |
| 1014 | expect(data == 2); | |
| 1013 | comptime try expect(@TypeOf(f) == anyframe->i32); | |
| 1014 | try expect(data == 2); | |
| 1015 | 1015 | resume f; |
| 1016 | expect(data == 4); | |
| 1016 | try expect(data == 4); | |
| 1017 | 1017 | _ = async S.getAnswer(f, &data); |
| 1018 | expect(data == 1234); | |
| 1018 | try expect(data == 1234); | |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | test "@TypeOf an async function call of generic fn with error union type" { |
| 1022 | 1022 | const S = struct { |
| 1023 | 1023 | fn func(comptime x: anytype) anyerror!i32 { |
| 1024 | 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 | 1026 | return undefined; |
| 1027 | 1027 | } |
| 1028 | 1028 | }; |
| ... | ... | @@ -1051,7 +1051,7 @@ test "using @TypeOf on a generic function call" { |
| 1051 | 1051 | }; |
| 1052 | 1052 | _ = async S.amain(@as(u32, 1)); |
| 1053 | 1053 | resume S.global_frame; |
| 1054 | expect(S.global_ok); | |
| 1054 | try expect(S.global_ok); | |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | 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 | 1084 | var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined; |
| 1085 | 1085 | _ = @asyncCall(&frame, &res, S.amain, .{@as(u32, 1)}); |
| 1086 | 1086 | resume S.global_frame; |
| 1087 | expect(S.global_ok); | |
| 1088 | expect(res.x == 1); | |
| 1089 | expect(res.y == 2); | |
| 1090 | expect(res.z == 3); | |
| 1087 | try expect(S.global_ok); | |
| 1088 | try expect(res.x == 1); | |
| 1089 | try expect(res.y == 2); | |
| 1090 | try expect(res.z == 3); | |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | test "nosuspend function call" { |
| 1094 | 1094 | const S = struct { |
| 1095 | fn doTheTest() void { | |
| 1095 | fn doTheTest() !void { | |
| 1096 | 1096 | const result = nosuspend add(50, 100); |
| 1097 | expect(result == 150); | |
| 1097 | try expect(result == 150); | |
| 1098 | 1098 | } |
| 1099 | 1099 | fn add(a: i32, b: i32) i32 { |
| 1100 | 1100 | if (a > 100) { |
| ... | ... | @@ -1103,7 +1103,7 @@ test "nosuspend function call" { |
| 1103 | 1103 | return a + b; |
| 1104 | 1104 | } |
| 1105 | 1105 | }; |
| 1106 | S.doTheTest(); | |
| 1106 | try S.doTheTest(); | |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | test "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 | 1113 | var f2 = async add(3, 4); |
| 1114 | 1114 | |
| 1115 | 1115 | const sum = (await f1) + (await f2); |
| 1116 | expect(sum == 10); | |
| 1116 | expect(sum == 10) catch @panic("test failure"); | |
| 1117 | 1117 | } |
| 1118 | 1118 | fn add(a: i32, b: i32) callconv(.Async) i32 { |
| 1119 | 1119 | return a + b; |
| ... | ... | @@ -1128,7 +1128,7 @@ test "await used in expression after a fn call" { |
| 1128 | 1128 | var f1 = async add(3, 4); |
| 1129 | 1129 | var sum: i32 = 0; |
| 1130 | 1130 | sum = foo() + await f1; |
| 1131 | expect(sum == 8); | |
| 1131 | expect(sum == 8) catch @panic("test failure"); | |
| 1132 | 1132 | } |
| 1133 | 1133 | fn add(a: i32, b: i32) callconv(.Async) i32 { |
| 1134 | 1134 | return a + b; |
| ... | ... | @@ -1145,7 +1145,7 @@ test "async fn call used in expression after a fn call" { |
| 1145 | 1145 | fn atest() void { |
| 1146 | 1146 | var sum: i32 = 0; |
| 1147 | 1147 | sum = foo() + add(3, 4); |
| 1148 | expect(sum == 8); | |
| 1148 | expect(sum == 8) catch @panic("test failure"); | |
| 1149 | 1149 | } |
| 1150 | 1150 | fn add(a: i32, b: i32) callconv(.Async) i32 { |
| 1151 | 1151 | return a + b; |
| ... | ... | @@ -1167,7 +1167,7 @@ test "suspend in for loop" { |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 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 | 1172 | fn func(stuff: []const u8) u32 { |
| 1173 | 1173 | global_frame = @frame(); |
| ... | ... | @@ -1193,8 +1193,8 @@ test "suspend in while loop" { |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | fn atest() void { |
| 1196 | expect(optional(6) == 6); | |
| 1197 | expect(errunion(6) == 6); | |
| 1196 | expect(optional(6) == 6) catch @panic("test failure"); | |
| 1197 | expect(errunion(6) == 6) catch @panic("test failure"); | |
| 1198 | 1198 | } |
| 1199 | 1199 | fn optional(stuff: ?u32) u32 { |
| 1200 | 1200 | global_frame = @frame(); |
| ... | ... | @@ -1223,8 +1223,8 @@ test "correctly spill when returning the error union result of another async fn" |
| 1223 | 1223 | const S = struct { |
| 1224 | 1224 | var global_frame: anyframe = undefined; |
| 1225 | 1225 | |
| 1226 | fn doTheTest() void { | |
| 1227 | expect((atest() catch unreachable) == 1234); | |
| 1226 | fn doTheTest() !void { | |
| 1227 | expect((atest() catch unreachable) == 1234) catch @panic("test failure"); | |
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | fn atest() !i32 { |
| ... | ... | @@ -1246,11 +1246,11 @@ test "spill target expr in a for loop" { |
| 1246 | 1246 | const S = struct { |
| 1247 | 1247 | var global_frame: anyframe = undefined; |
| 1248 | 1248 | |
| 1249 | fn doTheTest() void { | |
| 1249 | fn doTheTest() !void { | |
| 1250 | 1250 | var foo = Foo{ |
| 1251 | 1251 | .slice = &[_]i32{ 1, 2 }, |
| 1252 | 1252 | }; |
| 1253 | expect(atest(&foo) == 3); | |
| 1253 | expect(atest(&foo) == 3) catch @panic("test failure"); | |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 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 | 1277 | const S = struct { |
| 1278 | 1278 | var global_frame: anyframe = undefined; |
| 1279 | 1279 | |
| 1280 | fn doTheTest() void { | |
| 1280 | fn doTheTest() !void { | |
| 1281 | 1281 | var foo = Foo{ |
| 1282 | 1282 | .slice = &[_]i32{ 1, 2 }, |
| 1283 | 1283 | }; |
| 1284 | expect(atest(&foo) == 3); | |
| 1284 | expect(atest(&foo) == 3) catch @panic("test failure"); | |
| 1285 | 1285 | } |
| 1286 | 1286 | |
| 1287 | 1287 | const Foo = struct { |
| ... | ... | @@ -1319,7 +1319,7 @@ test "async call with @call" { |
| 1319 | 1319 | fn atest() void { |
| 1320 | 1320 | var frame = @call(.{ .modifier = .async_kw }, afoo, .{}); |
| 1321 | 1321 | const res = await frame; |
| 1322 | expect(res == 42); | |
| 1322 | expect(res == 42) catch @panic("test failure"); | |
| 1323 | 1323 | } |
| 1324 | 1324 | fn afoo() i32 { |
| 1325 | 1325 | suspend { |
| ... | ... | @@ -1348,7 +1348,7 @@ test "async function passed 0-bit arg after non-0-bit arg" { |
| 1348 | 1348 | }; |
| 1349 | 1349 | _ = async S.foo(); |
| 1350 | 1350 | resume S.global_frame; |
| 1351 | expect(S.global_int == 1); | |
| 1351 | try expect(S.global_int == 1); | |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | 1354 | 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 | } |
| 1363 | 1363 | |
| 1364 | 1364 | fn bar(x: u64, args: anytype) anyerror!void { |
| 1365 | expect(x == 10); | |
| 1365 | try expect(x == 10); | |
| 1366 | 1366 | global_frame = @frame(); |
| 1367 | 1367 | suspend {} |
| 1368 | 1368 | global_int = args[0]; |
| ... | ... | @@ -1370,7 +1370,7 @@ test "async function passed align(16) arg after align(8) arg" { |
| 1370 | 1370 | }; |
| 1371 | 1371 | _ = async S.foo(); |
| 1372 | 1372 | resume S.global_frame; |
| 1373 | expect(S.global_int == 99); | |
| 1373 | try expect(S.global_int == 99); | |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | 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 | 1393 | _ = async S.foo(); |
| 1394 | 1394 | resume S.global_frame; |
| 1395 | expect(S.global_int == 10); | |
| 1395 | try expect(S.global_int == 10); | |
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | 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 | 1416 | _ = async S.foo(); |
| 1417 | 1417 | resume S.global_frame; |
| 1418 | expect(S.global_int == 10); | |
| 1418 | try expect(S.global_int == 10); | |
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | 1421 | test "properly spill optional payload capture value" { |
| ... | ... | @@ -1439,7 +1439,7 @@ test "properly spill optional payload capture value" { |
| 1439 | 1439 | }; |
| 1440 | 1440 | _ = async S.foo(); |
| 1441 | 1441 | resume S.global_frame; |
| 1442 | expect(S.global_int == 1237); | |
| 1442 | try expect(S.global_int == 1237); | |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | test "handle defer interfering with return value spill" { |
| ... | ... | @@ -1449,16 +1449,16 @@ test "handle defer interfering with return value spill" { |
| 1449 | 1449 | var finished = false; |
| 1450 | 1450 | var baz_happened = false; |
| 1451 | 1451 | |
| 1452 | fn doTheTest() void { | |
| 1452 | fn doTheTest() !void { | |
| 1453 | 1453 | _ = async testFoo(); |
| 1454 | 1454 | resume global_frame1; |
| 1455 | 1455 | resume global_frame2; |
| 1456 | expect(baz_happened); | |
| 1457 | expect(finished); | |
| 1456 | try expect(baz_happened); | |
| 1457 | try expect(finished); | |
| 1458 | 1458 | } |
| 1459 | 1459 | |
| 1460 | 1460 | fn testFoo() void { |
| 1461 | expectError(error.Bad, foo()); | |
| 1461 | expectError(error.Bad, foo()) catch @panic("test failure"); | |
| 1462 | 1462 | finished = true; |
| 1463 | 1463 | } |
| 1464 | 1464 | |
| ... | ... | @@ -1479,7 +1479,7 @@ test "handle defer interfering with return value spill" { |
| 1479 | 1479 | baz_happened = true; |
| 1480 | 1480 | } |
| 1481 | 1481 | }; |
| 1482 | S.doTheTest(); | |
| 1482 | try S.doTheTest(); | |
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | test "take address of temporary async frame" { |
| ... | ... | @@ -1487,14 +1487,14 @@ test "take address of temporary async frame" { |
| 1487 | 1487 | var global_frame: anyframe = undefined; |
| 1488 | 1488 | var finished = false; |
| 1489 | 1489 | |
| 1490 | fn doTheTest() void { | |
| 1490 | fn doTheTest() !void { | |
| 1491 | 1491 | _ = async asyncDoTheTest(); |
| 1492 | 1492 | resume global_frame; |
| 1493 | expect(finished); | |
| 1493 | try expect(finished); | |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | fn asyncDoTheTest() void { |
| 1497 | expect(finishIt(&async foo(10)) == 1245); | |
| 1497 | expect(finishIt(&async foo(10)) == 1245) catch @panic("test failure"); | |
| 1498 | 1498 | finished = true; |
| 1499 | 1499 | } |
| 1500 | 1500 | |
| ... | ... | @@ -1508,16 +1508,16 @@ test "take address of temporary async frame" { |
| 1508 | 1508 | return (await frame) + 1; |
| 1509 | 1509 | } |
| 1510 | 1510 | }; |
| 1511 | S.doTheTest(); | |
| 1511 | try S.doTheTest(); | |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | test "nosuspend await" { |
| 1515 | 1515 | const S = struct { |
| 1516 | 1516 | var finished = false; |
| 1517 | 1517 | |
| 1518 | fn doTheTest() void { | |
| 1518 | fn doTheTest() !void { | |
| 1519 | 1519 | var frame = async foo(false); |
| 1520 | expect(nosuspend await frame == 42); | |
| 1520 | try expect(nosuspend await frame == 42); | |
| 1521 | 1521 | finished = true; |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| ... | ... | @@ -1528,8 +1528,8 @@ test "nosuspend await" { |
| 1528 | 1528 | return 42; |
| 1529 | 1529 | } |
| 1530 | 1530 | }; |
| 1531 | S.doTheTest(); | |
| 1532 | expect(S.finished); | |
| 1531 | try S.doTheTest(); | |
| 1532 | try expect(S.finished); | |
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | test "nosuspend on function calls" { |
| ... | ... | @@ -1544,8 +1544,8 @@ test "nosuspend on function calls" { |
| 1544 | 1544 | return S0{}; |
| 1545 | 1545 | } |
| 1546 | 1546 | }; |
| 1547 | expectEqual(@as(i32, 42), nosuspend S1.c().b); | |
| 1548 | expectEqual(@as(i32, 42), (try nosuspend S1.d()).b); | |
| 1547 | try expectEqual(@as(i32, 42), nosuspend S1.c().b); | |
| 1548 | try expectEqual(@as(i32, 42), (try nosuspend S1.d()).b); | |
| 1549 | 1549 | } |
| 1550 | 1550 | |
| 1551 | 1551 | test "nosuspend on async function calls" { |
| ... | ... | @@ -1561,9 +1561,9 @@ test "nosuspend on async function calls" { |
| 1561 | 1561 | } |
| 1562 | 1562 | }; |
| 1563 | 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 | 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 | } |
| 1568 | 1568 | |
| 1569 | 1569 | // test "resume nosuspend async function calls" { |
| ... | ... | @@ -1582,10 +1582,10 @@ test "nosuspend on async function calls" { |
| 1582 | 1582 | // }; |
| 1583 | 1583 | // var frame_c = nosuspend async S1.c(); |
| 1584 | 1584 | // resume frame_c; |
| 1585 | // expectEqual(@as(i32, 42), (await frame_c).b); | |
| 1585 | // try expectEqual(@as(i32, 42), (await frame_c).b); | |
| 1586 | 1586 | // var frame_d = nosuspend async S1.d(); |
| 1587 | 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 | // } |
| 1590 | 1590 | |
| 1591 | 1591 | test "nosuspend resume async function calls" { |
| ... | ... | @@ -1604,10 +1604,10 @@ test "nosuspend resume async function calls" { |
| 1604 | 1604 | }; |
| 1605 | 1605 | var frame_c = async S1.c(); |
| 1606 | 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 | 1608 | var frame_d = async S1.d(); |
| 1609 | 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 | } |
| 1612 | 1612 | |
| 1613 | 1613 | 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 | 1624 | var frame = async S.foo(); |
| 1625 | 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 | } |
| 1628 | 1628 | |
| 1629 | 1629 | test "@asyncCall with pass-by-value arguments" { |
| ... | ... | @@ -1638,9 +1638,9 @@ test "@asyncCall with pass-by-value arguments" { |
| 1638 | 1638 | pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void { |
| 1639 | 1639 | // Check that the array and struct arguments passed by value don't |
| 1640 | 1640 | // end up overflowing the adjacent fields in the frame structure. |
| 1641 | expectEqual(F0, _fill0); | |
| 1642 | expectEqual(F1, _fill1); | |
| 1643 | expectEqual(F2, _fill2); | |
| 1641 | expectEqual(F0, _fill0) catch @panic("test failure"); | |
| 1642 | expectEqual(F1, _fill1) catch @panic("test failure"); | |
| 1643 | expectEqual(F2, _fill2) catch @panic("test failure"); | |
| 1644 | 1644 | } |
| 1645 | 1645 | }; |
| 1646 | 1646 | |
| ... | ... | @@ -1664,8 +1664,8 @@ test "@asyncCall with arguments having non-standard alignment" { |
| 1664 | 1664 | pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void { |
| 1665 | 1665 | // The compiler inserts extra alignment for s, check that the |
| 1666 | 1666 | // generated code picks the right slot for fill1. |
| 1667 | expectEqual(F0, _fill0); | |
| 1668 | expectEqual(F1, _fill1); | |
| 1667 | expectEqual(F0, _fill0) catch @panic("test failure"); | |
| 1668 | expectEqual(F1, _fill1) catch @panic("test failure"); | |
| 1669 | 1669 | } |
| 1670 | 1670 | }; |
| 1671 | 1671 |
test/stage1/behavior/atomics.zig+69-69| ... | ... | @@ -4,25 +4,25 @@ const expectEqual = std.testing.expectEqual; |
| 4 | 4 | const builtin = @import("builtin"); |
| 5 | 5 | |
| 6 | 6 | test "cmpxchg" { |
| 7 | testCmpxchg(); | |
| 8 | comptime testCmpxchg(); | |
| 7 | try testCmpxchg(); | |
| 8 | comptime try testCmpxchg(); | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | fn testCmpxchg() void { | |
| 11 | fn testCmpxchg() !void { | |
| 12 | 12 | var x: i32 = 1234; |
| 13 | 13 | if (@cmpxchgWeak(i32, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { |
| 14 | expect(x1 == 1234); | |
| 14 | try expect(x1 == 1234); | |
| 15 | 15 | } else { |
| 16 | 16 | @panic("cmpxchg should have failed"); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 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); | |
| 23 | 23 | |
| 24 | expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null); | |
| 25 | expect(x == 42); | |
| 24 | try expect(@cmpxchgStrong(i32, &x, 5678, 42, .SeqCst, .SeqCst) == null); | |
| 25 | try expect(x == 42); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "fence" { |
| ... | ... | @@ -33,25 +33,25 @@ test "fence" { |
| 33 | 33 | |
| 34 | 34 | test "atomicrmw and atomicload" { |
| 35 | 35 | var data: u8 = 200; |
| 36 | testAtomicRmw(&data); | |
| 37 | expect(data == 42); | |
| 38 | testAtomicLoad(&data); | |
| 36 | try testAtomicRmw(&data); | |
| 37 | try expect(data == 42); | |
| 38 | try testAtomicLoad(&data); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | fn testAtomicRmw(ptr: *u8) void { | |
| 41 | fn testAtomicRmw(ptr: *u8) !void { | |
| 42 | 42 | const prev_value = @atomicRmw(u8, ptr, .Xchg, 42, .SeqCst); |
| 43 | expect(prev_value == 200); | |
| 43 | try expect(prev_value == 200); | |
| 44 | 44 | comptime { |
| 45 | 45 | var x: i32 = 1234; |
| 46 | 46 | const y: i32 = 12345; |
| 47 | expect(@atomicLoad(i32, &x, .SeqCst) == 1234); | |
| 48 | expect(@atomicLoad(i32, &y, .SeqCst) == 12345); | |
| 47 | try expect(@atomicLoad(i32, &x, .SeqCst) == 1234); | |
| 48 | try expect(@atomicLoad(i32, &y, .SeqCst) == 12345); | |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | fn testAtomicLoad(ptr: *u8) void { | |
| 52 | fn testAtomicLoad(ptr: *u8) !void { | |
| 53 | 53 | const x = @atomicLoad(u8, ptr, .SeqCst); |
| 54 | expect(x == 42); | |
| 54 | try expect(x == 42); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | test "cmpxchg with ptr" { |
| ... | ... | @@ -60,18 +60,18 @@ test "cmpxchg with ptr" { |
| 60 | 60 | var data3: i32 = 9101; |
| 61 | 61 | var x: *i32 = &data1; |
| 62 | 62 | if (@cmpxchgWeak(*i32, &x, &data2, &data3, .SeqCst, .SeqCst)) |x1| { |
| 63 | expect(x1 == &data1); | |
| 63 | try expect(x1 == &data1); | |
| 64 | 64 | } else { |
| 65 | 65 | @panic("cmpxchg should have failed"); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 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); | |
| 72 | 72 | |
| 73 | expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null); | |
| 74 | expect(x == &data2); | |
| 73 | try expect(@cmpxchgStrong(*i32, &x, &data3, &data2, .SeqCst, .SeqCst) == null); | |
| 74 | try expect(x == &data2); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // TODO this test is disabled until this issue is resolved: |
| ... | ... | @@ -81,18 +81,18 @@ test "cmpxchg with ptr" { |
| 81 | 81 | //test "128-bit cmpxchg" { |
| 82 | 82 | // var x: u128 align(16) = 1234; // TODO: https://github.com/ziglang/zig/issues/2987 |
| 83 | 83 | // if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| { |
| 84 | // expect(x1 == 1234); | |
| 84 | // try expect(x1 == 1234); | |
| 85 | 85 | // } else { |
| 86 | 86 | // @panic("cmpxchg should have failed"); |
| 87 | 87 | // } |
| 88 | 88 | // |
| 89 | 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); | |
| 95 | // expect(x == 42); | |
| 94 | // try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null); | |
| 95 | // try expect(x == 42); | |
| 96 | 96 | //} |
| 97 | 97 | |
| 98 | 98 | test "cmpxchg with ignored result" { |
| ... | ... | @@ -101,14 +101,14 @@ test "cmpxchg with ignored result" { |
| 101 | 101 | |
| 102 | 102 | _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic); |
| 103 | 103 | |
| 104 | expectEqual(@as(i32, 5678), x); | |
| 104 | try expectEqual(@as(i32, 5678), x); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | var a_global_variable = @as(u32, 1234); |
| 108 | 108 | |
| 109 | 109 | test "cmpxchg on a global variable" { |
| 110 | 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 | } |
| 113 | 113 | |
| 114 | 114 | test "atomic load and rmw with enum" { |
| ... | ... | @@ -119,33 +119,33 @@ test "atomic load and rmw with enum" { |
| 119 | 119 | }; |
| 120 | 120 | var x = Value.a; |
| 121 | 121 | |
| 122 | expect(@atomicLoad(Value, &x, .SeqCst) != .b); | |
| 122 | try expect(@atomicLoad(Value, &x, .SeqCst) != .b); | |
| 123 | 123 | |
| 124 | 124 | _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); |
| 125 | expect(@atomicLoad(Value, &x, .SeqCst) == .c); | |
| 126 | expect(@atomicLoad(Value, &x, .SeqCst) != .a); | |
| 127 | expect(@atomicLoad(Value, &x, .SeqCst) != .b); | |
| 125 | try expect(@atomicLoad(Value, &x, .SeqCst) == .c); | |
| 126 | try expect(@atomicLoad(Value, &x, .SeqCst) != .a); | |
| 127 | try expect(@atomicLoad(Value, &x, .SeqCst) != .b); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | test "atomic store" { |
| 131 | 131 | var x: u32 = 0; |
| 132 | 132 | @atomicStore(u32, &x, 1, .SeqCst); |
| 133 | expect(@atomicLoad(u32, &x, .SeqCst) == 1); | |
| 133 | try expect(@atomicLoad(u32, &x, .SeqCst) == 1); | |
| 134 | 134 | @atomicStore(u32, &x, 12345678, .SeqCst); |
| 135 | expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); | |
| 135 | try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "atomic store comptime" { |
| 139 | comptime testAtomicStore(); | |
| 140 | testAtomicStore(); | |
| 139 | comptime try testAtomicStore(); | |
| 140 | try testAtomicStore(); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | fn testAtomicStore() void { | |
| 143 | fn testAtomicStore() !void { | |
| 144 | 144 | var x: u32 = 0; |
| 145 | 145 | @atomicStore(u32, &x, 1, .SeqCst); |
| 146 | expect(@atomicLoad(u32, &x, .SeqCst) == 1); | |
| 146 | try expect(@atomicLoad(u32, &x, .SeqCst) == 1); | |
| 147 | 147 | @atomicStore(u32, &x, 12345678, .SeqCst); |
| 148 | expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); | |
| 148 | try expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "atomicrmw with floats" { |
| ... | ... | @@ -154,66 +154,66 @@ test "atomicrmw with floats" { |
| 154 | 154 | .aarch64, .arm, .thumb, .riscv64 => return error.SkipZigTest, |
| 155 | 155 | else => {}, |
| 156 | 156 | } |
| 157 | testAtomicRmwFloat(); | |
| 158 | comptime testAtomicRmwFloat(); | |
| 157 | try testAtomicRmwFloat(); | |
| 158 | comptime try testAtomicRmwFloat(); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | fn testAtomicRmwFloat() void { | |
| 161 | fn testAtomicRmwFloat() !void { | |
| 162 | 162 | var x: f32 = 0; |
| 163 | expect(x == 0); | |
| 163 | try expect(x == 0); | |
| 164 | 164 | _ = @atomicRmw(f32, &x, .Xchg, 1, .SeqCst); |
| 165 | expect(x == 1); | |
| 165 | try expect(x == 1); | |
| 166 | 166 | _ = @atomicRmw(f32, &x, .Add, 5, .SeqCst); |
| 167 | expect(x == 6); | |
| 167 | try expect(x == 6); | |
| 168 | 168 | _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst); |
| 169 | expect(x == 4); | |
| 169 | try expect(x == 4); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "atomicrmw with ints" { |
| 173 | testAtomicRmwInt(); | |
| 174 | comptime testAtomicRmwInt(); | |
| 173 | try testAtomicRmwInt(); | |
| 174 | comptime try testAtomicRmwInt(); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | fn testAtomicRmwInt() void { | |
| 177 | fn testAtomicRmwInt() !void { | |
| 178 | 178 | var x: u8 = 1; |
| 179 | 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 | 181 | _ = @atomicRmw(u8, &x, .Add, 3, .SeqCst); |
| 182 | expect(x == 6); | |
| 182 | try expect(x == 6); | |
| 183 | 183 | _ = @atomicRmw(u8, &x, .Sub, 1, .SeqCst); |
| 184 | expect(x == 5); | |
| 184 | try expect(x == 5); | |
| 185 | 185 | _ = @atomicRmw(u8, &x, .And, 4, .SeqCst); |
| 186 | expect(x == 4); | |
| 186 | try expect(x == 4); | |
| 187 | 187 | _ = @atomicRmw(u8, &x, .Nand, 4, .SeqCst); |
| 188 | expect(x == 0xfb); | |
| 188 | try expect(x == 0xfb); | |
| 189 | 189 | _ = @atomicRmw(u8, &x, .Or, 6, .SeqCst); |
| 190 | expect(x == 0xff); | |
| 190 | try expect(x == 0xff); | |
| 191 | 191 | _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst); |
| 192 | expect(x == 0xfd); | |
| 192 | try expect(x == 0xfd); | |
| 193 | 193 | |
| 194 | 194 | _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst); |
| 195 | expect(x == 0xfd); | |
| 195 | try expect(x == 0xfd); | |
| 196 | 196 | _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst); |
| 197 | expect(x == 1); | |
| 197 | try expect(x == 1); | |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | test "atomics with different types" { |
| 201 | testAtomicsWithType(bool, true, false); | |
| 201 | try testAtomicsWithType(bool, true, false); | |
| 202 | 202 | inline for (.{ u1, i5, u15 }) |T| { |
| 203 | 203 | var x: T = 0; |
| 204 | testAtomicsWithType(T, 0, 1); | |
| 204 | try testAtomicsWithType(T, 0, 1); | |
| 205 | 205 | } |
| 206 | testAtomicsWithType(u0, 0, 0); | |
| 207 | testAtomicsWithType(i0, 0, 0); | |
| 206 | try testAtomicsWithType(u0, 0, 0); | |
| 207 | try testAtomicsWithType(i0, 0, 0); | |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | fn testAtomicsWithType(comptime T: type, a: T, b: T) void { | |
| 210 | fn testAtomicsWithType(comptime T: type, a: T, b: T) !void { | |
| 211 | 211 | var x: T = b; |
| 212 | 212 | @atomicStore(T, &x, a, .SeqCst); |
| 213 | expect(x == a); | |
| 214 | expect(@atomicLoad(T, &x, .SeqCst) == a); | |
| 215 | expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a); | |
| 216 | expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null); | |
| 213 | try expect(x == a); | |
| 214 | try expect(@atomicLoad(T, &x, .SeqCst) == a); | |
| 215 | try expect(@atomicRmw(T, &x, .Xchg, b, .SeqCst) == a); | |
| 216 | try expect(@cmpxchgStrong(T, &x, b, a, .SeqCst, .SeqCst) == null); | |
| 217 | 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/stage1/behavior/await_struct.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ test "coroutine await struct" { |
| 15 | 15 | await_seq('f'); |
| 16 | 16 | resume await_a_promise; |
| 17 | 17 | await_seq('i'); |
| 18 | expect(await_final_result.x == 1234); | |
| 19 | expect(std.mem.eql(u8, &await_points, "abcdefghi")); | |
| 18 | try expect(await_final_result.x == 1234); | |
| 19 | try expect(std.mem.eql(u8, &await_points, "abcdefghi")); | |
| 20 | 20 | } |
| 21 | 21 | fn await_amain() callconv(.Async) void { |
| 22 | 22 | await_seq('b'); |
test/stage1/behavior/bit_shifting.zig+14-14| ... | ... | @@ -3,8 +3,8 @@ const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type { |
| 5 | 5 | const key_bits = @typeInfo(Key).Int.bits; |
| 6 | expect(Key == std.meta.Int(.unsigned, key_bits)); | |
| 7 | expect(key_bits >= mask_bit_count); | |
| 6 | std.debug.assert(Key == std.meta.Int(.unsigned, key_bits)); | |
| 7 | std.debug.assert(key_bits >= mask_bit_count); | |
| 8 | 8 | const shard_key_bits = mask_bit_count; |
| 9 | 9 | const ShardKey = std.meta.Int(.unsigned, mask_bit_count); |
| 10 | 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 | 61 | |
| 62 | 62 | test "sharded table" { |
| 63 | 63 | // realistic 16-way sharding |
| 64 | testShardedTable(u32, 4, 8); | |
| 64 | try testShardedTable(u32, 4, 8); | |
| 65 | 65 | |
| 66 | testShardedTable(u5, 0, 32); // ShardKey == u0 | |
| 67 | testShardedTable(u5, 2, 32); | |
| 68 | testShardedTable(u5, 5, 32); | |
| 66 | try testShardedTable(u5, 0, 32); // ShardKey == u0 | |
| 67 | try testShardedTable(u5, 2, 32); | |
| 68 | try testShardedTable(u5, 5, 32); | |
| 69 | 69 | |
| 70 | testShardedTable(u1, 0, 2); | |
| 71 | testShardedTable(u1, 1, 2); // this does u1 >> u0 | |
| 70 | try testShardedTable(u1, 0, 2); | |
| 71 | try testShardedTable(u1, 1, 2); // this does u1 >> u0 | |
| 72 | 72 | |
| 73 | testShardedTable(u0, 0, 1); | |
| 73 | try testShardedTable(u0, 0, 1); | |
| 74 | 74 | } |
| 75 | fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) void { | |
| 75 | fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime node_count: comptime_int) !void { | |
| 76 | 76 | const Table = ShardedTable(Key, mask_bit_count, void); |
| 77 | 77 | |
| 78 | 78 | var table = Table.create(); |
| 79 | 79 | var node_buffer: [node_count]Table.Node = undefined; |
| 80 | 80 | for (node_buffer) |*node, i| { |
| 81 | 81 | const key = @intCast(Key, i); |
| 82 | expect(table.get(key) == null); | |
| 82 | try expect(table.get(key) == null); | |
| 83 | 83 | node.init(key, {}); |
| 84 | 84 | table.put(node); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 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 | } |
| 91 | 91 | |
| ... | ... | @@ -93,9 +93,9 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c |
| 93 | 93 | test "comptime shr of BigInt" { |
| 94 | 94 | comptime { |
| 95 | 95 | var n0 = 0xdeadbeef0000000000000000; |
| 96 | std.debug.assert(n0 >> 64 == 0xdeadbeef); | |
| 96 | try expect(n0 >> 64 == 0xdeadbeef); | |
| 97 | 97 | var n1 = 17908056155735594659; |
| 98 | std.debug.assert(n1 >> 64 == 0); | |
| 98 | try expect(n1 >> 64 == 0); | |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 |
test/stage1/behavior/bitcast.zig+52-52| ... | ... | @@ -5,13 +5,13 @@ const expectEqual = std.testing.expectEqual; |
| 5 | 5 | const maxInt = std.math.maxInt; |
| 6 | 6 | |
| 7 | 7 | test "@bitCast i32 -> u32" { |
| 8 | testBitCast_i32_u32(); | |
| 9 | comptime testBitCast_i32_u32(); | |
| 8 | try testBitCast_i32_u32(); | |
| 9 | comptime try testBitCast_i32_u32(); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | fn testBitCast_i32_u32() void { | |
| 13 | expect(conv(-1) == maxInt(u32)); | |
| 14 | expect(conv2(maxInt(u32)) == -1); | |
| 12 | fn testBitCast_i32_u32() !void { | |
| 13 | try expect(conv(-1) == maxInt(u32)); | |
| 14 | try expect(conv2(maxInt(u32)) == -1); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn conv(x: i32) u32 { |
| ... | ... | @@ -26,15 +26,15 @@ test "@bitCast extern enum to its integer type" { |
| 26 | 26 | A, |
| 27 | 27 | B, |
| 28 | 28 | |
| 29 | fn testBitCastExternEnum() void { | |
| 29 | fn testBitCastExternEnum() !void { | |
| 30 | 30 | var SOCK_DGRAM = @This().B; |
| 31 | 31 | var sock_dgram = @bitCast(c_int, SOCK_DGRAM); |
| 32 | expect(sock_dgram == 1); | |
| 32 | try expect(sock_dgram == 1); | |
| 33 | 33 | } |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | SOCK.testBitCastExternEnum(); | |
| 37 | comptime SOCK.testBitCastExternEnum(); | |
| 36 | try SOCK.testBitCastExternEnum(); | |
| 37 | comptime try SOCK.testBitCastExternEnum(); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "@bitCast packed structs at runtime and comptime" { |
| ... | ... | @@ -47,25 +47,25 @@ test "@bitCast packed structs at runtime and comptime" { |
| 47 | 47 | quarter4: u4, |
| 48 | 48 | }; |
| 49 | 49 | const S = struct { |
| 50 | fn doTheTest() void { | |
| 50 | fn doTheTest() !void { | |
| 51 | 51 | var full = Full{ .number = 0x1234 }; |
| 52 | 52 | var two_halves = @bitCast(Divided, full); |
| 53 | 53 | switch (builtin.endian) { |
| 54 | 54 | builtin.Endian.Big => { |
| 55 | expect(two_halves.half1 == 0x12); | |
| 56 | expect(two_halves.quarter3 == 0x3); | |
| 57 | expect(two_halves.quarter4 == 0x4); | |
| 55 | try expect(two_halves.half1 == 0x12); | |
| 56 | try expect(two_halves.quarter3 == 0x3); | |
| 57 | try expect(two_halves.quarter4 == 0x4); | |
| 58 | 58 | }, |
| 59 | 59 | builtin.Endian.Little => { |
| 60 | expect(two_halves.half1 == 0x34); | |
| 61 | expect(two_halves.quarter3 == 0x2); | |
| 62 | expect(two_halves.quarter4 == 0x1); | |
| 60 | try expect(two_halves.half1 == 0x34); | |
| 61 | try expect(two_halves.quarter3 == 0x2); | |
| 62 | try expect(two_halves.quarter4 == 0x1); | |
| 63 | 63 | }, |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | }; |
| 67 | S.doTheTest(); | |
| 68 | comptime S.doTheTest(); | |
| 67 | try S.doTheTest(); | |
| 68 | comptime try S.doTheTest(); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "@bitCast extern structs at runtime and comptime" { |
| ... | ... | @@ -77,23 +77,23 @@ test "@bitCast extern structs at runtime and comptime" { |
| 77 | 77 | half2: u8, |
| 78 | 78 | }; |
| 79 | 79 | const S = struct { |
| 80 | fn doTheTest() void { | |
| 80 | fn doTheTest() !void { | |
| 81 | 81 | var full = Full{ .number = 0x1234 }; |
| 82 | 82 | var two_halves = @bitCast(TwoHalves, full); |
| 83 | 83 | switch (builtin.endian) { |
| 84 | 84 | builtin.Endian.Big => { |
| 85 | expect(two_halves.half1 == 0x12); | |
| 86 | expect(two_halves.half2 == 0x34); | |
| 85 | try expect(two_halves.half1 == 0x12); | |
| 86 | try expect(two_halves.half2 == 0x34); | |
| 87 | 87 | }, |
| 88 | 88 | builtin.Endian.Little => { |
| 89 | expect(two_halves.half1 == 0x34); | |
| 90 | expect(two_halves.half2 == 0x12); | |
| 89 | try expect(two_halves.half1 == 0x34); | |
| 90 | try expect(two_halves.half2 == 0x12); | |
| 91 | 91 | }, |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | }; |
| 95 | S.doTheTest(); | |
| 96 | comptime S.doTheTest(); | |
| 95 | try S.doTheTest(); | |
| 96 | comptime try S.doTheTest(); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test "bitcast packed struct to integer and back" { |
| ... | ... | @@ -102,35 +102,35 @@ test "bitcast packed struct to integer and back" { |
| 102 | 102 | level: u7, |
| 103 | 103 | }; |
| 104 | 104 | const S = struct { |
| 105 | fn doTheTest() void { | |
| 105 | fn doTheTest() !void { | |
| 106 | 106 | var move = LevelUpMove{ .move_id = 1, .level = 2 }; |
| 107 | 107 | var v = @bitCast(u16, move); |
| 108 | 108 | var back_to_a_move = @bitCast(LevelUpMove, v); |
| 109 | expect(back_to_a_move.move_id == 1); | |
| 110 | expect(back_to_a_move.level == 2); | |
| 109 | try expect(back_to_a_move.move_id == 1); | |
| 110 | try expect(back_to_a_move.level == 2); | |
| 111 | 111 | } |
| 112 | 112 | }; |
| 113 | S.doTheTest(); | |
| 114 | comptime S.doTheTest(); | |
| 113 | try S.doTheTest(); | |
| 114 | comptime try S.doTheTest(); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "implicit cast to error union by returning" { |
| 118 | 118 | const S = struct { |
| 119 | fn entry() void { | |
| 120 | expect((func(-1) catch unreachable) == maxInt(u64)); | |
| 119 | fn entry() !void { | |
| 120 | try expect((func(-1) catch unreachable) == maxInt(u64)); | |
| 121 | 121 | } |
| 122 | 122 | pub fn func(sz: i64) anyerror!u64 { |
| 123 | 123 | return @bitCast(u64, sz); |
| 124 | 124 | } |
| 125 | 125 | }; |
| 126 | S.entry(); | |
| 127 | comptime S.entry(); | |
| 126 | try S.entry(); | |
| 127 | comptime try S.entry(); | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // issue #3010: compiler segfault |
| 131 | 131 | test "bitcast literal [4]u8 param to u32" { |
| 132 | 132 | const ip = @bitCast(u32, [_]u8{ 255, 255, 255, 255 }); |
| 133 | expect(ip == maxInt(u32)); | |
| 133 | try expect(ip == maxInt(u32)); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | test "bitcast packed struct literal to byte" { |
| ... | ... | @@ -138,14 +138,14 @@ test "bitcast packed struct literal to byte" { |
| 138 | 138 | value: u8, |
| 139 | 139 | }; |
| 140 | 140 | const casted = @bitCast(u8, Foo{ .value = 0xF }); |
| 141 | expect(casted == 0xf); | |
| 141 | try expect(casted == 0xf); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "comptime bitcast used in expression has the correct type" { |
| 145 | 145 | const Foo = packed struct { |
| 146 | 146 | value: u8, |
| 147 | 147 | }; |
| 148 | expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf); | |
| 148 | try expect(@bitCast(u8, Foo{ .value = 0xF }) == 0xf); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "bitcast result to _" { |
| ... | ... | @@ -154,43 +154,43 @@ test "bitcast result to _" { |
| 154 | 154 | |
| 155 | 155 | test "nested bitcast" { |
| 156 | 156 | const S = struct { |
| 157 | fn moo(x: isize) void { | |
| 158 | @import("std").testing.expectEqual(@intCast(isize, 42), x); | |
| 157 | fn moo(x: isize) !void { | |
| 158 | try @import("std").testing.expectEqual(@intCast(isize, 42), x); | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | fn foo(x: isize) void { | |
| 162 | @This().moo( | |
| 161 | fn foo(x: isize) !void { | |
| 162 | try @This().moo( | |
| 163 | 163 | @bitCast(isize, if (x != 0) @bitCast(usize, x) else @bitCast(usize, x)), |
| 164 | 164 | ); |
| 165 | 165 | } |
| 166 | 166 | }; |
| 167 | 167 | |
| 168 | S.foo(42); | |
| 169 | comptime S.foo(42); | |
| 168 | try S.foo(42); | |
| 169 | comptime try S.foo(42); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "bitcast passed as tuple element" { |
| 173 | 173 | const S = struct { |
| 174 | fn foo(args: anytype) void { | |
| 175 | comptime expect(@TypeOf(args[0]) == f32); | |
| 176 | expect(args[0] == 12.34); | |
| 174 | fn foo(args: anytype) !void { | |
| 175 | comptime try expect(@TypeOf(args[0]) == f32); | |
| 176 | try expect(args[0] == 12.34); | |
| 177 | 177 | } |
| 178 | 178 | }; |
| 179 | S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))}); | |
| 179 | try S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))}); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | test "triple level result location with bitcast sandwich passed as tuple element" { |
| 183 | 183 | const S = struct { |
| 184 | fn foo(args: anytype) void { | |
| 185 | comptime expect(@TypeOf(args[0]) == f64); | |
| 186 | expect(args[0] > 12.33 and args[0] < 12.35); | |
| 184 | fn foo(args: anytype) !void { | |
| 185 | comptime try expect(@TypeOf(args[0]) == f64); | |
| 186 | try expect(args[0] > 12.33 and args[0] < 12.35); | |
| 187 | 187 | } |
| 188 | 188 | }; |
| 189 | S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))}); | |
| 189 | try S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))}); | |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | test "bitcast generates a temporary value" { |
| 193 | 193 | var y = @as(u16, 0x55AA); |
| 194 | 194 | const x = @bitCast(u16, @bitCast([2]u8, y)); |
| 195 | expectEqual(y, x); | |
| 195 | try expectEqual(y, x); | |
| 196 | 196 | } |
test/stage1/behavior/bitreverse.zig+39-39| ... | ... | @@ -3,67 +3,67 @@ const expect = std.testing.expect; |
| 3 | 3 | const minInt = std.math.minInt; |
| 4 | 4 | |
| 5 | 5 | test "@bitReverse" { |
| 6 | comptime testBitReverse(); | |
| 7 | testBitReverse(); | |
| 6 | comptime try testBitReverse(); | |
| 7 | try testBitReverse(); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn testBitReverse() void { | |
| 10 | fn testBitReverse() !void { | |
| 11 | 11 | // using comptime_ints, unsigned |
| 12 | expect(@bitReverse(u0, 0) == 0); | |
| 13 | expect(@bitReverse(u5, 0x12) == 0x9); | |
| 14 | expect(@bitReverse(u8, 0x12) == 0x48); | |
| 15 | expect(@bitReverse(u16, 0x1234) == 0x2c48); | |
| 16 | expect(@bitReverse(u24, 0x123456) == 0x6a2c48); | |
| 17 | expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48); | |
| 18 | expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48); | |
| 19 | expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48); | |
| 20 | expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48); | |
| 21 | expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48); | |
| 22 | expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 12 | try expect(@bitReverse(u0, 0) == 0); | |
| 13 | try expect(@bitReverse(u5, 0x12) == 0x9); | |
| 14 | try expect(@bitReverse(u8, 0x12) == 0x48); | |
| 15 | try expect(@bitReverse(u16, 0x1234) == 0x2c48); | |
| 16 | try expect(@bitReverse(u24, 0x123456) == 0x6a2c48); | |
| 17 | try expect(@bitReverse(u32, 0x12345678) == 0x1e6a2c48); | |
| 18 | try expect(@bitReverse(u40, 0x123456789a) == 0x591e6a2c48); | |
| 19 | try expect(@bitReverse(u48, 0x123456789abc) == 0x3d591e6a2c48); | |
| 20 | try expect(@bitReverse(u56, 0x123456789abcde) == 0x7b3d591e6a2c48); | |
| 21 | try expect(@bitReverse(u64, 0x123456789abcdef1) == 0x8f7b3d591e6a2c48); | |
| 22 | try expect(@bitReverse(u128, 0x123456789abcdef11121314151617181) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 23 | 23 | |
| 24 | 24 | // using runtime uints, unsigned |
| 25 | 25 | var num0: u0 = 0; |
| 26 | expect(@bitReverse(u0, num0) == 0); | |
| 26 | try expect(@bitReverse(u0, num0) == 0); | |
| 27 | 27 | var num5: u5 = 0x12; |
| 28 | expect(@bitReverse(u5, num5) == 0x9); | |
| 28 | try expect(@bitReverse(u5, num5) == 0x9); | |
| 29 | 29 | var num8: u8 = 0x12; |
| 30 | expect(@bitReverse(u8, num8) == 0x48); | |
| 30 | try expect(@bitReverse(u8, num8) == 0x48); | |
| 31 | 31 | var num16: u16 = 0x1234; |
| 32 | expect(@bitReverse(u16, num16) == 0x2c48); | |
| 32 | try expect(@bitReverse(u16, num16) == 0x2c48); | |
| 33 | 33 | var num24: u24 = 0x123456; |
| 34 | expect(@bitReverse(u24, num24) == 0x6a2c48); | |
| 34 | try expect(@bitReverse(u24, num24) == 0x6a2c48); | |
| 35 | 35 | var num32: u32 = 0x12345678; |
| 36 | expect(@bitReverse(u32, num32) == 0x1e6a2c48); | |
| 36 | try expect(@bitReverse(u32, num32) == 0x1e6a2c48); | |
| 37 | 37 | var num40: u40 = 0x123456789a; |
| 38 | expect(@bitReverse(u40, num40) == 0x591e6a2c48); | |
| 38 | try expect(@bitReverse(u40, num40) == 0x591e6a2c48); | |
| 39 | 39 | var num48: u48 = 0x123456789abc; |
| 40 | expect(@bitReverse(u48, num48) == 0x3d591e6a2c48); | |
| 40 | try expect(@bitReverse(u48, num48) == 0x3d591e6a2c48); | |
| 41 | 41 | var num56: u56 = 0x123456789abcde; |
| 42 | expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48); | |
| 42 | try expect(@bitReverse(u56, num56) == 0x7b3d591e6a2c48); | |
| 43 | 43 | var num64: u64 = 0x123456789abcdef1; |
| 44 | expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48); | |
| 44 | try expect(@bitReverse(u64, num64) == 0x8f7b3d591e6a2c48); | |
| 45 | 45 | var num128: u128 = 0x123456789abcdef11121314151617181; |
| 46 | expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 46 | try expect(@bitReverse(u128, num128) == 0x818e868a828c84888f7b3d591e6a2c48); | |
| 47 | 47 | |
| 48 | 48 | // using comptime_ints, signed, positive |
| 49 | expect(@bitReverse(u8, @as(u8, 0)) == 0); | |
| 50 | expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); | |
| 51 | expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48))); | |
| 52 | expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48))); | |
| 53 | expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48))); | |
| 54 | expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48))); | |
| 55 | expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48))); | |
| 56 | expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48))); | |
| 57 | expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48))); | |
| 58 | expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); | |
| 49 | try expect(@bitReverse(u8, @as(u8, 0)) == 0); | |
| 50 | try expect(@bitReverse(i8, @bitCast(i8, @as(u8, 0x92))) == @bitCast(i8, @as(u8, 0x49))); | |
| 51 | try expect(@bitReverse(i16, @bitCast(i16, @as(u16, 0x1234))) == @bitCast(i16, @as(u16, 0x2c48))); | |
| 52 | try expect(@bitReverse(i24, @bitCast(i24, @as(u24, 0x123456))) == @bitCast(i24, @as(u24, 0x6a2c48))); | |
| 53 | try expect(@bitReverse(i32, @bitCast(i32, @as(u32, 0x12345678))) == @bitCast(i32, @as(u32, 0x1e6a2c48))); | |
| 54 | try expect(@bitReverse(i40, @bitCast(i40, @as(u40, 0x123456789a))) == @bitCast(i40, @as(u40, 0x591e6a2c48))); | |
| 55 | try expect(@bitReverse(i48, @bitCast(i48, @as(u48, 0x123456789abc))) == @bitCast(i48, @as(u48, 0x3d591e6a2c48))); | |
| 56 | try expect(@bitReverse(i56, @bitCast(i56, @as(u56, 0x123456789abcde))) == @bitCast(i56, @as(u56, 0x7b3d591e6a2c48))); | |
| 57 | try expect(@bitReverse(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1))) == @bitCast(i64, @as(u64, 0x8f7b3d591e6a2c48))); | |
| 58 | try expect(@bitReverse(i128, @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181))) == @bitCast(i128, @as(u128, 0x818e868a828c84888f7b3d591e6a2c48))); | |
| 59 | 59 | |
| 60 | 60 | // using signed, negative. Compare to runtime ints returned from llvm. |
| 61 | 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 | 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 | 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 | 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/stage1/behavior/bool.zig+11-11| ... | ... | @@ -1,25 +1,25 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "bool literals" { |
| 4 | expect(true); | |
| 5 | expect(!false); | |
| 4 | try expect(true); | |
| 5 | try expect(!false); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "cast bool to int" { |
| 9 | 9 | const t = true; |
| 10 | 10 | const f = false; |
| 11 | expect(@boolToInt(t) == @as(u32, 1)); | |
| 12 | expect(@boolToInt(f) == @as(u32, 0)); | |
| 13 | nonConstCastBoolToInt(t, f); | |
| 11 | try expect(@boolToInt(t) == @as(u32, 1)); | |
| 12 | try expect(@boolToInt(f) == @as(u32, 0)); | |
| 13 | try nonConstCastBoolToInt(t, f); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | fn nonConstCastBoolToInt(t: bool, f: bool) void { | |
| 17 | expect(@boolToInt(t) == @as(u32, 1)); | |
| 18 | expect(@boolToInt(f) == @as(u32, 0)); | |
| 16 | fn nonConstCastBoolToInt(t: bool, f: bool) !void { | |
| 17 | try expect(@boolToInt(t) == @as(u32, 1)); | |
| 18 | try expect(@boolToInt(f) == @as(u32, 0)); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "bool cmp" { |
| 22 | expect(testBoolCmp(true, false) == false); | |
| 22 | try expect(testBoolCmp(true, false) == false); | |
| 23 | 23 | } |
| 24 | 24 | fn testBoolCmp(a: bool, b: bool) bool { |
| 25 | 25 | return a == b; |
| ... | ... | @@ -30,6 +30,6 @@ const global_t = true; |
| 30 | 30 | const not_global_f = !global_f; |
| 31 | 31 | const not_global_t = !global_t; |
| 32 | 32 | test "compile time bool not" { |
| 33 | expect(not_global_f); | |
| 34 | expect(!not_global_t); | |
| 33 | try expect(not_global_f); | |
| 34 | try expect(!not_global_t); | |
| 35 | 35 | } |
test/stage1/behavior/bugs/1025.zig+1-1| ... | ... | @@ -8,5 +8,5 @@ fn getA() A { |
| 8 | 8 | |
| 9 | 9 | test "bug 1025" { |
| 10 | 10 | const a = getA(); |
| 11 | @import("std").testing.expect(a.B == u8); | |
| 11 | try @import("std").testing.expect(a.B == u8); | |
| 12 | 12 | } |
test/stage1/behavior/bugs/1076.zig+5-5| ... | ... | @@ -3,21 +3,21 @@ const mem = std.mem; |
| 3 | 3 | const expect = std.testing.expect; |
| 4 | 4 | |
| 5 | 5 | test "comptime code should not modify constant data" { |
| 6 | testCastPtrOfArrayToSliceAndPtr(); | |
| 7 | comptime testCastPtrOfArrayToSliceAndPtr(); | |
| 6 | try testCastPtrOfArrayToSliceAndPtr(); | |
| 7 | comptime try testCastPtrOfArrayToSliceAndPtr(); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn testCastPtrOfArrayToSliceAndPtr() void { | |
| 10 | fn testCastPtrOfArrayToSliceAndPtr() !void { | |
| 11 | 11 | { |
| 12 | 12 | var array = "aoeu".*; |
| 13 | 13 | const x: [*]u8 = &array; |
| 14 | 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 | 18 | var array: [4]u8 = "aoeu".*; |
| 19 | 19 | const x: [*]u8 = &array; |
| 20 | 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/stage1/behavior/bugs/1120.zig+1-1| ... | ... | @@ -19,5 +19,5 @@ test "bug 1120" { |
| 19 | 19 | 1 => &b.a, |
| 20 | 20 | else => unreachable, |
| 21 | 21 | }; |
| 22 | expect(ptr.* == 2); | |
| 22 | try expect(ptr.* == 2); | |
| 23 | 23 | } |
test/stage1/behavior/bugs/1277.zig+1-1| ... | ... | @@ -11,5 +11,5 @@ fn f() i32 { |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "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/stage1/behavior/bugs/1310.zig+1-1| ... | ... | @@ -20,5 +20,5 @@ fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "fixed" { |
| 23 | expect(agent_callback(undefined, undefined) == 11); | |
| 23 | try expect(agent_callback(undefined, undefined) == 11); | |
| 24 | 24 | } |
test/stage1/behavior/bugs/1322.zig+2-2| ... | ... | @@ -13,7 +13,7 @@ const C = struct {}; |
| 13 | 13 | |
| 14 | 14 | test "tagged union with all void fields but a meaningful tag" { |
| 15 | 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 | 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/stage1/behavior/bugs/1381.zig+1-1| ... | ... | @@ -17,5 +17,5 @@ test "union that needs padding bytes inside an array" { |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | const a = as[0].B; |
| 20 | std.testing.expect(a.D == 1); | |
| 20 | try std.testing.expect(a.D == 1); | |
| 21 | 21 | } |
test/stage1/behavior/bugs/1421.zig+1-1| ... | ... | @@ -10,5 +10,5 @@ const S = struct { |
| 10 | 10 | |
| 11 | 11 | test "functions with return type required to be comptime are generic" { |
| 12 | 12 | const ti = S.method(); |
| 13 | expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct); | |
| 13 | try expect(@as(builtin.TypeId, ti) == builtin.TypeId.Struct); | |
| 14 | 14 | } |
test/stage1/behavior/bugs/1442.zig+1-1| ... | ... | @@ -7,5 +7,5 @@ const Union = union(enum) { |
| 7 | 7 | |
| 8 | 8 | test "const error union field alignment" { |
| 9 | 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/stage1/behavior/bugs/1486.zig+2-2| ... | ... | @@ -5,6 +5,6 @@ var global: u64 = 123; |
| 5 | 5 | |
| 6 | 6 | test "constant pointer to global variable causes runtime load" { |
| 7 | 7 | global = 1234; |
| 8 | expect(&global == ptr); | |
| 9 | expect(ptr.* == 1234); | |
| 8 | try expect(&global == ptr); | |
| 9 | try expect(ptr.* == 1234); | |
| 10 | 10 | } |
test/stage1/behavior/bugs/1607.zig+4-4| ... | ... | @@ -3,13 +3,13 @@ const testing = std.testing; |
| 3 | 3 | |
| 4 | 4 | const a = [_]u8{ 1, 2, 3 }; |
| 5 | 5 | |
| 6 | fn checkAddress(s: []const u8) void { | |
| 6 | fn checkAddress(s: []const u8) !void { | |
| 7 | 7 | for (s) |*i, j| { |
| 8 | testing.expect(i == &a[j]); | |
| 8 | try testing.expect(i == &a[j]); | |
| 9 | 9 | } |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | test "slices pointing at the same address as global array." { |
| 13 | checkAddress(&a); | |
| 14 | comptime checkAddress(&a); | |
| 13 | try checkAddress(&a); | |
| 14 | comptime try checkAddress(&a); | |
| 15 | 15 | } |
test/stage1/behavior/bugs/1735.zig+1-1| ... | ... | @@ -42,5 +42,5 @@ const a = struct { |
| 42 | 42 | |
| 43 | 43 | test "intialization" { |
| 44 | 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/stage1/behavior/bugs/1741.zig+1-1| ... | ... | @@ -2,5 +2,5 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | test "fixed" { |
| 4 | 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/stage1/behavior/bugs/1851.zig+9-9| ... | ... | @@ -2,25 +2,25 @@ const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "allocation and looping over 3-byte integer" { |
| 5 | expect(@sizeOf(u24) == 4); | |
| 6 | expect(@sizeOf([1]u24) == 4); | |
| 7 | expect(@alignOf(u24) == 4); | |
| 8 | expect(@alignOf([1]u24) == 4); | |
| 5 | try expect(@sizeOf(u24) == 4); | |
| 6 | try expect(@sizeOf([1]u24) == 4); | |
| 7 | try expect(@alignOf(u24) == 4); | |
| 8 | try expect(@alignOf([1]u24) == 4); | |
| 9 | 9 | |
| 10 | 10 | var x = try std.testing.allocator.alloc(u24, 2); |
| 11 | 11 | defer std.testing.allocator.free(x); |
| 12 | expect(x.len == 2); | |
| 12 | try expect(x.len == 2); | |
| 13 | 13 | x[0] = 0xFFFFFF; |
| 14 | 14 | x[1] = 0xFFFFFF; |
| 15 | 15 | |
| 16 | 16 | const bytes = std.mem.sliceAsBytes(x); |
| 17 | expect(@TypeOf(bytes) == []align(4) u8); | |
| 18 | expect(bytes.len == 8); | |
| 17 | try expect(@TypeOf(bytes) == []align(4) u8); | |
| 18 | try expect(bytes.len == 8); | |
| 19 | 19 | |
| 20 | 20 | for (bytes) |*b| { |
| 21 | 21 | b.* = 0x00; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | expect(x[0] == 0x00); | |
| 25 | expect(x[1] == 0x00); | |
| 24 | try expect(x[0] == 0x00); | |
| 25 | try expect(x[1] == 0x00); | |
| 26 | 26 | } |
test/stage1/behavior/bugs/2006.zig+2-2| ... | ... | @@ -7,6 +7,6 @@ const S = struct { |
| 7 | 7 | test "bug 2006" { |
| 8 | 8 | var a: S = undefined; |
| 9 | 9 | a = S{ .p = undefined }; |
| 10 | expect(@sizeOf(S) != 0); | |
| 11 | expect(@sizeOf(*void) == 0); | |
| 10 | try expect(@sizeOf(S) != 0); | |
| 11 | try expect(@sizeOf(*void) == 0); | |
| 12 | 12 | } |
test/stage1/behavior/bugs/2114.zig+7-7| ... | ... | @@ -7,13 +7,13 @@ fn ctz(x: anytype) usize { |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixed" { |
| 10 | testClz(); | |
| 11 | comptime testClz(); | |
| 10 | try testClz(); | |
| 11 | comptime try testClz(); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | fn testClz() void { | |
| 15 | expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); | |
| 16 | expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); | |
| 17 | expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); | |
| 18 | expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); | |
| 14 | fn testClz() !void { | |
| 15 | try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); | |
| 16 | try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); | |
| 17 | try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); | |
| 18 | try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); | |
| 19 | 19 | } |
test/stage1/behavior/bugs/2889.zig+1-1| ... | ... | @@ -27,5 +27,5 @@ fn parseNote() ?i32 { |
| 27 | 27 | |
| 28 | 28 | test "fixed" { |
| 29 | 29 | const result = parseNote(); |
| 30 | std.testing.expect(result.? == 9); | |
| 30 | try std.testing.expect(result.? == 9); | |
| 31 | 31 | } |
test/stage1/behavior/bugs/3007.zig+1-1| ... | ... | @@ -19,5 +19,5 @@ fn get_foo() Foo.FooError!*Foo { |
| 19 | 19 | |
| 20 | 20 | test "fixed" { |
| 21 | 21 | 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/stage1/behavior/bugs/3046.zig+1-1| ... | ... | @@ -15,5 +15,5 @@ test "fixed" { |
| 15 | 15 | some_struct = SomeStruct{ |
| 16 | 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/stage1/behavior/bugs/3112.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ const State = struct { |
| 7 | 7 | }; |
| 8 | 8 | |
| 9 | 9 | fn prev(p: ?State) void { |
| 10 | expect(p == null); | |
| 10 | expect(p == null) catch @panic("test failure"); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "zig test crash" { |
test/stage1/behavior/bugs/3384.zig+6-6| ... | ... | @@ -2,10 +2,10 @@ const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "resolve array slice using builtin" { |
| 5 | expect(@hasDecl(@This(), "std") == true); | |
| 6 | expect(@hasDecl(@This(), "std"[0..0]) == false); | |
| 7 | expect(@hasDecl(@This(), "std"[0..1]) == false); | |
| 8 | expect(@hasDecl(@This(), "std"[0..2]) == false); | |
| 9 | expect(@hasDecl(@This(), "std"[0..3]) == true); | |
| 10 | expect(@hasDecl(@This(), "std"[0..]) == true); | |
| 5 | try expect(@hasDecl(@This(), "std") == true); | |
| 6 | try expect(@hasDecl(@This(), "std"[0..0]) == false); | |
| 7 | try expect(@hasDecl(@This(), "std"[0..1]) == false); | |
| 8 | try expect(@hasDecl(@This(), "std"[0..2]) == false); | |
| 9 | try expect(@hasDecl(@This(), "std"[0..3]) == true); | |
| 10 | try expect(@hasDecl(@This(), "std"[0..]) == true); | |
| 11 | 11 | } |
test/stage1/behavior/bugs/394.zig+1-1| ... | ... | @@ -14,5 +14,5 @@ test "bug 394 fixed" { |
| 14 | 14 | .x = 3, |
| 15 | 15 | .y = E{ .B = 1 }, |
| 16 | 16 | }; |
| 17 | expect(x.x == 3); | |
| 17 | try expect(x.x == 3); | |
| 18 | 18 | } |
test/stage1/behavior/bugs/421.zig+4-4| ... | ... | @@ -1,12 +1,12 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "bitCast to array" { |
| 4 | comptime testBitCastArray(); | |
| 5 | testBitCastArray(); | |
| 4 | comptime try testBitCastArray(); | |
| 5 | try testBitCastArray(); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | fn testBitCastArray() void { | |
| 9 | expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef); | |
| 8 | fn testBitCastArray() !void { | |
| 9 | try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn extractOne64(a: u128) u64 { |
test/stage1/behavior/bugs/4328.zig+14-14| ... | ... | @@ -25,14 +25,14 @@ test "Extern function calls in @TypeOf" { |
| 25 | 25 | return 1; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | fn doTheTest() void { | |
| 29 | expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); | |
| 30 | expectEqual(c_short, @TypeOf(test_fn_2(0))); | |
| 28 | fn doTheTest() !void { | |
| 29 | try expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); | |
| 30 | try expectEqual(c_short, @TypeOf(test_fn_2(0))); | |
| 31 | 31 | } |
| 32 | 32 | }; |
| 33 | 33 | |
| 34 | Test.doTheTest(); | |
| 35 | comptime Test.doTheTest(); | |
| 34 | try Test.doTheTest(); | |
| 35 | comptime try Test.doTheTest(); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "Peer resolution of extern function calls in @TypeOf" { |
| ... | ... | @@ -41,13 +41,13 @@ test "Peer resolution of extern function calls in @TypeOf" { |
| 41 | 41 | return 0; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | fn doTheTest() void { | |
| 45 | expectEqual(c_long, @TypeOf(test_fn())); | |
| 44 | fn doTheTest() !void { | |
| 45 | try expectEqual(c_long, @TypeOf(test_fn())); | |
| 46 | 46 | } |
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | Test.doTheTest(); | |
| 50 | comptime Test.doTheTest(); | |
| 49 | try Test.doTheTest(); | |
| 50 | comptime try Test.doTheTest(); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | 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 | 60 | return 255; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | fn doTheTest() void { | |
| 64 | expectEqual(FILE, @TypeOf(test_fn_1(0))); | |
| 65 | expectEqual(u8, @TypeOf(test_fn_2(0))); | |
| 63 | fn doTheTest() !void { | |
| 64 | try expectEqual(FILE, @TypeOf(test_fn_1(0))); | |
| 65 | try expectEqual(u8, @TypeOf(test_fn_2(0))); | |
| 66 | 66 | } |
| 67 | 67 | }; |
| 68 | 68 | |
| 69 | Test.doTheTest(); | |
| 70 | comptime Test.doTheTest(); | |
| 69 | try Test.doTheTest(); | |
| 70 | comptime try Test.doTheTest(); | |
| 71 | 71 | } |
test/stage1/behavior/bugs/4560.zig+3-3| ... | ... | @@ -8,9 +8,9 @@ test "fixed" { |
| 8 | 8 | .max_distance_from_start_index = 456, |
| 9 | 9 | }, |
| 10 | 10 | }; |
| 11 | std.testing.expect(s.a == 1); | |
| 12 | std.testing.expect(s.b.size == 123); | |
| 13 | std.testing.expect(s.b.max_distance_from_start_index == 456); | |
| 11 | try std.testing.expect(s.a == 1); | |
| 12 | try std.testing.expect(s.b.size == 123); | |
| 13 | try std.testing.expect(s.b.max_distance_from_start_index == 456); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | const S = struct { |
test/stage1/behavior/bugs/4769_a.zig+1-1| ... | ... | @@ -1 +1 @@ |
| 1 | // | |
| \ No newline at end of file | ||
| 1 | // |
test/stage1/behavior/bugs/4769_b.zig+1-1| ... | ... | @@ -1 +1 @@ |
| 1 | //! | |
| \ No newline at end of file | ||
| 1 | //! |
test/stage1/behavior/bugs/5398.zig+3-3| ... | ... | @@ -25,7 +25,7 @@ test "assignment of field with padding" { |
| 25 | 25 | .emits_shadows = false, |
| 26 | 26 | }, |
| 27 | 27 | }; |
| 28 | testing.expectEqual(false, renderable.material.transparent); | |
| 29 | testing.expectEqual(false, renderable.material.emits_shadows); | |
| 30 | testing.expectEqual(true, renderable.material.render_color); | |
| 28 | try testing.expectEqual(false, renderable.material.transparent); | |
| 29 | try testing.expectEqual(false, renderable.material.emits_shadows); | |
| 30 | try testing.expectEqual(true, renderable.material.render_color); | |
| 31 | 31 | } |
test/stage1/behavior/bugs/5413.zig+2-2| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "Peer type resolution with string literals and unknown length u8 pointers" { |
| 4 | expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8); | |
| 5 | expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8); | |
| 4 | try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8); | |
| 5 | try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8); | |
| 6 | 6 | } |
test/stage1/behavior/bugs/5474.zig+9-9| ... | ... | @@ -25,33 +25,33 @@ const Box2 = struct { |
| 25 | 25 | }; |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | fn doTest() void { | |
| 28 | fn doTest() !void { | |
| 29 | 29 | // var |
| 30 | 30 | { |
| 31 | 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); | |
| 33 | 33 | |
| 34 | 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); | |
| 36 | 36 | |
| 37 | 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 | } |
| 40 | 40 | |
| 41 | 41 | // const |
| 42 | 42 | { |
| 43 | 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); | |
| 45 | 45 | |
| 46 | 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); | |
| 48 | 48 | |
| 49 | 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 | } |
| 53 | 53 | |
| 54 | 54 | test "pointer-to-array constness for zero-size elements" { |
| 55 | doTest(); | |
| 56 | comptime doTest(); | |
| 55 | try doTest(); | |
| 56 | comptime try doTest(); | |
| 57 | 57 | } |
test/stage1/behavior/bugs/624.zig+1-1| ... | ... | @@ -19,5 +19,5 @@ fn MemoryPool(comptime T: type) type { |
| 19 | 19 | |
| 20 | 20 | test "foo" { |
| 21 | 21 | var allocator = ContextAllocator{ .n = 10 }; |
| 22 | expect(allocator.n == 10); | |
| 22 | try expect(allocator.n == 10); | |
| 23 | 23 | } |
test/stage1/behavior/bugs/6456.zig+4-4| ... | ... | @@ -35,9 +35,9 @@ test "issue 6456" { |
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | 37 | const gen_fields = @typeInfo(T).Struct.fields; |
| 38 | testing.expectEqual(3, gen_fields.len); | |
| 39 | testing.expectEqualStrings("f1", gen_fields[0].name); | |
| 40 | testing.expectEqualStrings("f2", gen_fields[1].name); | |
| 41 | testing.expectEqualStrings("f3", gen_fields[2].name); | |
| 38 | try testing.expectEqual(3, gen_fields.len); | |
| 39 | try testing.expectEqualStrings("f1", gen_fields[0].name); | |
| 40 | try testing.expectEqualStrings("f2", gen_fields[1].name); | |
| 41 | try testing.expectEqualStrings("f3", gen_fields[2].name); | |
| 42 | 42 | } |
| 43 | 43 | } |
test/stage1/behavior/bugs/655.zig+4-4| ... | ... | @@ -3,10 +3,10 @@ const other_file = @import("655_other_file.zig"); |
| 3 | 3 | |
| 4 | 4 | test "function with *const parameter with type dereferenced by namespace" { |
| 5 | 5 | const x: other_file.Integer = 1234; |
| 6 | comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer); | |
| 7 | foo(&x); | |
| 6 | comptime try std.testing.expect(@TypeOf(&x) == *const other_file.Integer); | |
| 7 | try foo(&x); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn foo(x: *const other_file.Integer) void { | |
| 11 | std.testing.expect(x.* == 1234); | |
| 10 | fn foo(x: *const other_file.Integer) !void { | |
| 11 | try std.testing.expect(x.* == 1234); | |
| 12 | 12 | } |
test/stage1/behavior/bugs/656.zig+3-3| ... | ... | @@ -10,10 +10,10 @@ const Value = struct { |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | test "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 | } |
| 15 | 15 | |
| 16 | fn foo(a: bool, b: bool) void { | |
| 16 | fn foo(a: bool, b: bool) !void { | |
| 17 | 17 | var prefix_op = PrefixOp{ |
| 18 | 18 | .AddrOf = Value{ .align_expr = 1234 }, |
| 19 | 19 | }; |
| ... | ... | @@ -22,7 +22,7 @@ fn foo(a: bool, b: bool) void { |
| 22 | 22 | PrefixOp.AddrOf => |addr_of_info| { |
| 23 | 23 | if (b) {} |
| 24 | 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 | 28 | PrefixOp.Return => {}, |
test/stage1/behavior/bugs/679.zig+1-1| ... | ... | @@ -13,5 +13,5 @@ const Element = struct { |
| 13 | 13 | test "false dependency loop in struct definition" { |
| 14 | 14 | const listType = ElementList; |
| 15 | 15 | var x: listType = 42; |
| 16 | expect(x == 42); | |
| 16 | try expect(x == 42); | |
| 17 | 17 | } |
test/stage1/behavior/bugs/6850.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ test "lazy sizeof comparison with zero" { |
| 4 | 4 | const Empty = struct {}; |
| 5 | 5 | const T = *Empty; |
| 6 | 6 | |
| 7 | std.testing.expect(hasNoBits(T)); | |
| 7 | try std.testing.expect(hasNoBits(T)); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | fn hasNoBits(comptime T: type) bool { |
test/stage1/behavior/bugs/7047.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ fn S(comptime query: U) type { |
| 15 | 15 | |
| 16 | 16 | test "compiler doesn't consider equal unions with different 'type' payload" { |
| 17 | 17 | const s1 = S(U{ .T = u32 }).tag(); |
| 18 | std.testing.expectEqual(u32, s1); | |
| 18 | try std.testing.expectEqual(u32, s1); | |
| 19 | 19 | |
| 20 | 20 | const s2 = S(U{ .T = u64 }).tag(); |
| 21 | std.testing.expectEqual(u64, s2); | |
| 21 | try std.testing.expectEqual(u64, s2); | |
| 22 | 22 | } |
test/stage1/behavior/bugs/718.zig+4-4| ... | ... | @@ -10,8 +10,8 @@ const Keys = struct { |
| 10 | 10 | var keys: Keys = undefined; |
| 11 | 11 | test "zero keys with @memset" { |
| 12 | 12 | @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys))); |
| 13 | expect(!keys.up); | |
| 14 | expect(!keys.down); | |
| 15 | expect(!keys.left); | |
| 16 | expect(!keys.right); | |
| 13 | try expect(!keys.up); | |
| 14 | try expect(!keys.down); | |
| 15 | try expect(!keys.left); | |
| 16 | try expect(!keys.right); | |
| 17 | 17 | } |
test/stage1/behavior/bugs/726.zig+2-2| ... | ... | @@ -3,7 +3,7 @@ const expect = @import("std").testing.expect; |
| 3 | 3 | test "@ptrCast from const to nullable" { |
| 4 | 4 | const c: u8 = 4; |
| 5 | 5 | var x: ?*const u8 = @ptrCast(?*const u8, &c); |
| 6 | expect(x.?.* == 4); | |
| 6 | try expect(x.?.* == 4); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "@ptrCast from var in empty struct to nullable" { |
| ... | ... | @@ -11,5 +11,5 @@ test "@ptrCast from var in empty struct to nullable" { |
| 11 | 11 | var c: u8 = 4; |
| 12 | 12 | }; |
| 13 | 13 | var x: ?*const u8 = @ptrCast(?*const u8, &container.c); |
| 14 | expect(x.?.* == 4); | |
| 14 | try expect(x.?.* == 4); | |
| 15 | 15 | } |
test/stage1/behavior/bugs/920.zig+1-1| ... | ... | @@ -60,6 +60,6 @@ test "bug 920 fixed" { |
| 60 | 60 | }; |
| 61 | 61 | |
| 62 | 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/stage1/behavior/byteswap.zig+33-33| ... | ... | @@ -3,39 +3,39 @@ const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "@byteSwap integers" { |
| 5 | 5 | const ByteSwapIntTest = struct { |
| 6 | fn run() void { | |
| 7 | t(u0, 0, 0); | |
| 8 | t(u8, 0x12, 0x12); | |
| 9 | t(u16, 0x1234, 0x3412); | |
| 10 | t(u24, 0x123456, 0x563412); | |
| 11 | t(u32, 0x12345678, 0x78563412); | |
| 12 | t(u40, 0x123456789a, 0x9a78563412); | |
| 13 | t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); | |
| 14 | t(u56, 0x123456789abcde, 0xdebc9a78563412); | |
| 15 | t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); | |
| 16 | t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); | |
| 6 | fn run() !void { | |
| 7 | try t(u0, 0, 0); | |
| 8 | try t(u8, 0x12, 0x12); | |
| 9 | try t(u16, 0x1234, 0x3412); | |
| 10 | try t(u24, 0x123456, 0x563412); | |
| 11 | try t(u32, 0x12345678, 0x78563412); | |
| 12 | try t(u40, 0x123456789a, 0x9a78563412); | |
| 13 | try t(i48, 0x123456789abc, @bitCast(i48, @as(u48, 0xbc9a78563412))); | |
| 14 | try t(u56, 0x123456789abcde, 0xdebc9a78563412); | |
| 15 | try t(u64, 0x123456789abcdef1, 0xf1debc9a78563412); | |
| 16 | try t(u128, 0x123456789abcdef11121314151617181, 0x8171615141312111f1debc9a78563412); | |
| 17 | 17 | |
| 18 | t(u0, @as(u0, 0), 0); | |
| 19 | t(i8, @as(i8, -50), -50); | |
| 20 | t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412))); | |
| 21 | t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412))); | |
| 22 | t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412))); | |
| 23 | t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412)); | |
| 24 | t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412))); | |
| 25 | t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412))); | |
| 26 | t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412))); | |
| 27 | t( | |
| 18 | try t(u0, @as(u0, 0), 0); | |
| 19 | try t(i8, @as(i8, -50), -50); | |
| 20 | try t(i16, @bitCast(i16, @as(u16, 0x1234)), @bitCast(i16, @as(u16, 0x3412))); | |
| 21 | try t(i24, @bitCast(i24, @as(u24, 0x123456)), @bitCast(i24, @as(u24, 0x563412))); | |
| 22 | try t(i32, @bitCast(i32, @as(u32, 0x12345678)), @bitCast(i32, @as(u32, 0x78563412))); | |
| 23 | try t(u40, @bitCast(i40, @as(u40, 0x123456789a)), @as(u40, 0x9a78563412)); | |
| 24 | try t(i48, @bitCast(i48, @as(u48, 0x123456789abc)), @bitCast(i48, @as(u48, 0xbc9a78563412))); | |
| 25 | try t(i56, @bitCast(i56, @as(u56, 0x123456789abcde)), @bitCast(i56, @as(u56, 0xdebc9a78563412))); | |
| 26 | try t(i64, @bitCast(i64, @as(u64, 0x123456789abcdef1)), @bitCast(i64, @as(u64, 0xf1debc9a78563412))); | |
| 27 | try t( | |
| 28 | 28 | i128, |
| 29 | 29 | @bitCast(i128, @as(u128, 0x123456789abcdef11121314151617181)), |
| 30 | 30 | @bitCast(i128, @as(u128, 0x8171615141312111f1debc9a78563412)), |
| 31 | 31 | ); |
| 32 | 32 | } |
| 33 | fn t(comptime I: type, input: I, expected_output: I) void { | |
| 34 | std.testing.expectEqual(expected_output, @byteSwap(I, input)); | |
| 33 | fn t(comptime I: type, input: I, expected_output: I) !void { | |
| 34 | try std.testing.expectEqual(expected_output, @byteSwap(I, input)); | |
| 35 | 35 | } |
| 36 | 36 | }; |
| 37 | comptime ByteSwapIntTest.run(); | |
| 38 | ByteSwapIntTest.run(); | |
| 37 | comptime try ByteSwapIntTest.run(); | |
| 38 | try ByteSwapIntTest.run(); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | test "@byteSwap vectors" { |
| ... | ... | @@ -46,10 +46,10 @@ test "@byteSwap vectors" { |
| 46 | 46 | if (std.Target.current.cpu.arch == .mipsel or std.Target.current.cpu.arch == .mips) return error.SkipZigTest; |
| 47 | 47 | |
| 48 | 48 | const ByteSwapVectorTest = struct { |
| 49 | fn run() void { | |
| 50 | t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 }); | |
| 51 | t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 }); | |
| 52 | t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 }); | |
| 49 | fn run() !void { | |
| 50 | try t(u8, 2, [_]u8{ 0x12, 0x13 }, [_]u8{ 0x12, 0x13 }); | |
| 51 | try t(u16, 2, [_]u16{ 0x1234, 0x2345 }, [_]u16{ 0x3412, 0x4523 }); | |
| 52 | try t(u24, 2, [_]u24{ 0x123456, 0x234567 }, [_]u24{ 0x563412, 0x674523 }); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn t( |
| ... | ... | @@ -57,12 +57,12 @@ test "@byteSwap vectors" { |
| 57 | 57 | comptime n: comptime_int, |
| 58 | 58 | input: std.meta.Vector(n, I), |
| 59 | 59 | expected_vector: std.meta.Vector(n, I), |
| 60 | ) void { | |
| 60 | ) !void { | |
| 61 | 61 | const actual_output: [n]I = @byteSwap(I, input); |
| 62 | 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(); | |
| 67 | ByteSwapVectorTest.run(); | |
| 66 | comptime try ByteSwapVectorTest.run(); | |
| 67 | try ByteSwapVectorTest.run(); | |
| 68 | 68 | } |
test/stage1/behavior/byval_arg_var.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ test "pass string literal byvalue to a generic var param" { |
| 6 | 6 | start(); |
| 7 | 7 | blowUpStack(10); |
| 8 | 8 | |
| 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 | } |
| 11 | 11 | |
| 12 | 12 | fn start() void { |
test/stage1/behavior/call.zig+19-19| ... | ... | @@ -8,25 +8,25 @@ test "basic invocations" { |
| 8 | 8 | return 1234; |
| 9 | 9 | } |
| 10 | 10 | }.foo; |
| 11 | expect(@call(.{}, foo, .{}) == 1234); | |
| 11 | try expect(@call(.{}, foo, .{}) == 1234); | |
| 12 | 12 | comptime { |
| 13 | 13 | // modifiers that allow comptime calls |
| 14 | expect(@call(.{}, foo, .{}) == 1234); | |
| 15 | expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234); | |
| 16 | expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234); | |
| 17 | expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234); | |
| 14 | try expect(@call(.{}, foo, .{}) == 1234); | |
| 15 | try expect(@call(.{ .modifier = .no_async }, foo, .{}) == 1234); | |
| 16 | try expect(@call(.{ .modifier = .always_tail }, foo, .{}) == 1234); | |
| 17 | try expect(@call(.{ .modifier = .always_inline }, foo, .{}) == 1234); | |
| 18 | 18 | } |
| 19 | 19 | { |
| 20 | 20 | // comptime call without comptime keyword |
| 21 | 21 | const result = @call(.{ .modifier = .compile_time }, foo, .{}) == 1234; |
| 22 | comptime expect(result); | |
| 22 | comptime try expect(result); | |
| 23 | 23 | } |
| 24 | 24 | { |
| 25 | 25 | // call of non comptime-known function |
| 26 | 26 | var alias_foo = foo; |
| 27 | expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234); | |
| 28 | expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234); | |
| 29 | expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234); | |
| 27 | try expect(@call(.{ .modifier = .no_async }, alias_foo, .{}) == 1234); | |
| 28 | try expect(@call(.{ .modifier = .never_tail }, alias_foo, .{}) == 1234); | |
| 29 | try expect(@call(.{ .modifier = .never_inline }, alias_foo, .{}) == 1234); | |
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| ... | ... | @@ -38,20 +38,20 @@ test "tuple parameters" { |
| 38 | 38 | }.add; |
| 39 | 39 | var a: i32 = 12; |
| 40 | 40 | var b: i32 = 34; |
| 41 | expect(@call(.{}, add, .{ a, 34 }) == 46); | |
| 42 | expect(@call(.{}, add, .{ 12, b }) == 46); | |
| 43 | expect(@call(.{}, add, .{ a, b }) == 46); | |
| 44 | expect(@call(.{}, add, .{ 12, 34 }) == 46); | |
| 45 | comptime expect(@call(.{}, add, .{ 12, 34 }) == 46); | |
| 41 | try expect(@call(.{}, add, .{ a, 34 }) == 46); | |
| 42 | try expect(@call(.{}, add, .{ 12, b }) == 46); | |
| 43 | try expect(@call(.{}, add, .{ a, b }) == 46); | |
| 44 | try expect(@call(.{}, add, .{ 12, 34 }) == 46); | |
| 45 | comptime try expect(@call(.{}, add, .{ 12, 34 }) == 46); | |
| 46 | 46 | { |
| 47 | 47 | const separate_args0 = .{ a, b }; |
| 48 | 48 | const separate_args1 = .{ a, 34 }; |
| 49 | 49 | const separate_args2 = .{ 12, 34 }; |
| 50 | 50 | const separate_args3 = .{ 12, b }; |
| 51 | expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46); | |
| 52 | expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46); | |
| 53 | expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46); | |
| 54 | expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); | |
| 51 | try expect(@call(.{ .modifier = .always_inline }, add, separate_args0) == 46); | |
| 52 | try expect(@call(.{ .modifier = .always_inline }, add, separate_args1) == 46); | |
| 53 | try expect(@call(.{ .modifier = .always_inline }, add, separate_args2) == 46); | |
| 54 | try expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); | |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| ... | ... | @@ -70,5 +70,5 @@ test "comptime call with bound function as parameter" { |
| 70 | 70 | }; |
| 71 | 71 | |
| 72 | 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/stage1/behavior/cast.zig+226-226| ... | ... | @@ -8,12 +8,12 @@ test "int to ptr cast" { |
| 8 | 8 | const x = @as(usize, 13); |
| 9 | 9 | const y = @intToPtr(*u8, x); |
| 10 | 10 | const z = @ptrToInt(y); |
| 11 | expect(z == 13); | |
| 11 | try expect(z == 13); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "integer literal to pointer cast" { |
| 15 | 15 | const vga_mem = @intToPtr(*u16, 0xB8000); |
| 16 | expect(@ptrToInt(vga_mem) == 0xB8000); | |
| 16 | try expect(@ptrToInt(vga_mem) == 0xB8000); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "pointer reinterpret const float to int" { |
| ... | ... | @@ -23,9 +23,9 @@ test "pointer reinterpret const float to int" { |
| 23 | 23 | const int_ptr = @ptrCast(*const i32, float_ptr); |
| 24 | 24 | const int_val = int_ptr.*; |
| 25 | 25 | if (std.builtin.endian == .Little) |
| 26 | expect(int_val == 0x33333303) | |
| 26 | try expect(int_val == 0x33333303) | |
| 27 | 27 | else |
| 28 | expect(int_val == 0x3fe33333); | |
| 28 | try expect(int_val == 0x3fe33333); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| ... | ... | @@ -49,62 +49,62 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| 49 | 49 | const p = &s; |
| 50 | 50 | const q = &p; |
| 51 | 51 | const r = &q; |
| 52 | expect(42 == S.constConst(q)); | |
| 53 | expect(42 == S.maybeConstConst(q)); | |
| 54 | expect(42 == S.constConstConst(r)); | |
| 55 | expect(42 == S.maybeConstConstConst(r)); | |
| 52 | try expect(42 == S.constConst(q)); | |
| 53 | try expect(42 == S.maybeConstConst(q)); | |
| 54 | try expect(42 == S.constConstConst(r)); | |
| 55 | try expect(42 == S.maybeConstConstConst(r)); | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | test "explicit cast from integer to error type" { |
| 59 | testCastIntToErr(error.ItBroke); | |
| 60 | comptime testCastIntToErr(error.ItBroke); | |
| 59 | try testCastIntToErr(error.ItBroke); | |
| 60 | comptime try testCastIntToErr(error.ItBroke); | |
| 61 | 61 | } |
| 62 | fn testCastIntToErr(err: anyerror) void { | |
| 62 | fn testCastIntToErr(err: anyerror) !void { | |
| 63 | 63 | const x = @errorToInt(err); |
| 64 | 64 | const y = @intToError(x); |
| 65 | expect(error.ItBroke == y); | |
| 65 | try expect(error.ItBroke == y); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "peer resolve arrays of different size to const slice" { |
| 69 | expect(mem.eql(u8, boolToStr(true), "true")); | |
| 70 | expect(mem.eql(u8, boolToStr(false), "false")); | |
| 71 | comptime expect(mem.eql(u8, boolToStr(true), "true")); | |
| 72 | comptime expect(mem.eql(u8, boolToStr(false), "false")); | |
| 69 | try expect(mem.eql(u8, boolToStr(true), "true")); | |
| 70 | try expect(mem.eql(u8, boolToStr(false), "false")); | |
| 71 | comptime try expect(mem.eql(u8, boolToStr(true), "true")); | |
| 72 | comptime try expect(mem.eql(u8, boolToStr(false), "false")); | |
| 73 | 73 | } |
| 74 | 74 | fn boolToStr(b: bool) []const u8 { |
| 75 | 75 | return if (b) "true" else "false"; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "peer resolve array and const slice" { |
| 79 | testPeerResolveArrayConstSlice(true); | |
| 80 | comptime testPeerResolveArrayConstSlice(true); | |
| 79 | try testPeerResolveArrayConstSlice(true); | |
| 80 | comptime try testPeerResolveArrayConstSlice(true); | |
| 81 | 81 | } |
| 82 | fn testPeerResolveArrayConstSlice(b: bool) void { | |
| 82 | fn testPeerResolveArrayConstSlice(b: bool) !void { | |
| 83 | 83 | const value1 = if (b) "aoeu" else @as([]const u8, "zz"); |
| 84 | 84 | const value2 = if (b) @as([]const u8, "zz") else "aoeu"; |
| 85 | expect(mem.eql(u8, value1, "aoeu")); | |
| 86 | expect(mem.eql(u8, value2, "zz")); | |
| 85 | try expect(mem.eql(u8, value1, "aoeu")); | |
| 86 | try expect(mem.eql(u8, value2, "zz")); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "implicitly cast from T to anyerror!?T" { |
| 90 | castToOptionalTypeError(1); | |
| 91 | comptime castToOptionalTypeError(1); | |
| 90 | try castToOptionalTypeError(1); | |
| 91 | comptime try castToOptionalTypeError(1); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | const A = struct { |
| 95 | 95 | a: i32, |
| 96 | 96 | }; |
| 97 | fn castToOptionalTypeError(z: i32) void { | |
| 97 | fn castToOptionalTypeError(z: i32) !void { | |
| 98 | 98 | const x = @as(i32, 1); |
| 99 | 99 | const y: anyerror!?i32 = x; |
| 100 | expect((try y).? == 1); | |
| 100 | try expect((try y).? == 1); | |
| 101 | 101 | |
| 102 | 102 | const f = z; |
| 103 | 103 | const g: anyerror!?i32 = f; |
| 104 | 104 | |
| 105 | 105 | const a = A{ .a = z }; |
| 106 | 106 | const b: anyerror!?A = a; |
| 107 | expect((b catch unreachable).?.a == 1); | |
| 107 | try expect((b catch unreachable).?.a == 1); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | test "implicitly cast from int to anyerror!?T" { |
| ... | ... | @@ -119,7 +119,7 @@ fn implicitIntLitToOptional() void { |
| 119 | 119 | test "return null from fn() anyerror!?&T" { |
| 120 | 120 | const a = returnNullFromOptionalTypeErrorRef(); |
| 121 | 121 | const b = returnNullLitFromOptionalTypeErrorRef(); |
| 122 | expect((try a) == null and (try b) == null); | |
| 122 | try expect((try a) == null and (try b) == null); | |
| 123 | 123 | } |
| 124 | 124 | fn returnNullFromOptionalTypeErrorRef() anyerror!?*A { |
| 125 | 125 | const a: ?*A = null; |
| ... | ... | @@ -130,11 +130,11 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A { |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | test "peer type resolution: ?T and T" { |
| 133 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 134 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 133 | try expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 134 | try expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 135 | 135 | comptime { |
| 136 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 137 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 136 | try expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 137 | try expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| ... | ... | @@ -146,11 +146,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "peer type resolution: [0]u8 and []const u8" { |
| 149 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 150 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 149 | try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 150 | try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 151 | 151 | comptime { |
| 152 | expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 153 | expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 152 | try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); | |
| 153 | try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); | |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| ... | ... | @@ -162,8 +162,8 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | test "implicitly cast from [N]T to ?[]const T" { |
| 165 | expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 166 | comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 165 | try expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 166 | comptime try expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | fn castToOptionalSlice() ?[]const u8 { |
| ... | ... | @@ -171,12 +171,12 @@ fn castToOptionalSlice() ?[]const u8 { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | test "implicitly cast from [0]T to anyerror![]T" { |
| 174 | testCastZeroArrayToErrSliceMut(); | |
| 175 | comptime testCastZeroArrayToErrSliceMut(); | |
| 174 | try testCastZeroArrayToErrSliceMut(); | |
| 175 | comptime try testCastZeroArrayToErrSliceMut(); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | fn testCastZeroArrayToErrSliceMut() void { | |
| 179 | expect((gimmeErrOrSlice() catch unreachable).len == 0); | |
| 178 | fn testCastZeroArrayToErrSliceMut() !void { | |
| 179 | try expect((gimmeErrOrSlice() catch unreachable).len == 0); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | fn gimmeErrOrSlice() anyerror![]u8 { |
| ... | ... | @@ -189,19 +189,19 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { |
| 189 | 189 | { |
| 190 | 190 | var data = "hi".*; |
| 191 | 191 | const slice = data[0..]; |
| 192 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 193 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 192 | try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 193 | try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 194 | 194 | } |
| 195 | 195 | { |
| 196 | 196 | var data: [2]u8 = "hi".*; |
| 197 | 197 | const slice = data[0..]; |
| 198 | expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 199 | expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 198 | try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); | |
| 199 | try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); | |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | }; |
| 203 | 203 | try S.doTheTest(); |
| 204 | try comptime S.doTheTest(); | |
| 204 | comptime try S.doTheTest(); | |
| 205 | 205 | } |
| 206 | 206 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| 207 | 207 | if (a) { |
| ... | ... | @@ -212,43 +212,43 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | test "resolve undefined with integer" { |
| 215 | testResolveUndefWithInt(true, 1234); | |
| 216 | comptime testResolveUndefWithInt(true, 1234); | |
| 215 | try testResolveUndefWithInt(true, 1234); | |
| 216 | comptime try testResolveUndefWithInt(true, 1234); | |
| 217 | 217 | } |
| 218 | fn testResolveUndefWithInt(b: bool, x: i32) void { | |
| 218 | fn testResolveUndefWithInt(b: bool, x: i32) !void { | |
| 219 | 219 | const value = if (b) x else undefined; |
| 220 | 220 | if (b) { |
| 221 | expect(value == x); | |
| 221 | try expect(value == x); | |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | test "implicit cast from &const [N]T to []const T" { |
| 226 | testCastConstArrayRefToConstSlice(); | |
| 227 | comptime testCastConstArrayRefToConstSlice(); | |
| 226 | try testCastConstArrayRefToConstSlice(); | |
| 227 | comptime try testCastConstArrayRefToConstSlice(); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | fn testCastConstArrayRefToConstSlice() void { | |
| 230 | fn testCastConstArrayRefToConstSlice() !void { | |
| 231 | 231 | { |
| 232 | 232 | const blah = "aoeu".*; |
| 233 | 233 | const const_array_ref = &blah; |
| 234 | expect(@TypeOf(const_array_ref) == *const [4:0]u8); | |
| 234 | try expect(@TypeOf(const_array_ref) == *const [4:0]u8); | |
| 235 | 235 | const slice: []const u8 = const_array_ref; |
| 236 | expect(mem.eql(u8, slice, "aoeu")); | |
| 236 | try expect(mem.eql(u8, slice, "aoeu")); | |
| 237 | 237 | } |
| 238 | 238 | { |
| 239 | 239 | const blah: [4]u8 = "aoeu".*; |
| 240 | 240 | const const_array_ref = &blah; |
| 241 | expect(@TypeOf(const_array_ref) == *const [4]u8); | |
| 241 | try expect(@TypeOf(const_array_ref) == *const [4]u8); | |
| 242 | 242 | const slice: []const u8 = const_array_ref; |
| 243 | expect(mem.eql(u8, slice, "aoeu")); | |
| 243 | try expect(mem.eql(u8, slice, "aoeu")); | |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | test "peer type resolution: error and [N]T" { |
| 248 | expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 249 | comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 250 | expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 251 | comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 248 | try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 249 | comptime try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 250 | try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 251 | comptime try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | fn testPeerErrorAndArray(x: u8) anyerror![]const u8 { |
| ... | ... | @@ -266,35 +266,35 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 { |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | test "@floatToInt" { |
| 269 | testFloatToInts(); | |
| 270 | comptime testFloatToInts(); | |
| 269 | try testFloatToInts(); | |
| 270 | comptime try testFloatToInts(); | |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | fn testFloatToInts() void { | |
| 273 | fn testFloatToInts() !void { | |
| 274 | 274 | const x = @as(i32, 1e4); |
| 275 | expect(x == 10000); | |
| 275 | try expect(x == 10000); | |
| 276 | 276 | const y = @floatToInt(i32, @as(f32, 1e4)); |
| 277 | expect(y == 10000); | |
| 278 | expectFloatToInt(f16, 255.1, u8, 255); | |
| 279 | expectFloatToInt(f16, 127.2, i8, 127); | |
| 280 | expectFloatToInt(f16, -128.2, i8, -128); | |
| 281 | expectFloatToInt(f32, 255.1, u8, 255); | |
| 282 | expectFloatToInt(f32, 127.2, i8, 127); | |
| 283 | expectFloatToInt(f32, -128.2, i8, -128); | |
| 284 | expectFloatToInt(comptime_int, 1234, i16, 1234); | |
| 277 | try expect(y == 10000); | |
| 278 | try expectFloatToInt(f16, 255.1, u8, 255); | |
| 279 | try expectFloatToInt(f16, 127.2, i8, 127); | |
| 280 | try expectFloatToInt(f16, -128.2, i8, -128); | |
| 281 | try expectFloatToInt(f32, 255.1, u8, 255); | |
| 282 | try expectFloatToInt(f32, 127.2, i8, 127); | |
| 283 | try expectFloatToInt(f32, -128.2, i8, -128); | |
| 284 | try expectFloatToInt(comptime_int, 1234, i16, 1234); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void { | |
| 288 | expect(@floatToInt(I, f) == i); | |
| 287 | fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) !void { | |
| 288 | try expect(@floatToInt(I, f) == i); | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | test "cast u128 to f128 and back" { |
| 292 | comptime testCast128(); | |
| 293 | testCast128(); | |
| 292 | comptime try testCast128(); | |
| 293 | try testCast128(); | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | fn testCast128() void { | |
| 297 | expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); | |
| 296 | fn testCast128() !void { | |
| 297 | try expect(cast128Int(cast128Float(0x7fff0000000000000000000000000000)) == 0x7fff0000000000000000000000000000); | |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | fn cast128Int(x: f128) u128 { |
| ... | ... | @@ -306,69 +306,69 @@ fn cast128Float(x: u128) f128 { |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | test "single-item pointer of array to slice and to unknown length pointer" { |
| 309 | testCastPtrOfArrayToSliceAndPtr(); | |
| 310 | comptime testCastPtrOfArrayToSliceAndPtr(); | |
| 309 | try testCastPtrOfArrayToSliceAndPtr(); | |
| 310 | comptime try testCastPtrOfArrayToSliceAndPtr(); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | fn testCastPtrOfArrayToSliceAndPtr() void { | |
| 313 | fn testCastPtrOfArrayToSliceAndPtr() !void { | |
| 314 | 314 | { |
| 315 | 315 | var array = "aoeu".*; |
| 316 | 316 | const x: [*]u8 = &array; |
| 317 | 317 | x[0] += 1; |
| 318 | expect(mem.eql(u8, array[0..], "boeu")); | |
| 318 | try expect(mem.eql(u8, array[0..], "boeu")); | |
| 319 | 319 | const y: []u8 = &array; |
| 320 | 320 | y[0] += 1; |
| 321 | expect(mem.eql(u8, array[0..], "coeu")); | |
| 321 | try expect(mem.eql(u8, array[0..], "coeu")); | |
| 322 | 322 | } |
| 323 | 323 | { |
| 324 | 324 | var array: [4]u8 = "aoeu".*; |
| 325 | 325 | const x: [*]u8 = &array; |
| 326 | 326 | x[0] += 1; |
| 327 | expect(mem.eql(u8, array[0..], "boeu")); | |
| 327 | try expect(mem.eql(u8, array[0..], "boeu")); | |
| 328 | 328 | const y: []u8 = &array; |
| 329 | 329 | y[0] += 1; |
| 330 | expect(mem.eql(u8, array[0..], "coeu")); | |
| 330 | try expect(mem.eql(u8, array[0..], "coeu")); | |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 335 | 335 | const window_name = [1][*]const u8{"window name"}; |
| 336 | 336 | const x: [*]const ?[*]const u8 = &window_name; |
| 337 | expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 337 | try expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | test "@intCast comptime_int" { |
| 341 | 341 | const result = @intCast(i32, 1234); |
| 342 | expect(@TypeOf(result) == i32); | |
| 343 | expect(result == 1234); | |
| 342 | try expect(@TypeOf(result) == i32); | |
| 343 | try expect(result == 1234); | |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | test "@floatCast comptime_int and comptime_float" { |
| 347 | 347 | { |
| 348 | 348 | const result = @floatCast(f16, 1234); |
| 349 | expect(@TypeOf(result) == f16); | |
| 350 | expect(result == 1234.0); | |
| 349 | try expect(@TypeOf(result) == f16); | |
| 350 | try expect(result == 1234.0); | |
| 351 | 351 | } |
| 352 | 352 | { |
| 353 | 353 | const result = @floatCast(f16, 1234.0); |
| 354 | expect(@TypeOf(result) == f16); | |
| 355 | expect(result == 1234.0); | |
| 354 | try expect(@TypeOf(result) == f16); | |
| 355 | try expect(result == 1234.0); | |
| 356 | 356 | } |
| 357 | 357 | { |
| 358 | 358 | const result = @floatCast(f32, 1234); |
| 359 | expect(@TypeOf(result) == f32); | |
| 360 | expect(result == 1234.0); | |
| 359 | try expect(@TypeOf(result) == f32); | |
| 360 | try expect(result == 1234.0); | |
| 361 | 361 | } |
| 362 | 362 | { |
| 363 | 363 | const result = @floatCast(f32, 1234.0); |
| 364 | expect(@TypeOf(result) == f32); | |
| 365 | expect(result == 1234.0); | |
| 364 | try expect(@TypeOf(result) == f32); | |
| 365 | try expect(result == 1234.0); | |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | test "vector casts" { |
| 370 | 370 | const S = struct { |
| 371 | fn doTheTest() void { | |
| 371 | fn doTheTest() !void { | |
| 372 | 372 | // Upcast (implicit, equivalent to @intCast) |
| 373 | 373 | var up0: Vector(2, u8) = [_]u8{ 0x55, 0xaa }; |
| 374 | 374 | var up1 = @as(Vector(2, u16), up0); |
| ... | ... | @@ -380,55 +380,55 @@ test "vector casts" { |
| 380 | 380 | var down2 = @intCast(Vector(2, u16), down0); |
| 381 | 381 | var down3 = @intCast(Vector(2, u8), down0); |
| 382 | 382 | |
| 383 | expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); | |
| 384 | expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); | |
| 385 | expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa })); | |
| 383 | try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa })); | |
| 384 | try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa })); | |
| 385 | try expect(mem.eql(u64, &@as([2]u64, up3), &[2]u64{ 0x55, 0xaa })); | |
| 386 | 386 | |
| 387 | expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa })); | |
| 388 | expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa })); | |
| 389 | expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa })); | |
| 387 | try expect(mem.eql(u32, &@as([2]u32, down1), &[2]u32{ 0x55, 0xaa })); | |
| 388 | try expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa })); | |
| 389 | try expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa })); | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | fn doTheTestFloat() void { | |
| 392 | fn doTheTestFloat() !void { | |
| 393 | 393 | var vec = @splat(2, @as(f32, 1234.0)); |
| 394 | 394 | var wider: Vector(2, f64) = vec; |
| 395 | expect(wider[0] == 1234.0); | |
| 396 | expect(wider[1] == 1234.0); | |
| 395 | try expect(wider[0] == 1234.0); | |
| 396 | try expect(wider[1] == 1234.0); | |
| 397 | 397 | } |
| 398 | 398 | }; |
| 399 | 399 | |
| 400 | S.doTheTest(); | |
| 401 | comptime S.doTheTest(); | |
| 402 | S.doTheTestFloat(); | |
| 403 | comptime S.doTheTestFloat(); | |
| 400 | try S.doTheTest(); | |
| 401 | comptime try S.doTheTest(); | |
| 402 | try S.doTheTestFloat(); | |
| 403 | comptime try S.doTheTestFloat(); | |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | test "comptime_int @intToFloat" { |
| 407 | 407 | { |
| 408 | 408 | const result = @intToFloat(f16, 1234); |
| 409 | expect(@TypeOf(result) == f16); | |
| 410 | expect(result == 1234.0); | |
| 409 | try expect(@TypeOf(result) == f16); | |
| 410 | try expect(result == 1234.0); | |
| 411 | 411 | } |
| 412 | 412 | { |
| 413 | 413 | const result = @intToFloat(f32, 1234); |
| 414 | expect(@TypeOf(result) == f32); | |
| 415 | expect(result == 1234.0); | |
| 414 | try expect(@TypeOf(result) == f32); | |
| 415 | try expect(result == 1234.0); | |
| 416 | 416 | } |
| 417 | 417 | { |
| 418 | 418 | const result = @intToFloat(f64, 1234); |
| 419 | expect(@TypeOf(result) == f64); | |
| 420 | expect(result == 1234.0); | |
| 419 | try expect(@TypeOf(result) == f64); | |
| 420 | try expect(result == 1234.0); | |
| 421 | 421 | } |
| 422 | 422 | { |
| 423 | 423 | const result = @intToFloat(f128, 1234); |
| 424 | expect(@TypeOf(result) == f128); | |
| 425 | expect(result == 1234.0); | |
| 424 | try expect(@TypeOf(result) == f128); | |
| 425 | try expect(result == 1234.0); | |
| 426 | 426 | } |
| 427 | 427 | // big comptime_int (> 64 bits) to f128 conversion |
| 428 | 428 | { |
| 429 | 429 | const result = @intToFloat(f128, 0x1_0000_0000_0000_0000); |
| 430 | expect(@TypeOf(result) == f128); | |
| 431 | expect(result == 0x1_0000_0000_0000_0000.0); | |
| 430 | try expect(@TypeOf(result) == f128); | |
| 431 | try expect(result == 0x1_0000_0000_0000_0000.0); | |
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
| ... | ... | @@ -436,25 +436,25 @@ test "@intCast i32 to u7" { |
| 436 | 436 | var x: u128 = maxInt(u128); |
| 437 | 437 | var y: i32 = 120; |
| 438 | 438 | var z = x >> @intCast(u7, y); |
| 439 | expect(z == 0xff); | |
| 439 | try expect(z == 0xff); | |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | test "@floatCast cast down" { |
| 443 | 443 | { |
| 444 | 444 | var double: f64 = 0.001534; |
| 445 | 445 | var single = @floatCast(f32, double); |
| 446 | expect(single == 0.001534); | |
| 446 | try expect(single == 0.001534); | |
| 447 | 447 | } |
| 448 | 448 | { |
| 449 | 449 | const double: f64 = 0.001534; |
| 450 | 450 | const single = @floatCast(f32, double); |
| 451 | expect(single == 0.001534); | |
| 451 | try expect(single == 0.001534); | |
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | test "implicit cast undefined to optional" { |
| 456 | expect(MakeType(void).getNull() == null); | |
| 457 | expect(MakeType(void).getNonNull() != null); | |
| 456 | try expect(MakeType(void).getNull() == null); | |
| 457 | try expect(MakeType(void).getNonNull() != null); | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | fn MakeType(comptime T: type) type { |
| ... | ... | @@ -474,26 +474,26 @@ test "implicit cast from *[N]T to ?[*]T" { |
| 474 | 474 | var y: [4]u16 = [4]u16{ 0, 1, 2, 3 }; |
| 475 | 475 | |
| 476 | 476 | x = &y; |
| 477 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 477 | try expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 478 | 478 | x.?[0] = 8; |
| 479 | 479 | y[3] = 6; |
| 480 | expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 480 | try expect(std.mem.eql(u16, x.?[0..4], y[0..4])); | |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | test "implicit cast from *[N]T to [*c]T" { |
| 484 | 484 | var x: [4]u16 = [4]u16{ 0, 1, 2, 3 }; |
| 485 | 485 | var y: [*c]u16 = &x; |
| 486 | 486 | |
| 487 | expect(std.mem.eql(u16, x[0..4], y[0..4])); | |
| 487 | try expect(std.mem.eql(u16, x[0..4], y[0..4])); | |
| 488 | 488 | x[0] = 8; |
| 489 | 489 | y[3] = 6; |
| 490 | expect(std.mem.eql(u16, x[0..4], y[0..4])); | |
| 490 | try expect(std.mem.eql(u16, x[0..4], y[0..4])); | |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | test "implicit cast from *T to ?*c_void" { |
| 494 | 494 | var a: u8 = 1; |
| 495 | 495 | incrementVoidPtrValue(&a); |
| 496 | std.testing.expect(a == 2); | |
| 496 | try std.testing.expect(a == 2); | |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | fn incrementVoidPtrValue(value: ?*c_void) void { |
| ... | ... | @@ -504,7 +504,7 @@ test "implicit cast from [*]T to ?*c_void" { |
| 504 | 504 | var a = [_]u8{ 3, 2, 1 }; |
| 505 | 505 | var runtime_zero: usize = 0; |
| 506 | 506 | incrementVoidPtrArray(a[runtime_zero..].ptr, 3); |
| 507 | expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); | |
| 507 | try expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); | |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { |
| ... | ... | @@ -521,34 +521,34 @@ test "*usize to *void" { |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | test "compile time int to ptr of function" { |
| 524 | foobar(FUNCTION_CONSTANT); | |
| 524 | try foobar(FUNCTION_CONSTANT); | |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize)); |
| 528 | 528 | pub const PFN_void = fn (*c_void) callconv(.C) void; |
| 529 | 529 | |
| 530 | fn foobar(func: PFN_void) void { | |
| 531 | std.testing.expect(@ptrToInt(func) == maxInt(usize)); | |
| 530 | fn foobar(func: PFN_void) !void { | |
| 531 | try std.testing.expect(@ptrToInt(func) == maxInt(usize)); | |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | test "implicit ptr to *c_void" { |
| 535 | 535 | var a: u32 = 1; |
| 536 | 536 | var ptr: *align(@alignOf(u32)) c_void = &a; |
| 537 | 537 | var b: *u32 = @ptrCast(*u32, ptr); |
| 538 | expect(b.* == 1); | |
| 538 | try expect(b.* == 1); | |
| 539 | 539 | var ptr2: ?*align(@alignOf(u32)) c_void = &a; |
| 540 | 540 | var c: *u32 = @ptrCast(*u32, ptr2.?); |
| 541 | expect(c.* == 1); | |
| 541 | try expect(c.* == 1); | |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | test "@intCast to comptime_int" { |
| 545 | expect(@intCast(comptime_int, 0) == 0); | |
| 545 | try expect(@intCast(comptime_int, 0) == 0); | |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | test "implicit cast comptime numbers to any type when the value fits" { |
| 549 | 549 | const a: u64 = 255; |
| 550 | 550 | var b: u8 = a; |
| 551 | expect(b == 255); | |
| 551 | try expect(b == 255); | |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | test "@intToEnum passed a comptime_int to an enum with one item" { |
| ... | ... | @@ -556,7 +556,7 @@ test "@intToEnum passed a comptime_int to an enum with one item" { |
| 556 | 556 | A, |
| 557 | 557 | }; |
| 558 | 558 | const x = @intToEnum(E, 0); |
| 559 | expect(x == E.A); | |
| 559 | try expect(x == E.A); | |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | test "@intToEnum runtime to an extern enum with duplicate values" { |
| ... | ... | @@ -566,33 +566,33 @@ test "@intToEnum runtime to an extern enum with duplicate values" { |
| 566 | 566 | }; |
| 567 | 567 | var a: u8 = 1; |
| 568 | 568 | var x = @intToEnum(E, a); |
| 569 | expect(x == E.A); | |
| 570 | expect(x == E.B); | |
| 569 | try expect(x == E.A); | |
| 570 | try expect(x == E.B); | |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | test "@intCast to u0 and use the result" { |
| 574 | 574 | const S = struct { |
| 575 | fn doTheTest(zero: u1, one: u1, bigzero: i32) void { | |
| 576 | expect((one << @intCast(u0, bigzero)) == 1); | |
| 577 | expect((zero << @intCast(u0, bigzero)) == 0); | |
| 575 | fn doTheTest(zero: u1, one: u1, bigzero: i32) !void { | |
| 576 | try expect((one << @intCast(u0, bigzero)) == 1); | |
| 577 | try expect((zero << @intCast(u0, bigzero)) == 0); | |
| 578 | 578 | } |
| 579 | 579 | }; |
| 580 | S.doTheTest(0, 1, 0); | |
| 581 | comptime S.doTheTest(0, 1, 0); | |
| 580 | try S.doTheTest(0, 1, 0); | |
| 581 | comptime try S.doTheTest(0, 1, 0); | |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | test "peer type resolution: unreachable, null, slice" { |
| 585 | 585 | const S = struct { |
| 586 | fn doTheTest(num: usize, word: []const u8) void { | |
| 586 | fn doTheTest(num: usize, word: []const u8) !void { | |
| 587 | 587 | const result = switch (num) { |
| 588 | 588 | 0 => null, |
| 589 | 589 | 1 => word, |
| 590 | 590 | else => unreachable, |
| 591 | 591 | }; |
| 592 | expect(mem.eql(u8, result.?, "hi")); | |
| 592 | try expect(mem.eql(u8, result.?, "hi")); | |
| 593 | 593 | } |
| 594 | 594 | }; |
| 595 | S.doTheTest(1, "hi"); | |
| 595 | try S.doTheTest(1, "hi"); | |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | test "peer type resolution: unreachable, error set, unreachable" { |
| ... | ... | @@ -615,17 +615,17 @@ test "peer type resolution: unreachable, error set, unreachable" { |
| 615 | 615 | error.FileDescriptorIncompatibleWithEpoll => unreachable, |
| 616 | 616 | error.Unexpected => unreachable, |
| 617 | 617 | }; |
| 618 | expect(transformed_err == error.SystemResources); | |
| 618 | try expect(transformed_err == error.SystemResources); | |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | test "implicit cast comptime_int to comptime_float" { |
| 622 | comptime expect(@as(comptime_float, 10) == @as(f32, 10)); | |
| 623 | expect(2 == 2.0); | |
| 622 | comptime try expect(@as(comptime_float, 10) == @as(f32, 10)); | |
| 623 | try expect(2 == 2.0); | |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | test "implicit cast *[0]T to E![]const u8" { |
| 627 | 627 | var x = @as(anyerror![]const u8, &[0]u8{}); |
| 628 | expect((x catch unreachable).len == 0); | |
| 628 | try expect((x catch unreachable).len == 0); | |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | test "peer cast *[0]T to E![]const T" { |
| ... | ... | @@ -633,7 +633,7 @@ test "peer cast *[0]T to E![]const T" { |
| 633 | 633 | var buf: anyerror![]const u8 = buffer[0..]; |
| 634 | 634 | var b = false; |
| 635 | 635 | var y = if (b) &[0]u8{} else buf; |
| 636 | expect(mem.eql(u8, "abcde", y catch unreachable)); | |
| 636 | try expect(mem.eql(u8, "abcde", y catch unreachable)); | |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | test "peer cast *[0]T to []const T" { |
| ... | ... | @@ -641,25 +641,25 @@ test "peer cast *[0]T to []const T" { |
| 641 | 641 | var buf: []const u8 = buffer[0..]; |
| 642 | 642 | var b = false; |
| 643 | 643 | var y = if (b) &[0]u8{} else buf; |
| 644 | expect(mem.eql(u8, "abcde", y)); | |
| 644 | try expect(mem.eql(u8, "abcde", y)); | |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | var global_array: [4]u8 = undefined; |
| 648 | 648 | test "cast from array reference to fn" { |
| 649 | 649 | const f = @ptrCast(fn () callconv(.C) void, &global_array); |
| 650 | expect(@ptrToInt(f) == @ptrToInt(&global_array)); | |
| 650 | try expect(@ptrToInt(f) == @ptrToInt(&global_array)); | |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | test "*const [N]null u8 to ?[]const u8" { |
| 654 | 654 | const S = struct { |
| 655 | fn doTheTest() void { | |
| 655 | fn doTheTest() !void { | |
| 656 | 656 | var a = "Hello"; |
| 657 | 657 | var b: ?[]const u8 = a; |
| 658 | expect(mem.eql(u8, b.?, "Hello")); | |
| 658 | try expect(mem.eql(u8, b.?, "Hello")); | |
| 659 | 659 | } |
| 660 | 660 | }; |
| 661 | S.doTheTest(); | |
| 662 | comptime S.doTheTest(); | |
| 661 | try S.doTheTest(); | |
| 662 | comptime try S.doTheTest(); | |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | test "peer resolution of string literals" { |
| ... | ... | @@ -671,54 +671,54 @@ test "peer resolution of string literals" { |
| 671 | 671 | d, |
| 672 | 672 | }; |
| 673 | 673 | |
| 674 | fn doTheTest(e: E) void { | |
| 674 | fn doTheTest(e: E) !void { | |
| 675 | 675 | const cmd = switch (e) { |
| 676 | 676 | .a => "one", |
| 677 | 677 | .b => "two", |
| 678 | 678 | .c => "three", |
| 679 | 679 | .d => "four", |
| 680 | 680 | }; |
| 681 | expect(mem.eql(u8, cmd, "two")); | |
| 681 | try expect(mem.eql(u8, cmd, "two")); | |
| 682 | 682 | } |
| 683 | 683 | }; |
| 684 | S.doTheTest(.b); | |
| 685 | comptime S.doTheTest(.b); | |
| 684 | try S.doTheTest(.b); | |
| 685 | comptime try S.doTheTest(.b); | |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | test "type coercion related to sentinel-termination" { |
| 689 | 689 | const S = struct { |
| 690 | fn doTheTest() void { | |
| 690 | fn doTheTest() !void { | |
| 691 | 691 | // [:x]T to []T |
| 692 | 692 | { |
| 693 | 693 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 694 | 694 | var slice: [:0]i32 = &array; |
| 695 | 695 | var dest: []i32 = slice; |
| 696 | expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 696 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // [*:x]T to [*]T |
| 700 | 700 | { |
| 701 | 701 | var array = [4:99]i32{ 1, 2, 3, 4 }; |
| 702 | 702 | var dest: [*]i32 = &array; |
| 703 | expect(dest[0] == 1); | |
| 704 | expect(dest[1] == 2); | |
| 705 | expect(dest[2] == 3); | |
| 706 | expect(dest[3] == 4); | |
| 707 | expect(dest[4] == 99); | |
| 703 | try expect(dest[0] == 1); | |
| 704 | try expect(dest[1] == 2); | |
| 705 | try expect(dest[2] == 3); | |
| 706 | try expect(dest[3] == 4); | |
| 707 | try expect(dest[4] == 99); | |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | // [N:x]T to [N]T |
| 711 | 711 | { |
| 712 | 712 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 713 | 713 | var dest: [4]i32 = array; |
| 714 | expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 714 | try expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | // *[N:x]T to *[N]T |
| 718 | 718 | { |
| 719 | 719 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 720 | 720 | var dest: *[4]i32 = &array; |
| 721 | expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 721 | try expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); | |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // [:x]T to [*:x]T |
| ... | ... | @@ -726,24 +726,24 @@ test "type coercion related to sentinel-termination" { |
| 726 | 726 | var array = [4:0]i32{ 1, 2, 3, 4 }; |
| 727 | 727 | var slice: [:0]i32 = &array; |
| 728 | 728 | var dest: [*:0]i32 = slice; |
| 729 | expect(dest[0] == 1); | |
| 730 | expect(dest[1] == 2); | |
| 731 | expect(dest[2] == 3); | |
| 732 | expect(dest[3] == 4); | |
| 733 | expect(dest[4] == 0); | |
| 729 | try expect(dest[0] == 1); | |
| 730 | try expect(dest[1] == 2); | |
| 731 | try expect(dest[2] == 3); | |
| 732 | try expect(dest[3] == 4); | |
| 733 | try expect(dest[4] == 0); | |
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | }; |
| 737 | S.doTheTest(); | |
| 738 | comptime S.doTheTest(); | |
| 737 | try S.doTheTest(); | |
| 738 | comptime try S.doTheTest(); | |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | test "cast i8 fn call peers to i32 result" { |
| 742 | 742 | const S = struct { |
| 743 | fn doTheTest() void { | |
| 743 | fn doTheTest() !void { | |
| 744 | 744 | var cond = true; |
| 745 | 745 | const value: i32 = if (cond) smallBoi() else bigBoi(); |
| 746 | expect(value == 123); | |
| 746 | try expect(value == 123); | |
| 747 | 747 | } |
| 748 | 748 | fn smallBoi() i8 { |
| 749 | 749 | return 123; |
| ... | ... | @@ -752,21 +752,21 @@ test "cast i8 fn call peers to i32 result" { |
| 752 | 752 | return 1234; |
| 753 | 753 | } |
| 754 | 754 | }; |
| 755 | S.doTheTest(); | |
| 756 | comptime S.doTheTest(); | |
| 755 | try S.doTheTest(); | |
| 756 | comptime try S.doTheTest(); | |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | test "return u8 coercing into ?u32 return type" { |
| 760 | 760 | const S = struct { |
| 761 | fn doTheTest() void { | |
| 762 | expect(foo(123).? == 123); | |
| 761 | fn doTheTest() !void { | |
| 762 | try expect(foo(123).? == 123); | |
| 763 | 763 | } |
| 764 | 764 | fn foo(arg: u8) ?u32 { |
| 765 | 765 | return arg; |
| 766 | 766 | } |
| 767 | 767 | }; |
| 768 | S.doTheTest(); | |
| 769 | comptime S.doTheTest(); | |
| 768 | try S.doTheTest(); | |
| 769 | comptime try S.doTheTest(); | |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | test "peer result null and comptime_int" { |
| ... | ... | @@ -782,17 +782,17 @@ test "peer result null and comptime_int" { |
| 782 | 782 | } |
| 783 | 783 | }; |
| 784 | 784 | |
| 785 | expect(S.blah(0) == null); | |
| 786 | comptime expect(S.blah(0) == null); | |
| 787 | expect(S.blah(10).? == 1); | |
| 788 | comptime expect(S.blah(10).? == 1); | |
| 789 | expect(S.blah(-10).? == -1); | |
| 790 | comptime expect(S.blah(-10).? == -1); | |
| 785 | try expect(S.blah(0) == null); | |
| 786 | comptime try expect(S.blah(0) == null); | |
| 787 | try expect(S.blah(10).? == 1); | |
| 788 | comptime try expect(S.blah(10).? == 1); | |
| 789 | try expect(S.blah(-10).? == -1); | |
| 790 | comptime try expect(S.blah(-10).? == -1); | |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | test "peer type resolution implicit cast to return type" { |
| 794 | 794 | const S = struct { |
| 795 | fn doTheTest() void { | |
| 795 | fn doTheTest() !void { | |
| 796 | 796 | for ("hello") |c| _ = f(c); |
| 797 | 797 | } |
| 798 | 798 | fn f(c: u8) []const u8 { |
| ... | ... | @@ -803,13 +803,13 @@ test "peer type resolution implicit cast to return type" { |
| 803 | 803 | }; |
| 804 | 804 | } |
| 805 | 805 | }; |
| 806 | S.doTheTest(); | |
| 807 | comptime S.doTheTest(); | |
| 806 | try S.doTheTest(); | |
| 807 | comptime try S.doTheTest(); | |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | test "peer type resolution implicit cast to variable type" { |
| 811 | 811 | const S = struct { |
| 812 | fn doTheTest() void { | |
| 812 | fn doTheTest() !void { | |
| 813 | 813 | var x: []const u8 = undefined; |
| 814 | 814 | for ("hello") |c| x = switch (c) { |
| 815 | 815 | 'h', 'e' => &[_]u8{c}, // should cast to slice |
| ... | ... | @@ -818,14 +818,14 @@ test "peer type resolution implicit cast to variable type" { |
| 818 | 818 | }; |
| 819 | 819 | } |
| 820 | 820 | }; |
| 821 | S.doTheTest(); | |
| 822 | comptime S.doTheTest(); | |
| 821 | try S.doTheTest(); | |
| 822 | comptime try S.doTheTest(); | |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | test "variable initialization uses result locations properly with regards to the type" { |
| 826 | 826 | var b = true; |
| 827 | 827 | const x: i32 = if (b) 1 else 2; |
| 828 | expect(x == 1); | |
| 828 | try expect(x == 1); | |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | test "cast between [*c]T and ?[*:0]T on fn parameter" { |
| ... | ... | @@ -847,27 +847,27 @@ test "cast between C pointer with different but compatible types" { |
| 847 | 847 | fn foo(arg: [*]c_ushort) u16 { |
| 848 | 848 | return arg[0]; |
| 849 | 849 | } |
| 850 | fn doTheTest() void { | |
| 850 | fn doTheTest() !void { | |
| 851 | 851 | var x = [_]u16{ 4, 2, 1, 3 }; |
| 852 | expect(foo(@ptrCast([*]u16, &x)) == 4); | |
| 852 | try expect(foo(@ptrCast([*]u16, &x)) == 4); | |
| 853 | 853 | } |
| 854 | 854 | }; |
| 855 | S.doTheTest(); | |
| 855 | try S.doTheTest(); | |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | var global_struct: struct { f0: usize } = undefined; |
| 859 | 859 | |
| 860 | 860 | test "assignment to optional pointer result loc" { |
| 861 | 861 | var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct }; |
| 862 | expect(foo.ptr.? == @ptrCast(*c_void, &global_struct)); | |
| 862 | try expect(foo.ptr.? == @ptrCast(*c_void, &global_struct)); | |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | test "peer type resolve string lit with sentinel-terminated mutable slice" { |
| 866 | 866 | var array: [4:0]u8 = undefined; |
| 867 | 867 | array[4] = 0; // TODO remove this when #4372 is solved |
| 868 | 868 | var slice: [:0]u8 = array[0..4 :0]; |
| 869 | comptime expect(@TypeOf(slice, "hi") == [:0]const u8); | |
| 870 | comptime expect(@TypeOf("hi", slice) == [:0]const u8); | |
| 869 | comptime try expect(@TypeOf(slice, "hi") == [:0]const u8); | |
| 870 | comptime try expect(@TypeOf("hi", slice) == [:0]const u8); | |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | test "peer type unsigned int to signed" { |
| ... | ... | @@ -875,15 +875,15 @@ test "peer type unsigned int to signed" { |
| 875 | 875 | var x: u8 = 7; |
| 876 | 876 | var y: i32 = -5; |
| 877 | 877 | var a = w + y + x; |
| 878 | comptime expect(@TypeOf(a) == i32); | |
| 879 | expect(a == 7); | |
| 878 | comptime try expect(@TypeOf(a) == i32); | |
| 879 | try expect(a == 7); | |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | test "peer type resolve array pointers, one of them const" { |
| 883 | 883 | var array1: [4]u8 = undefined; |
| 884 | 884 | const array2: [5]u8 = undefined; |
| 885 | comptime expect(@TypeOf(&array1, &array2) == []const u8); | |
| 886 | comptime expect(@TypeOf(&array2, &array1) == []const u8); | |
| 885 | comptime try expect(@TypeOf(&array1, &array2) == []const u8); | |
| 886 | comptime try expect(@TypeOf(&array2, &array1) == []const u8); | |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | test "peer type resolve array pointer and unknown pointer" { |
| ... | ... | @@ -892,35 +892,35 @@ test "peer type resolve array pointer and unknown pointer" { |
| 892 | 892 | var const_ptr: [*]const u8 = undefined; |
| 893 | 893 | var ptr: [*]u8 = undefined; |
| 894 | 894 | |
| 895 | comptime expect(@TypeOf(&array, ptr) == [*]u8); | |
| 896 | comptime expect(@TypeOf(ptr, &array) == [*]u8); | |
| 895 | comptime try expect(@TypeOf(&array, ptr) == [*]u8); | |
| 896 | comptime try expect(@TypeOf(ptr, &array) == [*]u8); | |
| 897 | 897 | |
| 898 | comptime expect(@TypeOf(&const_array, ptr) == [*]const u8); | |
| 899 | comptime expect(@TypeOf(ptr, &const_array) == [*]const u8); | |
| 898 | comptime try expect(@TypeOf(&const_array, ptr) == [*]const u8); | |
| 899 | comptime try expect(@TypeOf(ptr, &const_array) == [*]const u8); | |
| 900 | 900 | |
| 901 | comptime expect(@TypeOf(&array, const_ptr) == [*]const u8); | |
| 902 | comptime expect(@TypeOf(const_ptr, &array) == [*]const u8); | |
| 901 | comptime try expect(@TypeOf(&array, const_ptr) == [*]const u8); | |
| 902 | comptime try expect(@TypeOf(const_ptr, &array) == [*]const u8); | |
| 903 | 903 | |
| 904 | comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8); | |
| 905 | comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8); | |
| 904 | comptime try expect(@TypeOf(&const_array, const_ptr) == [*]const u8); | |
| 905 | comptime try expect(@TypeOf(const_ptr, &const_array) == [*]const u8); | |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | test "comptime float casts" { |
| 909 | 909 | const a = @intToFloat(comptime_float, 1); |
| 910 | expect(a == 1); | |
| 911 | expect(@TypeOf(a) == comptime_float); | |
| 910 | try expect(a == 1); | |
| 911 | try expect(@TypeOf(a) == comptime_float); | |
| 912 | 912 | const b = @floatToInt(comptime_int, 2); |
| 913 | expect(b == 2); | |
| 914 | expect(@TypeOf(b) == comptime_int); | |
| 913 | try expect(b == 2); | |
| 914 | try expect(@TypeOf(b) == comptime_int); | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | test "cast from ?[*]T to ??[*]T" { |
| 918 | 918 | const a: ??[*]u8 = @as(?[*]u8, null); |
| 919 | expect(a != null and a.? == null); | |
| 919 | try expect(a != null and a.? == null); | |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | test "cast between *[N]void and []void" { |
| 923 | 923 | var a: [4]void = undefined; |
| 924 | 924 | var b: []void = &a; |
| 925 | expect(b.len == 4); | |
| 925 | try expect(b.len == 4); | |
| 926 | 926 | } |
test/stage1/behavior/const_slice_child.zig+8-8| ... | ... | @@ -12,24 +12,24 @@ test "const slice child" { |
| 12 | 12 | "three", |
| 13 | 13 | }; |
| 14 | 14 | argv = &strs; |
| 15 | bar(strs.len); | |
| 15 | try bar(strs.len); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | fn foo(args: [][]const u8) void { | |
| 19 | expect(args.len == 3); | |
| 20 | expect(streql(args[0], "one")); | |
| 21 | expect(streql(args[1], "two")); | |
| 22 | expect(streql(args[2], "three")); | |
| 18 | fn foo(args: [][]const u8) !void { | |
| 19 | try expect(args.len == 3); | |
| 20 | try expect(streql(args[0], "one")); | |
| 21 | try expect(streql(args[1], "two")); | |
| 22 | try expect(streql(args[2], "three")); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | fn bar(argc: usize) void { | |
| 25 | fn bar(argc: usize) !void { | |
| 26 | 26 | const args = testing.allocator.alloc([]const u8, argc) catch unreachable; |
| 27 | 27 | defer testing.allocator.free(args); |
| 28 | 28 | for (args) |_, i| { |
| 29 | 29 | const ptr = argv[i]; |
| 30 | 30 | args[i] = ptr[0..strlen(ptr)]; |
| 31 | 31 | } |
| 32 | foo(args); | |
| 32 | try foo(args); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | fn strlen(ptr: [*]const u8) usize { |
test/stage1/behavior/defer.zig+20-20| ... | ... | @@ -24,18 +24,18 @@ fn runSomeErrorDefers(x: bool) !bool { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | test "mixing normal and error defers" { |
| 27 | expect(runSomeErrorDefers(true) catch unreachable); | |
| 28 | expect(result[0] == 'c'); | |
| 29 | expect(result[1] == 'a'); | |
| 27 | try expect(runSomeErrorDefers(true) catch unreachable); | |
| 28 | try expect(result[0] == 'c'); | |
| 29 | try expect(result[1] == 'a'); | |
| 30 | 30 | |
| 31 | 31 | const ok = runSomeErrorDefers(false) catch |err| x: { |
| 32 | expect(err == error.FalseNotAllowed); | |
| 32 | try expect(err == error.FalseNotAllowed); | |
| 33 | 33 | break :x true; |
| 34 | 34 | }; |
| 35 | expect(ok); | |
| 36 | expect(result[0] == 'c'); | |
| 37 | expect(result[1] == 'b'); | |
| 38 | expect(result[2] == 'a'); | |
| 35 | try expect(ok); | |
| 36 | try expect(result[0] == 'c'); | |
| 37 | try expect(result[1] == 'b'); | |
| 38 | try expect(result[2] == 'a'); | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | test "break and continue inside loop inside defer expression" { |
| ... | ... | @@ -50,7 +50,7 @@ fn testBreakContInDefer(x: usize) void { |
| 50 | 50 | if (i < 5) continue; |
| 51 | 51 | if (i == 5) break; |
| 52 | 52 | } |
| 53 | expect(i == 5); | |
| 53 | expect(i == 5) catch @panic("test failure"); | |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| ... | ... | @@ -62,11 +62,11 @@ test "defer and labeled break" { |
| 62 | 62 | break :blk; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | expect(i == 1); | |
| 65 | try expect(i == 1); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "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 | } |
| 71 | 71 | |
| 72 | 72 | fn testNestedFnErrDefer() anyerror!void { |
| ... | ... | @@ -82,8 +82,8 @@ fn testNestedFnErrDefer() anyerror!void { |
| 82 | 82 | |
| 83 | 83 | test "return variable while defer expression in scope to modify it" { |
| 84 | 84 | const S = struct { |
| 85 | fn doTheTest() void { | |
| 86 | expect(notNull().? == 1); | |
| 85 | fn doTheTest() !void { | |
| 86 | try expect(notNull().? == 1); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | fn notNull() ?u8 { |
| ... | ... | @@ -93,22 +93,22 @@ test "return variable while defer expression in scope to modify it" { |
| 93 | 93 | } |
| 94 | 94 | }; |
| 95 | 95 | |
| 96 | S.doTheTest(); | |
| 97 | comptime S.doTheTest(); | |
| 96 | try S.doTheTest(); | |
| 97 | comptime try S.doTheTest(); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "errdefer with payload" { |
| 101 | 101 | const S = struct { |
| 102 | 102 | fn foo() !i32 { |
| 103 | 103 | errdefer |a| { |
| 104 | expectEqual(error.One, a); | |
| 104 | expectEqual(error.One, a) catch @panic("test failure"); | |
| 105 | 105 | } |
| 106 | 106 | return error.One; |
| 107 | 107 | } |
| 108 | fn doTheTest() void { | |
| 109 | expectError(error.One, foo()); | |
| 108 | fn doTheTest() !void { | |
| 109 | try expectError(error.One, foo()); | |
| 110 | 110 | } |
| 111 | 111 | }; |
| 112 | S.doTheTest(); | |
| 113 | comptime S.doTheTest(); | |
| 112 | try S.doTheTest(); | |
| 113 | comptime try S.doTheTest(); | |
| 114 | 114 | } |
test/stage1/behavior/enum.zig+112-112| ... | ... | @@ -29,41 +29,41 @@ test "non-exhaustive enum" { |
| 29 | 29 | b, |
| 30 | 30 | _, |
| 31 | 31 | }; |
| 32 | fn doTheTest(y: u8) void { | |
| 32 | fn doTheTest(y: u8) !void { | |
| 33 | 33 | var e: E = .b; |
| 34 | expect(switch (e) { | |
| 34 | try expect(switch (e) { | |
| 35 | 35 | .a => false, |
| 36 | 36 | .b => true, |
| 37 | 37 | _ => false, |
| 38 | 38 | }); |
| 39 | 39 | e = @intToEnum(E, 12); |
| 40 | expect(switch (e) { | |
| 40 | try expect(switch (e) { | |
| 41 | 41 | .a => false, |
| 42 | 42 | .b => false, |
| 43 | 43 | _ => true, |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | expect(switch (e) { | |
| 46 | try expect(switch (e) { | |
| 47 | 47 | .a => false, |
| 48 | 48 | .b => false, |
| 49 | 49 | else => true, |
| 50 | 50 | }); |
| 51 | 51 | e = .b; |
| 52 | expect(switch (e) { | |
| 52 | try expect(switch (e) { | |
| 53 | 53 | .a => false, |
| 54 | 54 | else => true, |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | expect(@typeInfo(E).Enum.fields.len == 2); | |
| 57 | try expect(@typeInfo(E).Enum.fields.len == 2); | |
| 58 | 58 | e = @intToEnum(E, 12); |
| 59 | expect(@enumToInt(e) == 12); | |
| 59 | try expect(@enumToInt(e) == 12); | |
| 60 | 60 | e = @intToEnum(E, y); |
| 61 | expect(@enumToInt(e) == 52); | |
| 62 | expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 61 | try expect(@enumToInt(e) == 52); | |
| 62 | try expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 63 | 63 | } |
| 64 | 64 | }; |
| 65 | S.doTheTest(52); | |
| 66 | comptime S.doTheTest(52); | |
| 65 | try S.doTheTest(52); | |
| 66 | comptime try S.doTheTest(52); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | test "empty non-exhaustive enum" { |
| ... | ... | @@ -71,19 +71,19 @@ test "empty non-exhaustive enum" { |
| 71 | 71 | const E = enum(u8) { |
| 72 | 72 | _, |
| 73 | 73 | }; |
| 74 | fn doTheTest(y: u8) void { | |
| 74 | fn doTheTest(y: u8) !void { | |
| 75 | 75 | var e = @intToEnum(E, y); |
| 76 | expect(switch (e) { | |
| 76 | try expect(switch (e) { | |
| 77 | 77 | _ => true, |
| 78 | 78 | }); |
| 79 | expect(@enumToInt(e) == y); | |
| 79 | try expect(@enumToInt(e) == y); | |
| 80 | 80 | |
| 81 | expect(@typeInfo(E).Enum.fields.len == 0); | |
| 82 | expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 81 | try expect(@typeInfo(E).Enum.fields.len == 0); | |
| 82 | try expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 83 | 83 | } |
| 84 | 84 | }; |
| 85 | S.doTheTest(42); | |
| 86 | comptime S.doTheTest(42); | |
| 85 | try S.doTheTest(42); | |
| 86 | comptime try S.doTheTest(42); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | test "single field non-exhaustive enum" { |
| ... | ... | @@ -92,35 +92,35 @@ test "single field non-exhaustive enum" { |
| 92 | 92 | a, |
| 93 | 93 | _, |
| 94 | 94 | }; |
| 95 | fn doTheTest(y: u8) void { | |
| 95 | fn doTheTest(y: u8) !void { | |
| 96 | 96 | var e: E = .a; |
| 97 | expect(switch (e) { | |
| 97 | try expect(switch (e) { | |
| 98 | 98 | .a => true, |
| 99 | 99 | _ => false, |
| 100 | 100 | }); |
| 101 | 101 | e = @intToEnum(E, 12); |
| 102 | expect(switch (e) { | |
| 102 | try expect(switch (e) { | |
| 103 | 103 | .a => false, |
| 104 | 104 | _ => true, |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | expect(switch (e) { | |
| 107 | try expect(switch (e) { | |
| 108 | 108 | .a => false, |
| 109 | 109 | else => true, |
| 110 | 110 | }); |
| 111 | 111 | e = .a; |
| 112 | expect(switch (e) { | |
| 112 | try expect(switch (e) { | |
| 113 | 113 | .a => true, |
| 114 | 114 | else => false, |
| 115 | 115 | }); |
| 116 | 116 | |
| 117 | expect(@enumToInt(@intToEnum(E, y)) == y); | |
| 118 | expect(@typeInfo(E).Enum.fields.len == 1); | |
| 119 | expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 117 | try expect(@enumToInt(@intToEnum(E, y)) == y); | |
| 118 | try expect(@typeInfo(E).Enum.fields.len == 1); | |
| 119 | try expect(@typeInfo(E).Enum.is_exhaustive == false); | |
| 120 | 120 | } |
| 121 | 121 | }; |
| 122 | S.doTheTest(23); | |
| 123 | comptime S.doTheTest(23); | |
| 122 | try S.doTheTest(23); | |
| 123 | comptime try S.doTheTest(23); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | test "enum type" { |
| ... | ... | @@ -133,16 +133,16 @@ test "enum type" { |
| 133 | 133 | }; |
| 134 | 134 | const bar = Bar.B; |
| 135 | 135 | |
| 136 | expect(bar == Bar.B); | |
| 137 | expect(@typeInfo(Foo).Union.fields.len == 3); | |
| 138 | expect(@typeInfo(Bar).Enum.fields.len == 4); | |
| 139 | expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); | |
| 140 | expect(@sizeOf(Bar) == 1); | |
| 136 | try expect(bar == Bar.B); | |
| 137 | try expect(@typeInfo(Foo).Union.fields.len == 3); | |
| 138 | try expect(@typeInfo(Bar).Enum.fields.len == 4); | |
| 139 | try expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); | |
| 140 | try expect(@sizeOf(Bar) == 1); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "enum as return value" { |
| 144 | 144 | switch (returnAnInt(13)) { |
| 145 | Foo.One => |value| expect(value == 13), | |
| 145 | Foo.One => |value| try expect(value == 13), | |
| 146 | 146 | else => unreachable, |
| 147 | 147 | } |
| 148 | 148 | } |
| ... | ... | @@ -206,22 +206,22 @@ const Number = enum { |
| 206 | 206 | }; |
| 207 | 207 | |
| 208 | 208 | test "enum to int" { |
| 209 | shouldEqual(Number.Zero, 0); | |
| 210 | shouldEqual(Number.One, 1); | |
| 211 | shouldEqual(Number.Two, 2); | |
| 212 | shouldEqual(Number.Three, 3); | |
| 213 | shouldEqual(Number.Four, 4); | |
| 209 | try shouldEqual(Number.Zero, 0); | |
| 210 | try shouldEqual(Number.One, 1); | |
| 211 | try shouldEqual(Number.Two, 2); | |
| 212 | try shouldEqual(Number.Three, 3); | |
| 213 | try shouldEqual(Number.Four, 4); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | fn shouldEqual(n: Number, expected: u3) void { | |
| 217 | expect(@enumToInt(n) == expected); | |
| 216 | fn shouldEqual(n: Number, expected: u3) !void { | |
| 217 | try expect(@enumToInt(n) == expected); | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | test "int to enum" { |
| 221 | testIntToEnumEval(3); | |
| 221 | try testIntToEnumEval(3); | |
| 222 | 222 | } |
| 223 | fn testIntToEnumEval(x: i32) void { | |
| 224 | expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three); | |
| 223 | fn testIntToEnumEval(x: i32) !void { | |
| 224 | try expect(@intToEnum(IntToEnumNumber, @intCast(u3, x)) == IntToEnumNumber.Three); | |
| 225 | 225 | } |
| 226 | 226 | const IntToEnumNumber = enum { |
| 227 | 227 | Zero, |
| ... | ... | @@ -232,18 +232,18 @@ const IntToEnumNumber = enum { |
| 232 | 232 | }; |
| 233 | 233 | |
| 234 | 234 | test "@tagName" { |
| 235 | expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 236 | comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 235 | try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 236 | comptime try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | test "@tagName extern enum with duplicates" { |
| 240 | expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A")); | |
| 241 | comptime expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A")); | |
| 240 | try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A")); | |
| 241 | comptime try expect(mem.eql(u8, testEnumTagNameBare(ExternDuplicates.B), "A")); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | test "@tagName non-exhaustive enum" { |
| 245 | expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 246 | comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 245 | try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 246 | comptime try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | fn testEnumTagNameBare(n: anytype) []const u8 { |
| ... | ... | @@ -269,8 +269,8 @@ const NonExhaustive = enum(u8) { |
| 269 | 269 | |
| 270 | 270 | test "enum alignment" { |
| 271 | 271 | comptime { |
| 272 | expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8)); | |
| 273 | expect(@alignOf(AlignTestEnum) >= @alignOf(u64)); | |
| 272 | try expect(@alignOf(AlignTestEnum) >= @alignOf([9]u8)); | |
| 273 | try expect(@alignOf(AlignTestEnum) >= @alignOf(u64)); | |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| ... | ... | @@ -806,10 +806,10 @@ const ValueCount257 = enum { |
| 806 | 806 | |
| 807 | 807 | test "enum sizes" { |
| 808 | 808 | comptime { |
| 809 | expect(@sizeOf(ValueCount1) == 0); | |
| 810 | expect(@sizeOf(ValueCount2) == 1); | |
| 811 | expect(@sizeOf(ValueCount256) == 1); | |
| 812 | expect(@sizeOf(ValueCount257) == 2); | |
| 809 | try expect(@sizeOf(ValueCount1) == 0); | |
| 810 | try expect(@sizeOf(ValueCount2) == 1); | |
| 811 | try expect(@sizeOf(ValueCount256) == 1); | |
| 812 | try expect(@sizeOf(ValueCount257) == 2); | |
| 813 | 813 | } |
| 814 | 814 | } |
| 815 | 815 | |
| ... | ... | @@ -828,12 +828,12 @@ test "set enum tag type" { |
| 828 | 828 | { |
| 829 | 829 | var x = Small.One; |
| 830 | 830 | x = Small.Two; |
| 831 | comptime expect(Tag(Small) == u2); | |
| 831 | comptime try expect(Tag(Small) == u2); | |
| 832 | 832 | } |
| 833 | 833 | { |
| 834 | 834 | var x = Small2.One; |
| 835 | 835 | x = Small2.Two; |
| 836 | comptime expect(Tag(Small2) == u2); | |
| 836 | comptime try expect(Tag(Small2) == u2); | |
| 837 | 837 | } |
| 838 | 838 | } |
| 839 | 839 | |
| ... | ... | @@ -880,17 +880,17 @@ const bit_field_1 = BitFieldOfEnums{ |
| 880 | 880 | |
| 881 | 881 | test "bit field access with enum fields" { |
| 882 | 882 | var data = bit_field_1; |
| 883 | expect(getA(&data) == A.Two); | |
| 884 | expect(getB(&data) == B.Three3); | |
| 885 | expect(getC(&data) == C.Four4); | |
| 886 | comptime expect(@sizeOf(BitFieldOfEnums) == 1); | |
| 883 | try expect(getA(&data) == A.Two); | |
| 884 | try expect(getB(&data) == B.Three3); | |
| 885 | try expect(getC(&data) == C.Four4); | |
| 886 | comptime try expect(@sizeOf(BitFieldOfEnums) == 1); | |
| 887 | 887 | |
| 888 | 888 | data.b = B.Four3; |
| 889 | expect(data.b == B.Four3); | |
| 889 | try expect(data.b == B.Four3); | |
| 890 | 890 | |
| 891 | 891 | data.a = A.Three; |
| 892 | expect(data.a == A.Three); | |
| 893 | expect(data.b == B.Four3); | |
| 892 | try expect(data.a == A.Three); | |
| 893 | try expect(data.b == B.Four3); | |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | fn getA(data: *const BitFieldOfEnums) A { |
| ... | ... | @@ -906,12 +906,12 @@ fn getC(data: *const BitFieldOfEnums) C { |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | test "casting enum to its tag type" { |
| 909 | testCastEnumTag(Small2.Two); | |
| 910 | comptime testCastEnumTag(Small2.Two); | |
| 909 | try testCastEnumTag(Small2.Two); | |
| 910 | comptime try testCastEnumTag(Small2.Two); | |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | fn testCastEnumTag(value: Small2) void { | |
| 914 | expect(@enumToInt(value) == 1); | |
| 913 | fn testCastEnumTag(value: Small2) !void { | |
| 914 | try expect(@enumToInt(value) == 1); | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | const MultipleChoice = enum(u32) { |
| ... | ... | @@ -922,13 +922,13 @@ const MultipleChoice = enum(u32) { |
| 922 | 922 | }; |
| 923 | 923 | |
| 924 | 924 | test "enum with specified tag values" { |
| 925 | testEnumWithSpecifiedTagValues(MultipleChoice.C); | |
| 926 | comptime testEnumWithSpecifiedTagValues(MultipleChoice.C); | |
| 925 | try testEnumWithSpecifiedTagValues(MultipleChoice.C); | |
| 926 | comptime try testEnumWithSpecifiedTagValues(MultipleChoice.C); | |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | fn testEnumWithSpecifiedTagValues(x: MultipleChoice) void { | |
| 930 | expect(@enumToInt(x) == 60); | |
| 931 | expect(1234 == switch (x) { | |
| 929 | fn testEnumWithSpecifiedTagValues(x: MultipleChoice) !void { | |
| 930 | try expect(@enumToInt(x) == 60); | |
| 931 | try expect(1234 == switch (x) { | |
| 932 | 932 | MultipleChoice.A => 1, |
| 933 | 933 | MultipleChoice.B => 2, |
| 934 | 934 | MultipleChoice.C => @as(u32, 1234), |
| ... | ... | @@ -949,13 +949,13 @@ const MultipleChoice2 = enum(u32) { |
| 949 | 949 | }; |
| 950 | 950 | |
| 951 | 951 | test "enum with specified and unspecified tag values" { |
| 952 | testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); | |
| 953 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); | |
| 952 | try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); | |
| 953 | comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2.D); | |
| 954 | 954 | } |
| 955 | 955 | |
| 956 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { | |
| 957 | expect(@enumToInt(x) == 1000); | |
| 958 | expect(1234 == switch (x) { | |
| 956 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void { | |
| 957 | try expect(@enumToInt(x) == 1000); | |
| 958 | try expect(1234 == switch (x) { | |
| 959 | 959 | MultipleChoice2.A => 1, |
| 960 | 960 | MultipleChoice2.B => 2, |
| 961 | 961 | MultipleChoice2.C => 3, |
| ... | ... | @@ -969,8 +969,8 @@ fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | test "cast integer literal to enum" { |
| 972 | expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1); | |
| 973 | expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B); | |
| 972 | try expect(@intToEnum(MultipleChoice2, 0) == MultipleChoice2.Unspecified1); | |
| 973 | try expect(@intToEnum(MultipleChoice2, 40) == MultipleChoice2.B); | |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | const EnumWithOneMember = enum { |
| ... | ... | @@ -1008,14 +1008,14 @@ const EnumWithTagValues = enum(u4) { |
| 1008 | 1008 | D = 1 << 3, |
| 1009 | 1009 | }; |
| 1010 | 1010 | test "enum with tag values don't require parens" { |
| 1011 | expect(@enumToInt(EnumWithTagValues.C) == 0b0100); | |
| 1011 | try expect(@enumToInt(EnumWithTagValues.C) == 0b0100); | |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | test "enum with 1 field but explicit tag type should still have the tag type" { |
| 1015 | 1015 | const Enum = enum(u8) { |
| 1016 | 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 | } |
| 1020 | 1020 | |
| 1021 | 1021 | test "empty extern enum with members" { |
| ... | ... | @@ -1024,7 +1024,7 @@ test "empty extern enum with members" { |
| 1024 | 1024 | B, |
| 1025 | 1025 | C, |
| 1026 | 1026 | }; |
| 1027 | expect(@sizeOf(E) == @sizeOf(c_int)); | |
| 1027 | try expect(@sizeOf(E) == @sizeOf(c_int)); | |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | test "tag name with assigned enum values" { |
| ... | ... | @@ -1033,7 +1033,7 @@ test "tag name with assigned enum values" { |
| 1033 | 1033 | B = 0, |
| 1034 | 1034 | }; |
| 1035 | 1035 | var b = LocalFoo.B; |
| 1036 | expect(mem.eql(u8, @tagName(b), "B")); | |
| 1036 | try expect(mem.eql(u8, @tagName(b), "B")); | |
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | test "enum literal equality" { |
| ... | ... | @@ -1041,8 +1041,8 @@ test "enum literal equality" { |
| 1041 | 1041 | const y = .ok; |
| 1042 | 1042 | const z = .hi; |
| 1043 | 1043 | |
| 1044 | expect(x != y); | |
| 1045 | expect(x == z); | |
| 1044 | try expect(x != y); | |
| 1045 | try expect(x == z); | |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | test "enum literal cast to enum" { |
| ... | ... | @@ -1054,7 +1054,7 @@ test "enum literal cast to enum" { |
| 1054 | 1054 | |
| 1055 | 1055 | var color1: Color = .Auto; |
| 1056 | 1056 | var color2 = Color.Auto; |
| 1057 | expect(color1 == color2); | |
| 1057 | try expect(color1 == color2); | |
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | test "peer type resolution with enum literal" { |
| ... | ... | @@ -1063,8 +1063,8 @@ test "peer type resolution with enum literal" { |
| 1063 | 1063 | two, |
| 1064 | 1064 | }; |
| 1065 | 1065 | |
| 1066 | expect(Items.two == .two); | |
| 1067 | expect(.two == Items.two); | |
| 1066 | try expect(Items.two == .two); | |
| 1067 | try expect(.two == Items.two); | |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | test "enum literal in array literal" { |
| ... | ... | @@ -1078,8 +1078,8 @@ test "enum literal in array literal" { |
| 1078 | 1078 | .two, |
| 1079 | 1079 | }; |
| 1080 | 1080 | |
| 1081 | expect(array[0] == .one); | |
| 1082 | expect(array[1] == .two); | |
| 1081 | try expect(array[0] == .one); | |
| 1082 | try expect(array[1] == .two); | |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | test "signed integer as enum tag" { |
| ... | ... | @@ -1089,9 +1089,9 @@ test "signed integer as enum tag" { |
| 1089 | 1089 | A2 = 1, |
| 1090 | 1090 | }; |
| 1091 | 1091 | |
| 1092 | expect(@enumToInt(SignedEnum.A0) == -1); | |
| 1093 | expect(@enumToInt(SignedEnum.A1) == 0); | |
| 1094 | expect(@enumToInt(SignedEnum.A2) == 1); | |
| 1092 | try expect(@enumToInt(SignedEnum.A0) == -1); | |
| 1093 | try expect(@enumToInt(SignedEnum.A1) == 0); | |
| 1094 | try expect(@enumToInt(SignedEnum.A2) == 1); | |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | test "enum value allocation" { |
| ... | ... | @@ -1101,9 +1101,9 @@ test "enum value allocation" { |
| 1101 | 1101 | A2, |
| 1102 | 1102 | }; |
| 1103 | 1103 | |
| 1104 | expect(@enumToInt(LargeEnum.A0) == 0x80000000); | |
| 1105 | expect(@enumToInt(LargeEnum.A1) == 0x80000001); | |
| 1106 | expect(@enumToInt(LargeEnum.A2) == 0x80000002); | |
| 1104 | try expect(@enumToInt(LargeEnum.A0) == 0x80000000); | |
| 1105 | try expect(@enumToInt(LargeEnum.A1) == 0x80000001); | |
| 1106 | try expect(@enumToInt(LargeEnum.A2) == 0x80000002); | |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | test "enum literal casting to tagged union" { |
| ... | ... | @@ -1130,32 +1130,32 @@ test "enum with one member and custom tag type" { |
| 1130 | 1130 | const E = enum(u2) { |
| 1131 | 1131 | One, |
| 1132 | 1132 | }; |
| 1133 | expect(@enumToInt(E.One) == 0); | |
| 1133 | try expect(@enumToInt(E.One) == 0); | |
| 1134 | 1134 | const E2 = enum(u2) { |
| 1135 | 1135 | One = 2, |
| 1136 | 1136 | }; |
| 1137 | expect(@enumToInt(E2.One) == 2); | |
| 1137 | try expect(@enumToInt(E2.One) == 2); | |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | test "enum literal casting to optional" { |
| 1141 | 1141 | var bar: ?Bar = undefined; |
| 1142 | 1142 | bar = .B; |
| 1143 | 1143 | |
| 1144 | expect(bar.? == Bar.B); | |
| 1144 | try expect(bar.? == Bar.B); | |
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | test "enum literal casting to error union with payload enum" { |
| 1148 | 1148 | var bar: error{B}!Bar = undefined; |
| 1149 | 1149 | bar = .B; // should never cast to the error set |
| 1150 | 1150 | |
| 1151 | expect((try bar) == Bar.B); | |
| 1151 | try expect((try bar) == Bar.B); | |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | 1154 | test "enum with one member and u1 tag type @enumToInt" { |
| 1155 | 1155 | const Enum = enum(u1) { |
| 1156 | 1156 | Test, |
| 1157 | 1157 | }; |
| 1158 | expect(@enumToInt(Enum.Test) == 0); | |
| 1158 | try expect(@enumToInt(Enum.Test) == 0); | |
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | test "enum with comptime_int tag type" { |
| ... | ... | @@ -1164,19 +1164,19 @@ test "enum with comptime_int tag type" { |
| 1164 | 1164 | Two = 2, |
| 1165 | 1165 | Three = 1, |
| 1166 | 1166 | }; |
| 1167 | comptime expect(Tag(Enum) == comptime_int); | |
| 1167 | comptime try expect(Tag(Enum) == comptime_int); | |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | test "enum with one member default to u0 tag type" { |
| 1171 | 1171 | const E0 = enum { |
| 1172 | 1172 | X, |
| 1173 | 1173 | }; |
| 1174 | comptime expect(Tag(E0) == u0); | |
| 1174 | comptime try expect(Tag(E0) == u0); | |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | test "tagName on enum literals" { |
| 1178 | expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1179 | comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1178 | try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1179 | comptime try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | test "method call on an enum" { |
| ... | ... | @@ -1193,12 +1193,12 @@ test "method call on an enum" { |
| 1193 | 1193 | return self.* == .two and foo == bool; |
| 1194 | 1194 | } |
| 1195 | 1195 | }; |
| 1196 | fn doTheTest() void { | |
| 1196 | fn doTheTest() !void { | |
| 1197 | 1197 | var e = E.two; |
| 1198 | expect(e.method()); | |
| 1199 | expect(e.generic_method(bool)); | |
| 1198 | try expect(e.method()); | |
| 1199 | try expect(e.generic_method(bool)); | |
| 1200 | 1200 | } |
| 1201 | 1201 | }; |
| 1202 | S.doTheTest(); | |
| 1203 | comptime S.doTheTest(); | |
| 1202 | try S.doTheTest(); | |
| 1203 | comptime try S.doTheTest(); | |
| 1204 | 1204 | } |
test/stage1/behavior/enum_with_members.zig+4-4| ... | ... | @@ -19,9 +19,9 @@ test "enum with members" { |
| 19 | 19 | const b = ET{ .UINT = 42 }; |
| 20 | 20 | var buf: [20]u8 = undefined; |
| 21 | 21 | |
| 22 | expect((a.print(buf[0..]) catch unreachable) == 3); | |
| 23 | expect(mem.eql(u8, buf[0..3], "-42")); | |
| 22 | try expect((a.print(buf[0..]) catch unreachable) == 3); | |
| 23 | try expect(mem.eql(u8, buf[0..3], "-42")); | |
| 24 | 24 | |
| 25 | expect((b.print(buf[0..]) catch unreachable) == 2); | |
| 26 | expect(mem.eql(u8, buf[0..2], "42")); | |
| 25 | try expect((b.print(buf[0..]) catch unreachable) == 2); | |
| 26 | try expect(mem.eql(u8, buf[0..2], "42")); | |
| 27 | 27 | } |
test/stage1/behavior/error.zig+60-60| ... | ... | @@ -19,7 +19,7 @@ pub fn baz() anyerror!i32 { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "error wrapping" { |
| 22 | expect((baz() catch unreachable) == 15); | |
| 22 | try expect((baz() catch unreachable) == 15); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | fn gimmeItBroke() []const u8 { |
| ... | ... | @@ -27,14 +27,14 @@ fn gimmeItBroke() []const u8 { |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | test "@errorName" { |
| 30 | expect(mem.eql(u8, @errorName(error.AnError), "AnError")); | |
| 31 | expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 30 | try expect(mem.eql(u8, @errorName(error.AnError), "AnError")); | |
| 31 | try expect(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName")); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "error values" { |
| 35 | 35 | const a = @errorToInt(error.err1); |
| 36 | 36 | const b = @errorToInt(error.err2); |
| 37 | expect(a != b); | |
| 37 | try expect(a != b); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | test "redefinition of error values allowed" { |
| ... | ... | @@ -47,8 +47,8 @@ fn shouldBeNotEqual(a: anyerror, b: anyerror) void { |
| 47 | 47 | test "error binary operator" { |
| 48 | 48 | const a = errBinaryOperatorG(true) catch 3; |
| 49 | 49 | const b = errBinaryOperatorG(false) catch 3; |
| 50 | expect(a == 3); | |
| 51 | expect(b == 10); | |
| 50 | try expect(a == 3); | |
| 51 | try expect(b == 10); | |
| 52 | 52 | } |
| 53 | 53 | fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 54 | 54 | return if (x) error.ItBroke else @as(isize, 10); |
| ... | ... | @@ -56,7 +56,7 @@ fn errBinaryOperatorG(x: bool) anyerror!isize { |
| 56 | 56 | |
| 57 | 57 | test "unwrap simple value from error" { |
| 58 | 58 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; |
| 59 | expect(i == 13); | |
| 59 | try expect(i == 13); | |
| 60 | 60 | } |
| 61 | 61 | fn unwrapSimpleValueFromErrorDo() anyerror!isize { |
| 62 | 62 | return 13; |
| ... | ... | @@ -76,21 +76,21 @@ fn makeANonErr() anyerror!i32 { |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "error union type " { |
| 79 | testErrorUnionType(); | |
| 80 | comptime testErrorUnionType(); | |
| 79 | try testErrorUnionType(); | |
| 80 | comptime try testErrorUnionType(); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | fn testErrorUnionType() void { | |
| 83 | fn testErrorUnionType() !void { | |
| 84 | 84 | const x: anyerror!i32 = 1234; |
| 85 | if (x) |value| expect(value == 1234) else |_| unreachable; | |
| 86 | expect(@typeInfo(@TypeOf(x)) == .ErrorUnion); | |
| 87 | expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet); | |
| 88 | expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror); | |
| 85 | if (x) |value| try expect(value == 1234) else |_| unreachable; | |
| 86 | try expect(@typeInfo(@TypeOf(x)) == .ErrorUnion); | |
| 87 | try expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet); | |
| 88 | try expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "error set type" { |
| 92 | testErrorSetType(); | |
| 93 | comptime testErrorSetType(); | |
| 92 | try testErrorSetType(); | |
| 93 | comptime try testErrorSetType(); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | const MyErrSet = error{ |
| ... | ... | @@ -98,21 +98,21 @@ const MyErrSet = error{ |
| 98 | 98 | FileNotFound, |
| 99 | 99 | }; |
| 100 | 100 | |
| 101 | fn testErrorSetType() void { | |
| 102 | expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2); | |
| 101 | fn testErrorSetType() !void { | |
| 102 | try expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2); | |
| 103 | 103 | |
| 104 | 104 | const a: MyErrSet!i32 = 5678; |
| 105 | 105 | const b: MyErrSet!i32 = MyErrSet.OutOfMemory; |
| 106 | 106 | |
| 107 | if (a) |value| expect(value == 5678) else |err| switch (err) { | |
| 107 | if (a) |value| try expect(value == 5678) else |err| switch (err) { | |
| 108 | 108 | error.OutOfMemory => unreachable, |
| 109 | 109 | error.FileNotFound => unreachable, |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | test "explicit error set cast" { |
| 114 | testExplicitErrorSetCast(Set1.A); | |
| 115 | comptime testExplicitErrorSetCast(Set1.A); | |
| 114 | try testExplicitErrorSetCast(Set1.A); | |
| 115 | comptime try testExplicitErrorSetCast(Set1.A); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | const Set1 = error{ |
| ... | ... | @@ -124,26 +124,26 @@ const Set2 = error{ |
| 124 | 124 | C, |
| 125 | 125 | }; |
| 126 | 126 | |
| 127 | fn testExplicitErrorSetCast(set1: Set1) void { | |
| 127 | fn testExplicitErrorSetCast(set1: Set1) !void { | |
| 128 | 128 | var x = @errSetCast(Set2, set1); |
| 129 | 129 | var y = @errSetCast(Set1, x); |
| 130 | expect(y == error.A); | |
| 130 | try expect(y == error.A); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "comptime test error for empty error set" { |
| 134 | testComptimeTestErrorEmptySet(1234); | |
| 135 | comptime testComptimeTestErrorEmptySet(1234); | |
| 134 | try testComptimeTestErrorEmptySet(1234); | |
| 135 | comptime try testComptimeTestErrorEmptySet(1234); | |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | const EmptyErrorSet = error{}; |
| 139 | 139 | |
| 140 | fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void { | |
| 141 | if (x) |v| expect(v == 1234) else |err| @compileError("bad"); | |
| 140 | fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void { | |
| 141 | if (x) |v| try expect(v == 1234) else |err| @compileError("bad"); | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | test "syntax: optional operator in front of error union operator" { |
| 145 | 145 | comptime { |
| 146 | expect(?(anyerror!i32) == ?(anyerror!i32)); | |
| 146 | try expect(?(anyerror!i32) == ?(anyerror!i32)); | |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| ... | ... | @@ -165,10 +165,10 @@ test "empty error union" { |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | test "error union peer type resolution" { |
| 168 | testErrorUnionPeerTypeResolution(1); | |
| 168 | try testErrorUnionPeerTypeResolution(1); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | fn testErrorUnionPeerTypeResolution(x: i32) void { | |
| 171 | fn testErrorUnionPeerTypeResolution(x: i32) !void { | |
| 172 | 172 | const y = switch (x) { |
| 173 | 173 | 1 => bar_1(), |
| 174 | 174 | 2 => baz_1(), |
| ... | ... | @@ -177,7 +177,7 @@ fn testErrorUnionPeerTypeResolution(x: i32) void { |
| 177 | 177 | if (y) |_| { |
| 178 | 178 | @panic("expected error"); |
| 179 | 179 | } else |e| { |
| 180 | expect(e == error.A); | |
| 180 | try expect(e == error.A); | |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| ... | ... | @@ -286,13 +286,13 @@ test "nested error union function call in optional unwrap" { |
| 286 | 286 | return null; |
| 287 | 287 | } |
| 288 | 288 | }; |
| 289 | expect((try S.errorable()) == 1234); | |
| 290 | expectError(error.Failure, S.errorable2()); | |
| 291 | expectError(error.Other, S.errorable3()); | |
| 289 | try expect((try S.errorable()) == 1234); | |
| 290 | try expectError(error.Failure, S.errorable2()); | |
| 291 | try expectError(error.Other, S.errorable3()); | |
| 292 | 292 | comptime { |
| 293 | expect((try S.errorable()) == 1234); | |
| 294 | expectError(error.Failure, S.errorable2()); | |
| 295 | expectError(error.Other, S.errorable3()); | |
| 293 | try expect((try S.errorable()) == 1234); | |
| 294 | try expectError(error.Failure, S.errorable2()); | |
| 295 | try expectError(error.Other, S.errorable3()); | |
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| ... | ... | @@ -307,7 +307,7 @@ test "widen cast integer payload of error union function call" { |
| 307 | 307 | return 1234; |
| 308 | 308 | } |
| 309 | 309 | }; |
| 310 | expect((try S.errorable()) == 1234); | |
| 310 | try expect((try S.errorable()) == 1234); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | 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 | 320 | return error.Failure; |
| 321 | 321 | } |
| 322 | 322 | }; |
| 323 | expectError(error.Failure, S.errorable()); | |
| 324 | comptime expectError(error.Failure, S.errorable()); | |
| 323 | try expectError(error.Failure, S.errorable()); | |
| 324 | comptime try expectError(error.Failure, S.errorable()); | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | test "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 | 329 | const S = struct { |
| 330 | 330 | fn returnsOptErrSet() ?anyerror { |
| 331 | 331 | return null; |
| 332 | 332 | } |
| 333 | 333 | }; |
| 334 | expect(S.returnsOptErrSet() == null); | |
| 335 | comptime expect(S.returnsOptErrSet() == null); | |
| 334 | try expect(S.returnsOptErrSet() == null); | |
| 335 | comptime try expect(S.returnsOptErrSet() == null); | |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | test "debug info for optional error set" { |
| ... | ... | @@ -342,8 +342,8 @@ test "debug info for optional error set" { |
| 342 | 342 | |
| 343 | 343 | test "nested catch" { |
| 344 | 344 | const S = struct { |
| 345 | fn entry() void { | |
| 346 | expectError(error.Bad, func()); | |
| 345 | fn entry() !void { | |
| 346 | try expectError(error.Bad, func()); | |
| 347 | 347 | } |
| 348 | 348 | fn fail() anyerror!Foo { |
| 349 | 349 | return error.Wrong; |
| ... | ... | @@ -358,16 +358,16 @@ test "nested catch" { |
| 358 | 358 | field: i32, |
| 359 | 359 | }; |
| 360 | 360 | }; |
| 361 | S.entry(); | |
| 362 | comptime S.entry(); | |
| 361 | try S.entry(); | |
| 362 | comptime try S.entry(); | |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | test "implicit cast to optional to error union to return result loc" { |
| 366 | 366 | const S = struct { |
| 367 | fn entry() void { | |
| 367 | fn entry() !void { | |
| 368 | 368 | var x: Foo = undefined; |
| 369 | 369 | if (func(&x)) |opt| { |
| 370 | expect(opt != null); | |
| 370 | try expect(opt != null); | |
| 371 | 371 | } else |_| @panic("expected non error"); |
| 372 | 372 | } |
| 373 | 373 | fn func(f: *Foo) anyerror!?*Foo { |
| ... | ... | @@ -377,7 +377,7 @@ test "implicit cast to optional to error union to return result loc" { |
| 377 | 377 | field: i32, |
| 378 | 378 | }; |
| 379 | 379 | }; |
| 380 | S.entry(); | |
| 380 | try S.entry(); | |
| 381 | 381 | //comptime S.entry(); TODO |
| 382 | 382 | } |
| 383 | 383 | |
| ... | ... | @@ -393,23 +393,23 @@ test "function pointer with return type that is error union with payload which i |
| 393 | 393 | return Err.UnspecifiedErr; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | fn doTheTest() void { | |
| 396 | fn doTheTest() !void { | |
| 397 | 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 | } |
| 403 | 403 | |
| 404 | 404 | test "return result loc as peer result loc in inferred error set function" { |
| 405 | 405 | const S = struct { |
| 406 | fn doTheTest() void { | |
| 406 | fn doTheTest() !void { | |
| 407 | 407 | if (foo(2)) |x| { |
| 408 | expect(x.Two); | |
| 408 | try expect(x.Two); | |
| 409 | 409 | } else |e| switch (e) { |
| 410 | 410 | error.Whatever => @panic("fail"), |
| 411 | 411 | } |
| 412 | expectError(error.Whatever, foo(99)); | |
| 412 | try expectError(error.Whatever, foo(99)); | |
| 413 | 413 | } |
| 414 | 414 | const FormValue = union(enum) { |
| 415 | 415 | One: void, |
| ... | ... | @@ -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(); | |
| 428 | comptime S.doTheTest(); | |
| 427 | try S.doTheTest(); | |
| 428 | comptime try S.doTheTest(); | |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | test "error payload type is correctly resolved" { |
| ... | ... | @@ -439,7 +439,7 @@ test "error payload type is correctly resolved" { |
| 439 | 439 | } |
| 440 | 440 | }; |
| 441 | 441 | |
| 442 | expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create()); | |
| 442 | try expectEqual(MyIntWrapper{ .x = 42 }, try MyIntWrapper.create()); | |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | test "error union comptime caching" { |
| ... | ... | @@ -449,4 +449,4 @@ test "error union comptime caching" { |
| 449 | 449 | |
| 450 | 450 | S.foo(@as(anyerror!void, {})); |
| 451 | 451 | S.foo(@as(anyerror!void, {})); |
| 452 | } | |
| \ No newline at end of file | ||
| 452 | } |
test/stage1/behavior/eval.zig+119-119| ... | ... | @@ -4,7 +4,7 @@ const expectEqual = std.testing.expectEqual; |
| 4 | 4 | const builtin = @import("builtin"); |
| 5 | 5 | |
| 6 | 6 | test "compile time recursion" { |
| 7 | expect(some_data.len == 21); | |
| 7 | try expect(some_data.len == 21); | |
| 8 | 8 | } |
| 9 | 9 | var some_data: [@intCast(usize, fibonacci(7))]u8 = undefined; |
| 10 | 10 | fn fibonacci(x: i32) i32 { |
| ... | ... | @@ -17,7 +17,7 @@ fn unwrapAndAddOne(blah: ?i32) i32 { |
| 17 | 17 | } |
| 18 | 18 | const should_be_1235 = unwrapAndAddOne(1234); |
| 19 | 19 | test "static add one" { |
| 20 | expect(should_be_1235 == 1235); | |
| 20 | try expect(should_be_1235 == 1235); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "inlined loop" { |
| ... | ... | @@ -25,7 +25,7 @@ test "inlined loop" { |
| 25 | 25 | comptime var sum = 0; |
| 26 | 26 | inline while (i <= 5) : (i += 1) |
| 27 | 27 | sum += i; |
| 28 | expect(sum == 15); | |
| 28 | try expect(sum == 15); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | fn gimme1or2(comptime a: bool) i32 { |
| ... | ... | @@ -35,12 +35,12 @@ fn gimme1or2(comptime a: bool) i32 { |
| 35 | 35 | return z; |
| 36 | 36 | } |
| 37 | 37 | test "inline variable gets result of const if" { |
| 38 | expect(gimme1or2(true) == 1); | |
| 39 | expect(gimme1or2(false) == 2); | |
| 38 | try expect(gimme1or2(true) == 1); | |
| 39 | try expect(gimme1or2(false) == 2); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | test "static function evaluation" { |
| 43 | expect(statically_added_number == 3); | |
| 43 | try expect(statically_added_number == 3); | |
| 44 | 44 | } |
| 45 | 45 | const statically_added_number = staticAdd(1, 2); |
| 46 | 46 | fn staticAdd(a: i32, b: i32) i32 { |
| ... | ... | @@ -48,8 +48,8 @@ fn staticAdd(a: i32, b: i32) i32 { |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "const expr eval on single expr blocks" { |
| 51 | expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 52 | comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 51 | try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 52 | comptime try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| ... | ... | @@ -65,10 +65,10 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | test "statically initialized list" { |
| 68 | expect(static_point_list[0].x == 1); | |
| 69 | expect(static_point_list[0].y == 2); | |
| 70 | expect(static_point_list[1].x == 3); | |
| 71 | expect(static_point_list[1].y == 4); | |
| 68 | try expect(static_point_list[0].x == 1); | |
| 69 | try expect(static_point_list[0].y == 2); | |
| 70 | try expect(static_point_list[1].x == 3); | |
| 71 | try expect(static_point_list[1].y == 4); | |
| 72 | 72 | } |
| 73 | 73 | const Point = struct { |
| 74 | 74 | x: i32, |
| ... | ... | @@ -86,8 +86,8 @@ fn makePoint(x: i32, y: i32) Point { |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | test "static eval list init" { |
| 89 | expect(static_vec3.data[2] == 1.0); | |
| 90 | expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0); | |
| 89 | try expect(static_vec3.data[2] == 1.0); | |
| 90 | try expect(vec3(0.0, 0.0, 3.0).data[2] == 3.0); | |
| 91 | 91 | } |
| 92 | 92 | const static_vec3 = vec3(0.0, 0.0, 1.0); |
| 93 | 93 | pub const Vec3 = struct { |
| ... | ... | @@ -105,12 +105,12 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 { |
| 105 | 105 | |
| 106 | 106 | test "constant expressions" { |
| 107 | 107 | var array: [array_size]u8 = undefined; |
| 108 | expect(@sizeOf(@TypeOf(array)) == 20); | |
| 108 | try expect(@sizeOf(@TypeOf(array)) == 20); | |
| 109 | 109 | } |
| 110 | 110 | const array_size: u8 = 20; |
| 111 | 111 | |
| 112 | 112 | test "constant struct with negation" { |
| 113 | expect(vertices[0].x == -0.6); | |
| 113 | try expect(vertices[0].x == -0.6); | |
| 114 | 114 | } |
| 115 | 115 | const Vertex = struct { |
| 116 | 116 | x: f32, |
| ... | ... | @@ -145,7 +145,7 @@ const vertices = [_]Vertex{ |
| 145 | 145 | |
| 146 | 146 | test "statically initialized struct" { |
| 147 | 147 | st_init_str_foo.x += 1; |
| 148 | expect(st_init_str_foo.x == 14); | |
| 148 | try expect(st_init_str_foo.x == 14); | |
| 149 | 149 | } |
| 150 | 150 | const StInitStrFoo = struct { |
| 151 | 151 | x: i32, |
| ... | ... | @@ -158,7 +158,7 @@ var st_init_str_foo = StInitStrFoo{ |
| 158 | 158 | |
| 159 | 159 | test "statically initalized array literal" { |
| 160 | 160 | const y: [4]u8 = st_init_arr_lit_x; |
| 161 | expect(y[3] == 4); | |
| 161 | try expect(y[3] == 4); | |
| 162 | 162 | } |
| 163 | 163 | const st_init_arr_lit_x = [_]u8{ |
| 164 | 164 | 1, |
| ... | ... | @@ -170,15 +170,15 @@ const st_init_arr_lit_x = [_]u8{ |
| 170 | 170 | test "const slice" { |
| 171 | 171 | comptime { |
| 172 | 172 | const a = "1234567890"; |
| 173 | expect(a.len == 10); | |
| 173 | try expect(a.len == 10); | |
| 174 | 174 | const b = a[1..2]; |
| 175 | expect(b.len == 1); | |
| 176 | expect(b[0] == '2'); | |
| 175 | try expect(b.len == 1); | |
| 176 | try expect(b[0] == '2'); | |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | test "try to trick eval with runtime if" { |
| 181 | expect(testTryToTrickEvalWithRuntimeIf(true) == 10); | |
| 181 | try expect(testTryToTrickEvalWithRuntimeIf(true) == 10); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | fn testTryToTrickEvalWithRuntimeIf(b: bool) usize { |
| ... | ... | @@ -198,7 +198,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio |
| 198 | 198 | const result = if (i == 0) [1]i32{2} else runtime; |
| 199 | 199 | } |
| 200 | 200 | comptime { |
| 201 | expect(i == 2); | |
| 201 | try expect(i == 2); | |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| ... | ... | @@ -215,16 +215,16 @@ fn letsTryToCompareBools(a: bool, b: bool) bool { |
| 215 | 215 | return max(bool, a, b); |
| 216 | 216 | } |
| 217 | 217 | test "inlined block and runtime block phi" { |
| 218 | expect(letsTryToCompareBools(true, true)); | |
| 219 | expect(letsTryToCompareBools(true, false)); | |
| 220 | expect(letsTryToCompareBools(false, true)); | |
| 221 | expect(!letsTryToCompareBools(false, false)); | |
| 218 | try expect(letsTryToCompareBools(true, true)); | |
| 219 | try expect(letsTryToCompareBools(true, false)); | |
| 220 | try expect(letsTryToCompareBools(false, true)); | |
| 221 | try expect(!letsTryToCompareBools(false, false)); | |
| 222 | 222 | |
| 223 | 223 | comptime { |
| 224 | expect(letsTryToCompareBools(true, true)); | |
| 225 | expect(letsTryToCompareBools(true, false)); | |
| 226 | expect(letsTryToCompareBools(false, true)); | |
| 227 | expect(!letsTryToCompareBools(false, false)); | |
| 224 | try expect(letsTryToCompareBools(true, true)); | |
| 225 | try expect(letsTryToCompareBools(true, false)); | |
| 226 | try expect(letsTryToCompareBools(false, true)); | |
| 227 | try expect(!letsTryToCompareBools(false, false)); | |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| ... | ... | @@ -269,14 +269,14 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | test "comptime iterate over fn ptr list" { |
| 272 | expect(performFn('t', 1) == 6); | |
| 273 | expect(performFn('o', 0) == 1); | |
| 274 | expect(performFn('w', 99) == 99); | |
| 272 | try expect(performFn('t', 1) == 6); | |
| 273 | try expect(performFn('o', 0) == 1); | |
| 274 | try expect(performFn('w', 99) == 99); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | test "eval @setRuntimeSafety at compile-time" { |
| 278 | 278 | const result = comptime fnWithSetRuntimeSafety(); |
| 279 | expect(result == 1234); | |
| 279 | try expect(result == 1234); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | fn fnWithSetRuntimeSafety() i32 { |
| ... | ... | @@ -286,7 +286,7 @@ fn fnWithSetRuntimeSafety() i32 { |
| 286 | 286 | |
| 287 | 287 | test "eval @setFloatMode at compile-time" { |
| 288 | 288 | const result = comptime fnWithFloatMode(); |
| 289 | expect(result == 1234.0); | |
| 289 | try expect(result == 1234.0); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | fn fnWithFloatMode() f32 { |
| ... | ... | @@ -307,15 +307,15 @@ var simple_struct = SimpleStruct{ .field = 1234 }; |
| 307 | 307 | const bound_fn = simple_struct.method; |
| 308 | 308 | |
| 309 | 309 | test "call method on bound fn referring to var instance" { |
| 310 | expect(bound_fn() == 1237); | |
| 310 | try expect(bound_fn() == 1237); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | test "ptr to local array argument at comptime" { |
| 314 | 314 | comptime { |
| 315 | 315 | var bytes: [10]u8 = undefined; |
| 316 | 316 | modifySomeBytes(bytes[0..]); |
| 317 | expect(bytes[0] == 'a'); | |
| 318 | expect(bytes[9] == 'b'); | |
| 317 | try expect(bytes[0] == 'a'); | |
| 318 | try expect(bytes[9] == 'b'); | |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
| ... | ... | @@ -343,9 +343,9 @@ fn testCompTimeUIntComparisons(x: u32) void { |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | test "const ptr to variable data changes at runtime" { |
| 346 | expect(foo_ref.name[0] == 'a'); | |
| 346 | try expect(foo_ref.name[0] == 'a'); | |
| 347 | 347 | foo_ref.name = "b"; |
| 348 | expect(foo_ref.name[0] == 'b'); | |
| 348 | try expect(foo_ref.name[0] == 'b'); | |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | const Foo = struct { |
| ... | ... | @@ -356,8 +356,8 @@ var foo_contents = Foo{ .name = "a" }; |
| 356 | 356 | const foo_ref = &foo_contents; |
| 357 | 357 | |
| 358 | 358 | test "create global array with for loop" { |
| 359 | expect(global_array[5] == 5 * 5); | |
| 360 | expect(global_array[9] == 9 * 9); | |
| 359 | try expect(global_array[5] == 5 * 5); | |
| 360 | try expect(global_array[9] == 9 * 9); | |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | const global_array = x: { |
| ... | ... | @@ -372,18 +372,18 @@ test "compile-time downcast when the bits fit" { |
| 372 | 372 | comptime { |
| 373 | 373 | const spartan_count: u16 = 255; |
| 374 | 374 | const byte = @intCast(u8, spartan_count); |
| 375 | expect(byte == 255); | |
| 375 | try expect(byte == 255); | |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | const hi1 = "hi"; |
| 380 | 380 | const hi2 = hi1; |
| 381 | 381 | test "const global shares pointer with other same one" { |
| 382 | assertEqualPtrs(&hi1[0], &hi2[0]); | |
| 383 | comptime expect(&hi1[0] == &hi2[0]); | |
| 382 | try assertEqualPtrs(&hi1[0], &hi2[0]); | |
| 383 | comptime try expect(&hi1[0] == &hi2[0]); | |
| 384 | 384 | } |
| 385 | fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) void { | |
| 386 | expect(ptr1 == ptr2); | |
| 385 | fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void { | |
| 386 | try expect(ptr1 == ptr2); | |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | test "@setEvalBranchQuota" { |
| ... | ... | @@ -395,29 +395,29 @@ test "@setEvalBranchQuota" { |
| 395 | 395 | while (i < 1001) : (i += 1) { |
| 396 | 396 | sum += i; |
| 397 | 397 | } |
| 398 | expect(sum == 500500); | |
| 398 | try expect(sum == 500500); | |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | test "float literal at compile time not lossy" { |
| 403 | expect(16777216.0 + 1.0 == 16777217.0); | |
| 404 | expect(9007199254740992.0 + 1.0 == 9007199254740993.0); | |
| 403 | try expect(16777216.0 + 1.0 == 16777217.0); | |
| 404 | try expect(9007199254740992.0 + 1.0 == 9007199254740993.0); | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | test "f32 at compile time is lossy" { |
| 408 | expect(@as(f32, 1 << 24) + 1 == 1 << 24); | |
| 408 | try expect(@as(f32, 1 << 24) + 1 == 1 << 24); | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | test "f64 at compile time is lossy" { |
| 412 | expect(@as(f64, 1 << 53) + 1 == 1 << 53); | |
| 412 | try expect(@as(f64, 1 << 53) + 1 == 1 << 53); | |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | test "f128 at compile time is lossy" { |
| 416 | expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 416 | try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0); | |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | comptime { |
| 420 | expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); | |
| 420 | try expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| ... | ... | @@ -429,15 +429,15 @@ pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| 429 | 429 | test "string literal used as comptime slice is memoized" { |
| 430 | 430 | const a = "link"; |
| 431 | 431 | const b = "link"; |
| 432 | comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 433 | comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 432 | comptime try expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 433 | comptime try expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | test "comptime slice of undefined pointer of length 0" { |
| 437 | 437 | const slice1 = @as([*]i32, undefined)[0..0]; |
| 438 | expect(slice1.len == 0); | |
| 438 | try expect(slice1.len == 0); | |
| 439 | 439 | const slice2 = @as([*]i32, undefined)[100..100]; |
| 440 | expect(slice2.len == 0); | |
| 440 | try expect(slice2.len == 0); | |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | fn copyWithPartialInline(s: []u32, b: []u8) void { |
| ... | ... | @@ -459,16 +459,16 @@ test "binary math operator in partially inlined function" { |
| 459 | 459 | r.* = @intCast(u8, i + 1); |
| 460 | 460 | |
| 461 | 461 | copyWithPartialInline(s[0..], b[0..]); |
| 462 | expect(s[0] == 0x1020304); | |
| 463 | expect(s[1] == 0x5060708); | |
| 464 | expect(s[2] == 0x90a0b0c); | |
| 465 | expect(s[3] == 0xd0e0f10); | |
| 462 | try expect(s[0] == 0x1020304); | |
| 463 | try expect(s[1] == 0x5060708); | |
| 464 | try expect(s[2] == 0x90a0b0c); | |
| 465 | try expect(s[3] == 0xd0e0f10); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | test "comptime function with the same args is memoized" { |
| 469 | 469 | comptime { |
| 470 | expect(MakeType(i32) == MakeType(i32)); | |
| 471 | expect(MakeType(i32) != MakeType(f64)); | |
| 470 | try expect(MakeType(i32) == MakeType(i32)); | |
| 471 | try expect(MakeType(i32) != MakeType(f64)); | |
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| ... | ... | @@ -484,7 +484,7 @@ test "comptime function with mutable pointer is not memoized" { |
| 484 | 484 | const ptr = &x; |
| 485 | 485 | increment(ptr); |
| 486 | 486 | increment(ptr); |
| 487 | expect(x == 3); | |
| 487 | try expect(x == 3); | |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | |
| ... | ... | @@ -510,14 +510,14 @@ fn doesAlotT(comptime T: type, value: usize) T { |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | test "@setEvalBranchQuota at same scope as generic function call" { |
| 513 | expect(doesAlotT(u32, 2) == 2); | |
| 513 | try expect(doesAlotT(u32, 2) == 2); | |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | test "comptime slice of slice preserves comptime var" { |
| 517 | 517 | comptime { |
| 518 | 518 | var buff: [10]u8 = undefined; |
| 519 | 519 | buff[0..][0..][0] = 1; |
| 520 | expect(buff[0..][0..][0] == 1); | |
| 520 | try expect(buff[0..][0..][0] == 1); | |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
| ... | ... | @@ -526,7 +526,7 @@ test "comptime slice of pointer preserves comptime var" { |
| 526 | 526 | var buff: [10]u8 = undefined; |
| 527 | 527 | var a = @ptrCast([*]u8, &buff); |
| 528 | 528 | a[0..1][0] = 1; |
| 529 | expect(buff[0..][0..][0] == 1); | |
| 529 | try expect(buff[0..][0..][0] == 1); | |
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | 532 | |
| ... | ... | @@ -540,9 +540,9 @@ const SingleFieldStruct = struct { |
| 540 | 540 | test "const ptr to comptime mutable data is not memoized" { |
| 541 | 541 | comptime { |
| 542 | 542 | var foo = SingleFieldStruct{ .x = 1 }; |
| 543 | expect(foo.read_x() == 1); | |
| 543 | try expect(foo.read_x() == 1); | |
| 544 | 544 | foo.x = 2; |
| 545 | expect(foo.read_x() == 2); | |
| 545 | try expect(foo.read_x() == 2); | |
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | |
| ... | ... | @@ -551,7 +551,7 @@ test "array concat of slices gives slice" { |
| 551 | 551 | var a: []const u8 = "aoeu"; |
| 552 | 552 | var b: []const u8 = "asdf"; |
| 553 | 553 | const c = a ++ b; |
| 554 | expect(std.mem.eql(u8, c, "aoeuasdf")); | |
| 554 | try expect(std.mem.eql(u8, c, "aoeuasdf")); | |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| ... | ... | @@ -568,14 +568,14 @@ test "comptime shlWithOverflow" { |
| 568 | 568 | break :amt amt; |
| 569 | 569 | }; |
| 570 | 570 | |
| 571 | expect(ct_shifted == rt_shifted); | |
| 571 | try expect(ct_shifted == rt_shifted); | |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | test "runtime 128 bit integer division" { |
| 575 | 575 | var a: u128 = 152313999999999991610955792383; |
| 576 | 576 | var b: u128 = 10000000000000000000; |
| 577 | 577 | var c = a / b; |
| 578 | expect(c == 15231399999); | |
| 578 | try expect(c == 15231399999); | |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | pub const Info = struct { |
| ... | ... | @@ -588,20 +588,20 @@ test "comptime modification of const struct field" { |
| 588 | 588 | comptime { |
| 589 | 589 | var res = diamond_info; |
| 590 | 590 | res.version = 1; |
| 591 | expect(diamond_info.version == 0); | |
| 592 | expect(res.version == 1); | |
| 591 | try expect(diamond_info.version == 0); | |
| 592 | try expect(res.version == 1); | |
| 593 | 593 | } |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | test "pointer to type" { |
| 597 | 597 | comptime { |
| 598 | 598 | var T: type = i32; |
| 599 | expect(T == i32); | |
| 599 | try expect(T == i32); | |
| 600 | 600 | var ptr = &T; |
| 601 | expect(@TypeOf(ptr) == *type); | |
| 601 | try expect(@TypeOf(ptr) == *type); | |
| 602 | 602 | ptr.* = f32; |
| 603 | expect(T == f32); | |
| 604 | expect(*T == *f32); | |
| 603 | try expect(T == f32); | |
| 604 | try expect(*T == *f32); | |
| 605 | 605 | } |
| 606 | 606 | } |
| 607 | 607 | |
| ... | ... | @@ -610,17 +610,17 @@ test "slice of type" { |
| 610 | 610 | var types_array = [_]type{ i32, f64, type }; |
| 611 | 611 | for (types_array) |T, i| { |
| 612 | 612 | switch (i) { |
| 613 | 0 => expect(T == i32), | |
| 614 | 1 => expect(T == f64), | |
| 615 | 2 => expect(T == type), | |
| 613 | 0 => try expect(T == i32), | |
| 614 | 1 => try expect(T == f64), | |
| 615 | 2 => try expect(T == type), | |
| 616 | 616 | else => unreachable, |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | for (types_array[0..]) |T, i| { |
| 620 | 620 | switch (i) { |
| 621 | 0 => expect(T == i32), | |
| 622 | 1 => expect(T == f64), | |
| 623 | 2 => expect(T == type), | |
| 621 | 0 => try expect(T == i32), | |
| 622 | 1 => try expect(T == f64), | |
| 623 | 2 => try expect(T == type), | |
| 624 | 624 | else => unreachable, |
| 625 | 625 | } |
| 626 | 626 | } |
| ... | ... | @@ -637,7 +637,7 @@ fn wrap(comptime T: type) Wrapper { |
| 637 | 637 | |
| 638 | 638 | test "function which returns struct with type field causes implicit comptime" { |
| 639 | 639 | const ty = wrap(i32).T; |
| 640 | expect(ty == i32); | |
| 640 | try expect(ty == i32); | |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | test "call method with comptime pass-by-non-copying-value self parameter" { |
| ... | ... | @@ -651,12 +651,12 @@ test "call method with comptime pass-by-non-copying-value self parameter" { |
| 651 | 651 | |
| 652 | 652 | const s = S{ .a = 2 }; |
| 653 | 653 | var b = s.b(); |
| 654 | expect(b == 2); | |
| 654 | try expect(b == 2); | |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | test "@tagName of @typeInfo" { |
| 658 | 658 | const str = @tagName(@typeInfo(u8)); |
| 659 | expect(std.mem.eql(u8, str, "Int")); | |
| 659 | try expect(std.mem.eql(u8, str, "Int")); | |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | test "setting backward branch quota just before a generic fn call" { |
| ... | ... | @@ -670,15 +670,15 @@ fn loopNTimes(comptime n: usize) void { |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | test "variable inside inline loop that has different types on different iterations" { |
| 673 | testVarInsideInlineLoop(.{ true, @as(u32, 42) }); | |
| 673 | try testVarInsideInlineLoop(.{ true, @as(u32, 42) }); | |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | fn testVarInsideInlineLoop(args: anytype) void { | |
| 676 | fn testVarInsideInlineLoop(args: anytype) !void { | |
| 677 | 677 | comptime var i = 0; |
| 678 | 678 | inline while (i < args.len) : (i += 1) { |
| 679 | 679 | const x = args[i]; |
| 680 | if (i == 0) expect(x); | |
| 681 | if (i == 1) expect(x == 42); | |
| 680 | if (i == 0) try expect(x); | |
| 681 | if (i == 1) try expect(x == 42); | |
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
| ... | ... | @@ -688,7 +688,7 @@ test "inline for with same type but different values" { |
| 688 | 688 | var a: T = undefined; |
| 689 | 689 | res += a.len; |
| 690 | 690 | } |
| 691 | expect(res == 5); | |
| 691 | try expect(res == 5); | |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | test "refer to the type of a generic function" { |
| ... | ... | @@ -702,13 +702,13 @@ fn doNothingWithType(comptime T: type) void {} |
| 702 | 702 | test "zero extend from u0 to u1" { |
| 703 | 703 | var zero_u0: u0 = 0; |
| 704 | 704 | var zero_u1: u1 = zero_u0; |
| 705 | expect(zero_u1 == 0); | |
| 705 | try expect(zero_u1 == 0); | |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | test "bit shift a u1" { |
| 709 | 709 | var x: u1 = 1; |
| 710 | 710 | var y = x << 0; |
| 711 | expect(y == 1); | |
| 711 | try expect(y == 1); | |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | test "comptime pointer cast array and then slice" { |
| ... | ... | @@ -720,8 +720,8 @@ test "comptime pointer cast array and then slice" { |
| 720 | 720 | const ptrB: [*]const u8 = &array; |
| 721 | 721 | const sliceB: []const u8 = ptrB[0..2]; |
| 722 | 722 | |
| 723 | expect(sliceA[1] == 2); | |
| 724 | expect(sliceB[1] == 2); | |
| 723 | try expect(sliceA[1] == 2); | |
| 724 | try expect(sliceB[1] == 2); | |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | test "slice bounds in comptime concatenation" { |
| ... | ... | @@ -730,46 +730,46 @@ test "slice bounds in comptime concatenation" { |
| 730 | 730 | break :blk b[8..9]; |
| 731 | 731 | }; |
| 732 | 732 | const str = "" ++ bs; |
| 733 | expect(str.len == 1); | |
| 734 | expect(std.mem.eql(u8, str, "1")); | |
| 733 | try expect(str.len == 1); | |
| 734 | try expect(std.mem.eql(u8, str, "1")); | |
| 735 | 735 | |
| 736 | 736 | const str2 = bs ++ ""; |
| 737 | expect(str2.len == 1); | |
| 738 | expect(std.mem.eql(u8, str2, "1")); | |
| 737 | try expect(str2.len == 1); | |
| 738 | try expect(std.mem.eql(u8, str2, "1")); | |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | test "comptime bitwise operators" { |
| 742 | 742 | comptime { |
| 743 | expect(3 & 1 == 1); | |
| 744 | expect(3 & -1 == 3); | |
| 745 | expect(-3 & -1 == -3); | |
| 746 | expect(3 | -1 == -1); | |
| 747 | expect(-3 | -1 == -1); | |
| 748 | expect(3 ^ -1 == -4); | |
| 749 | expect(-3 ^ -1 == 2); | |
| 750 | expect(~@as(i8, -1) == 0); | |
| 751 | expect(~@as(i128, -1) == 0); | |
| 752 | expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); | |
| 753 | expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); | |
| 754 | expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff); | |
| 743 | try expect(3 & 1 == 1); | |
| 744 | try expect(3 & -1 == 3); | |
| 745 | try expect(-3 & -1 == -3); | |
| 746 | try expect(3 | -1 == -1); | |
| 747 | try expect(-3 | -1 == -1); | |
| 748 | try expect(3 ^ -1 == -4); | |
| 749 | try expect(-3 ^ -1 == 2); | |
| 750 | try expect(~@as(i8, -1) == 0); | |
| 751 | try expect(~@as(i128, -1) == 0); | |
| 752 | try expect(18446744073709551615 & 18446744073709551611 == 18446744073709551611); | |
| 753 | try expect(-18446744073709551615 & -18446744073709551611 == -18446744073709551615); | |
| 754 | try expect(~@as(u128, 0) == 0xffffffffffffffffffffffffffffffff); | |
| 755 | 755 | } |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | test "*align(1) u16 is the same as *align(1:0:2) u16" { |
| 759 | 759 | comptime { |
| 760 | expect(*align(1:0:2) u16 == *align(1) u16); | |
| 761 | expect(*align(2:0:2) u16 == *u16); | |
| 760 | try expect(*align(1:0:2) u16 == *align(1) u16); | |
| 761 | try expect(*align(2:0:2) u16 == *u16); | |
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | test "array concatenation forces comptime" { |
| 766 | 766 | var a = oneItem(3) ++ oneItem(4); |
| 767 | expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); | |
| 767 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); | |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | test "array multiplication forces comptime" { |
| 771 | 771 | var a = oneItem(3) ** scalar(2); |
| 772 | expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); | |
| 772 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); | |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | fn oneItem(x: i32) [1]i32 { |
| ... | ... | @@ -791,7 +791,7 @@ test "comptime assign int to optional int" { |
| 791 | 791 | var x: ?i32 = null; |
| 792 | 792 | x = 2; |
| 793 | 793 | x.? *= 10; |
| 794 | expectEqual(20, x.?); | |
| 794 | try expectEqual(20, x.?); | |
| 795 | 795 | } |
| 796 | 796 | } |
| 797 | 797 |
test/stage1/behavior/field_parent_ptr.zig+12-12| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "@fieldParentPtr non-first field" { |
| 4 | testParentFieldPtr(&foo.c); | |
| 5 | comptime testParentFieldPtr(&foo.c); | |
| 4 | try testParentFieldPtr(&foo.c); | |
| 5 | comptime try testParentFieldPtr(&foo.c); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | test "@fieldParentPtr first field" { |
| 9 | testParentFieldPtrFirst(&foo.a); | |
| 10 | comptime testParentFieldPtrFirst(&foo.a); | |
| 9 | try testParentFieldPtrFirst(&foo.a); | |
| 10 | comptime try testParentFieldPtrFirst(&foo.a); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | const Foo = struct { |
| ... | ... | @@ -24,18 +24,18 @@ const foo = Foo{ |
| 24 | 24 | .d = -10, |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | fn testParentFieldPtr(c: *const i32) void { | |
| 28 | expect(c == &foo.c); | |
| 27 | fn testParentFieldPtr(c: *const i32) !void { | |
| 28 | try expect(c == &foo.c); | |
| 29 | 29 | |
| 30 | 30 | const base = @fieldParentPtr(Foo, "c", c); |
| 31 | expect(base == &foo); | |
| 32 | expect(&base.c == c); | |
| 31 | try expect(base == &foo); | |
| 32 | try expect(&base.c == c); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | fn testParentFieldPtrFirst(a: *const bool) void { | |
| 36 | expect(a == &foo.a); | |
| 35 | fn testParentFieldPtrFirst(a: *const bool) !void { | |
| 36 | try expect(a == &foo.a); | |
| 37 | 37 | |
| 38 | 38 | const base = @fieldParentPtr(Foo, "a", a); |
| 39 | expect(base == &foo); | |
| 40 | expect(&base.a == a); | |
| 39 | try expect(base == &foo); | |
| 40 | try expect(&base.a == a); | |
| 41 | 41 | } |
test/stage1/behavior/floatop.zig+161-161| ... | ... | @@ -8,441 +8,441 @@ const Vector = std.meta.Vector; |
| 8 | 8 | const epsilon = 0.000001; |
| 9 | 9 | |
| 10 | 10 | test "@sqrt" { |
| 11 | comptime testSqrt(); | |
| 12 | testSqrt(); | |
| 11 | comptime try testSqrt(); | |
| 12 | try testSqrt(); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | fn testSqrt() void { | |
| 15 | fn testSqrt() !void { | |
| 16 | 16 | { |
| 17 | 17 | var a: f16 = 4; |
| 18 | expect(@sqrt(a) == 2); | |
| 18 | try expect(@sqrt(a) == 2); | |
| 19 | 19 | } |
| 20 | 20 | { |
| 21 | 21 | var a: f32 = 9; |
| 22 | expect(@sqrt(a) == 3); | |
| 22 | try expect(@sqrt(a) == 3); | |
| 23 | 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 | 27 | var a: f64 = 25; |
| 28 | expect(@sqrt(a) == 5); | |
| 28 | try expect(@sqrt(a) == 5); | |
| 29 | 29 | } |
| 30 | 30 | { |
| 31 | 31 | const a: comptime_float = 25.0; |
| 32 | expect(@sqrt(a) == 5.0); | |
| 32 | try expect(@sqrt(a) == 5.0); | |
| 33 | 33 | } |
| 34 | 34 | // TODO https://github.com/ziglang/zig/issues/4026 |
| 35 | 35 | //{ |
| 36 | 36 | // var a: f128 = 49; |
| 37 | // expect(@sqrt(a) == 7); | |
| 37 | //try expect(@sqrt(a) == 7); | |
| 38 | 38 | //} |
| 39 | 39 | { |
| 40 | 40 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 41 | 41 | var result = @sqrt(v); |
| 42 | expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); | |
| 43 | expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); | |
| 44 | expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); | |
| 45 | expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon)); | |
| 42 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon)); | |
| 43 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon)); | |
| 44 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 3.3)), result[2], epsilon)); | |
| 45 | try expect(math.approxEqAbs(f32, @sqrt(@as(f32, 4.4)), result[3], epsilon)); | |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | test "more @sqrt f16 tests" { |
| 50 | 50 | // TODO these are not all passing at comptime |
| 51 | expect(@sqrt(@as(f16, 0.0)) == 0.0); | |
| 52 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon)); | |
| 53 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon)); | |
| 54 | expect(@sqrt(@as(f16, 4.0)) == 2.0); | |
| 55 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon)); | |
| 56 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon)); | |
| 57 | expect(@sqrt(@as(f16, 64.0)) == 8.0); | |
| 58 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon)); | |
| 59 | expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon)); | |
| 51 | try expect(@sqrt(@as(f16, 0.0)) == 0.0); | |
| 52 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 2.0)), 1.414214, epsilon)); | |
| 53 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 3.6)), 1.897367, epsilon)); | |
| 54 | try expect(@sqrt(@as(f16, 4.0)) == 2.0); | |
| 55 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 7.539840)), 2.745877, epsilon)); | |
| 56 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 19.230934)), 4.385309, epsilon)); | |
| 57 | try expect(@sqrt(@as(f16, 64.0)) == 8.0); | |
| 58 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 64.1)), 8.006248, epsilon)); | |
| 59 | try expect(math.approxEqAbs(f16, @sqrt(@as(f16, 8942.230469)), 94.563370, epsilon)); | |
| 60 | 60 | |
| 61 | 61 | // special cases |
| 62 | expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16))))); | |
| 63 | expect(@sqrt(@as(f16, 0.0)) == 0.0); | |
| 64 | expect(@sqrt(@as(f16, -0.0)) == -0.0); | |
| 65 | expect(math.isNan(@sqrt(@as(f16, -1.0)))); | |
| 66 | expect(math.isNan(@sqrt(@as(f16, math.nan(f16))))); | |
| 62 | try expect(math.isPositiveInf(@sqrt(@as(f16, math.inf(f16))))); | |
| 63 | try expect(@sqrt(@as(f16, 0.0)) == 0.0); | |
| 64 | try expect(@sqrt(@as(f16, -0.0)) == -0.0); | |
| 65 | try expect(math.isNan(@sqrt(@as(f16, -1.0)))); | |
| 66 | try expect(math.isNan(@sqrt(@as(f16, math.nan(f16))))); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | test "@sin" { |
| 70 | comptime testSin(); | |
| 71 | testSin(); | |
| 70 | comptime try testSin(); | |
| 71 | try testSin(); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | fn testSin() void { | |
| 74 | fn testSin() !void { | |
| 75 | 75 | // TODO test f128, and c_longdouble |
| 76 | 76 | // https://github.com/ziglang/zig/issues/4026 |
| 77 | 77 | { |
| 78 | 78 | var a: f16 = 0; |
| 79 | expect(@sin(a) == 0); | |
| 79 | try expect(@sin(a) == 0); | |
| 80 | 80 | } |
| 81 | 81 | { |
| 82 | 82 | var a: f32 = 0; |
| 83 | expect(@sin(a) == 0); | |
| 83 | try expect(@sin(a) == 0); | |
| 84 | 84 | } |
| 85 | 85 | { |
| 86 | 86 | var a: f64 = 0; |
| 87 | expect(@sin(a) == 0); | |
| 87 | try expect(@sin(a) == 0); | |
| 88 | 88 | } |
| 89 | 89 | { |
| 90 | 90 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 91 | 91 | var result = @sin(v); |
| 92 | expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); | |
| 93 | expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); | |
| 94 | expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); | |
| 95 | expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon)); | |
| 92 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 1.1)), result[0], epsilon)); | |
| 93 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 2.2)), result[1], epsilon)); | |
| 94 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 3.3)), result[2], epsilon)); | |
| 95 | try expect(math.approxEqAbs(f32, @sin(@as(f32, 4.4)), result[3], epsilon)); | |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test "@cos" { |
| 100 | comptime testCos(); | |
| 101 | testCos(); | |
| 100 | comptime try testCos(); | |
| 101 | try testCos(); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | fn testCos() void { | |
| 104 | fn testCos() !void { | |
| 105 | 105 | // TODO test f128, and c_longdouble |
| 106 | 106 | // https://github.com/ziglang/zig/issues/4026 |
| 107 | 107 | { |
| 108 | 108 | var a: f16 = 0; |
| 109 | expect(@cos(a) == 1); | |
| 109 | try expect(@cos(a) == 1); | |
| 110 | 110 | } |
| 111 | 111 | { |
| 112 | 112 | var a: f32 = 0; |
| 113 | expect(@cos(a) == 1); | |
| 113 | try expect(@cos(a) == 1); | |
| 114 | 114 | } |
| 115 | 115 | { |
| 116 | 116 | var a: f64 = 0; |
| 117 | expect(@cos(a) == 1); | |
| 117 | try expect(@cos(a) == 1); | |
| 118 | 118 | } |
| 119 | 119 | { |
| 120 | 120 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 121 | 121 | var result = @cos(v); |
| 122 | expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); | |
| 123 | expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); | |
| 124 | expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); | |
| 125 | expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon)); | |
| 122 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 1.1)), result[0], epsilon)); | |
| 123 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 2.2)), result[1], epsilon)); | |
| 124 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 3.3)), result[2], epsilon)); | |
| 125 | try expect(math.approxEqAbs(f32, @cos(@as(f32, 4.4)), result[3], epsilon)); | |
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | test "@exp" { |
| 130 | comptime testExp(); | |
| 131 | testExp(); | |
| 130 | comptime try testExp(); | |
| 131 | try testExp(); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | fn testExp() void { | |
| 134 | fn testExp() !void { | |
| 135 | 135 | // TODO test f128, and c_longdouble |
| 136 | 136 | // https://github.com/ziglang/zig/issues/4026 |
| 137 | 137 | { |
| 138 | 138 | var a: f16 = 0; |
| 139 | expect(@exp(a) == 1); | |
| 139 | try expect(@exp(a) == 1); | |
| 140 | 140 | } |
| 141 | 141 | { |
| 142 | 142 | var a: f32 = 0; |
| 143 | expect(@exp(a) == 1); | |
| 143 | try expect(@exp(a) == 1); | |
| 144 | 144 | } |
| 145 | 145 | { |
| 146 | 146 | var a: f64 = 0; |
| 147 | expect(@exp(a) == 1); | |
| 147 | try expect(@exp(a) == 1); | |
| 148 | 148 | } |
| 149 | 149 | { |
| 150 | 150 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 151 | 151 | var result = @exp(v); |
| 152 | expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); | |
| 153 | expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); | |
| 154 | expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); | |
| 155 | expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon)); | |
| 152 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 1.1)), result[0], epsilon)); | |
| 153 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 2.2)), result[1], epsilon)); | |
| 154 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.3)), result[2], epsilon)); | |
| 155 | try expect(math.approxEqAbs(f32, @exp(@as(f32, 0.4)), result[3], epsilon)); | |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "@exp2" { |
| 160 | comptime testExp2(); | |
| 161 | testExp2(); | |
| 160 | comptime try testExp2(); | |
| 161 | try testExp2(); | |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | fn testExp2() void { | |
| 164 | fn testExp2() !void { | |
| 165 | 165 | // TODO test f128, and c_longdouble |
| 166 | 166 | // https://github.com/ziglang/zig/issues/4026 |
| 167 | 167 | { |
| 168 | 168 | var a: f16 = 2; |
| 169 | expect(@exp2(a) == 4); | |
| 169 | try expect(@exp2(a) == 4); | |
| 170 | 170 | } |
| 171 | 171 | { |
| 172 | 172 | var a: f32 = 2; |
| 173 | expect(@exp2(a) == 4); | |
| 173 | try expect(@exp2(a) == 4); | |
| 174 | 174 | } |
| 175 | 175 | { |
| 176 | 176 | var a: f64 = 2; |
| 177 | expect(@exp2(a) == 4); | |
| 177 | try expect(@exp2(a) == 4); | |
| 178 | 178 | } |
| 179 | 179 | { |
| 180 | 180 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 181 | 181 | var result = @exp2(v); |
| 182 | expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); | |
| 183 | expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); | |
| 184 | expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); | |
| 185 | expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon)); | |
| 182 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 1.1)), result[0], epsilon)); | |
| 183 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 2.2)), result[1], epsilon)); | |
| 184 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.3)), result[2], epsilon)); | |
| 185 | try expect(math.approxEqAbs(f32, @exp2(@as(f32, 0.4)), result[3], epsilon)); | |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "@log" { |
| 190 | 190 | // Old musl (and glibc?), and our current math.ln implementation do not return 1 |
| 191 | 191 | // so also accept those values. |
| 192 | comptime testLog(); | |
| 193 | testLog(); | |
| 192 | comptime try testLog(); | |
| 193 | try testLog(); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | fn testLog() void { | |
| 196 | fn testLog() !void { | |
| 197 | 197 | // TODO test f128, and c_longdouble |
| 198 | 198 | // https://github.com/ziglang/zig/issues/4026 |
| 199 | 199 | { |
| 200 | 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 | 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 | 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 | 212 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 213 | 213 | var result = @log(v); |
| 214 | expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon)); | |
| 215 | expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon)); | |
| 216 | expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon)); | |
| 217 | expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon)); | |
| 214 | try expect(math.approxEqAbs(f32, @log(@as(f32, 1.1)), result[0], epsilon)); | |
| 215 | try expect(math.approxEqAbs(f32, @log(@as(f32, 2.2)), result[1], epsilon)); | |
| 216 | try expect(math.approxEqAbs(f32, @log(@as(f32, 0.3)), result[2], epsilon)); | |
| 217 | try expect(math.approxEqAbs(f32, @log(@as(f32, 0.4)), result[3], epsilon)); | |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | test "@log2" { |
| 222 | comptime testLog2(); | |
| 223 | testLog2(); | |
| 222 | comptime try testLog2(); | |
| 223 | try testLog2(); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | fn testLog2() void { | |
| 226 | fn testLog2() !void { | |
| 227 | 227 | // TODO test f128, and c_longdouble |
| 228 | 228 | // https://github.com/ziglang/zig/issues/4026 |
| 229 | 229 | { |
| 230 | 230 | var a: f16 = 4; |
| 231 | expect(@log2(a) == 2); | |
| 231 | try expect(@log2(a) == 2); | |
| 232 | 232 | } |
| 233 | 233 | { |
| 234 | 234 | var a: f32 = 4; |
| 235 | expect(@log2(a) == 2); | |
| 235 | try expect(@log2(a) == 2); | |
| 236 | 236 | } |
| 237 | 237 | { |
| 238 | 238 | var a: f64 = 4; |
| 239 | expect(@log2(a) == 2); | |
| 239 | try expect(@log2(a) == 2); | |
| 240 | 240 | } |
| 241 | 241 | { |
| 242 | 242 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 243 | 243 | var result = @log2(v); |
| 244 | expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon)); | |
| 245 | expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon)); | |
| 246 | expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon)); | |
| 247 | expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon)); | |
| 244 | try expect(math.approxEqAbs(f32, @log2(@as(f32, 1.1)), result[0], epsilon)); | |
| 245 | try expect(math.approxEqAbs(f32, @log2(@as(f32, 2.2)), result[1], epsilon)); | |
| 246 | try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.3)), result[2], epsilon)); | |
| 247 | try expect(math.approxEqAbs(f32, @log2(@as(f32, 0.4)), result[3], epsilon)); | |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | test "@log10" { |
| 252 | comptime testLog10(); | |
| 253 | testLog10(); | |
| 252 | comptime try testLog10(); | |
| 253 | try testLog10(); | |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | fn testLog10() void { | |
| 256 | fn testLog10() !void { | |
| 257 | 257 | // TODO test f128, and c_longdouble |
| 258 | 258 | // https://github.com/ziglang/zig/issues/4026 |
| 259 | 259 | { |
| 260 | 260 | var a: f16 = 100; |
| 261 | expect(@log10(a) == 2); | |
| 261 | try expect(@log10(a) == 2); | |
| 262 | 262 | } |
| 263 | 263 | { |
| 264 | 264 | var a: f32 = 100; |
| 265 | expect(@log10(a) == 2); | |
| 265 | try expect(@log10(a) == 2); | |
| 266 | 266 | } |
| 267 | 267 | { |
| 268 | 268 | var a: f64 = 1000; |
| 269 | expect(@log10(a) == 3); | |
| 269 | try expect(@log10(a) == 3); | |
| 270 | 270 | } |
| 271 | 271 | { |
| 272 | 272 | var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 }; |
| 273 | 273 | var result = @log10(v); |
| 274 | expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon)); | |
| 275 | expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon)); | |
| 276 | expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon)); | |
| 277 | expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon)); | |
| 274 | try expect(math.approxEqAbs(f32, @log10(@as(f32, 1.1)), result[0], epsilon)); | |
| 275 | try expect(math.approxEqAbs(f32, @log10(@as(f32, 2.2)), result[1], epsilon)); | |
| 276 | try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.3)), result[2], epsilon)); | |
| 277 | try expect(math.approxEqAbs(f32, @log10(@as(f32, 0.4)), result[3], epsilon)); | |
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | test "@fabs" { |
| 282 | comptime testFabs(); | |
| 283 | testFabs(); | |
| 282 | comptime try testFabs(); | |
| 283 | try testFabs(); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | fn testFabs() void { | |
| 286 | fn testFabs() !void { | |
| 287 | 287 | // TODO test f128, and c_longdouble |
| 288 | 288 | // https://github.com/ziglang/zig/issues/4026 |
| 289 | 289 | { |
| 290 | 290 | var a: f16 = -2.5; |
| 291 | 291 | var b: f16 = 2.5; |
| 292 | expect(@fabs(a) == 2.5); | |
| 293 | expect(@fabs(b) == 2.5); | |
| 292 | try expect(@fabs(a) == 2.5); | |
| 293 | try expect(@fabs(b) == 2.5); | |
| 294 | 294 | } |
| 295 | 295 | { |
| 296 | 296 | var a: f32 = -2.5; |
| 297 | 297 | var b: f32 = 2.5; |
| 298 | expect(@fabs(a) == 2.5); | |
| 299 | expect(@fabs(b) == 2.5); | |
| 298 | try expect(@fabs(a) == 2.5); | |
| 299 | try expect(@fabs(b) == 2.5); | |
| 300 | 300 | } |
| 301 | 301 | { |
| 302 | 302 | var a: f64 = -2.5; |
| 303 | 303 | var b: f64 = 2.5; |
| 304 | expect(@fabs(a) == 2.5); | |
| 305 | expect(@fabs(b) == 2.5); | |
| 304 | try expect(@fabs(a) == 2.5); | |
| 305 | try expect(@fabs(b) == 2.5); | |
| 306 | 306 | } |
| 307 | 307 | { |
| 308 | 308 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 309 | 309 | var result = @fabs(v); |
| 310 | expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon)); | |
| 311 | expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon)); | |
| 312 | expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon)); | |
| 313 | expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon)); | |
| 310 | try expect(math.approxEqAbs(f32, @fabs(@as(f32, 1.1)), result[0], epsilon)); | |
| 311 | try expect(math.approxEqAbs(f32, @fabs(@as(f32, -2.2)), result[1], epsilon)); | |
| 312 | try expect(math.approxEqAbs(f32, @fabs(@as(f32, 0.3)), result[2], epsilon)); | |
| 313 | try expect(math.approxEqAbs(f32, @fabs(@as(f32, -0.4)), result[3], epsilon)); | |
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | test "@floor" { |
| 318 | comptime testFloor(); | |
| 319 | testFloor(); | |
| 318 | comptime try testFloor(); | |
| 319 | try testFloor(); | |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | fn testFloor() void { | |
| 322 | fn testFloor() !void { | |
| 323 | 323 | // TODO test f128, and c_longdouble |
| 324 | 324 | // https://github.com/ziglang/zig/issues/4026 |
| 325 | 325 | { |
| 326 | 326 | var a: f16 = 2.1; |
| 327 | expect(@floor(a) == 2); | |
| 327 | try expect(@floor(a) == 2); | |
| 328 | 328 | } |
| 329 | 329 | { |
| 330 | 330 | var a: f32 = 2.1; |
| 331 | expect(@floor(a) == 2); | |
| 331 | try expect(@floor(a) == 2); | |
| 332 | 332 | } |
| 333 | 333 | { |
| 334 | 334 | var a: f64 = 3.5; |
| 335 | expect(@floor(a) == 3); | |
| 335 | try expect(@floor(a) == 3); | |
| 336 | 336 | } |
| 337 | 337 | { |
| 338 | 338 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 339 | 339 | var result = @floor(v); |
| 340 | expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); | |
| 341 | expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); | |
| 342 | expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); | |
| 343 | expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon)); | |
| 340 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 1.1)), result[0], epsilon)); | |
| 341 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -2.2)), result[1], epsilon)); | |
| 342 | try expect(math.approxEqAbs(f32, @floor(@as(f32, 0.3)), result[2], epsilon)); | |
| 343 | try expect(math.approxEqAbs(f32, @floor(@as(f32, -0.4)), result[3], epsilon)); | |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | test "@ceil" { |
| 348 | comptime testCeil(); | |
| 349 | testCeil(); | |
| 348 | comptime try testCeil(); | |
| 349 | try testCeil(); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | fn testCeil() void { | |
| 352 | fn testCeil() !void { | |
| 353 | 353 | // TODO test f128, and c_longdouble |
| 354 | 354 | // https://github.com/ziglang/zig/issues/4026 |
| 355 | 355 | { |
| 356 | 356 | var a: f16 = 2.1; |
| 357 | expect(@ceil(a) == 3); | |
| 357 | try expect(@ceil(a) == 3); | |
| 358 | 358 | } |
| 359 | 359 | { |
| 360 | 360 | var a: f32 = 2.1; |
| 361 | expect(@ceil(a) == 3); | |
| 361 | try expect(@ceil(a) == 3); | |
| 362 | 362 | } |
| 363 | 363 | { |
| 364 | 364 | var a: f64 = 3.5; |
| 365 | expect(@ceil(a) == 4); | |
| 365 | try expect(@ceil(a) == 4); | |
| 366 | 366 | } |
| 367 | 367 | { |
| 368 | 368 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 369 | 369 | var result = @ceil(v); |
| 370 | expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); | |
| 371 | expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); | |
| 372 | expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); | |
| 373 | expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon)); | |
| 370 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 1.1)), result[0], epsilon)); | |
| 371 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -2.2)), result[1], epsilon)); | |
| 372 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, 0.3)), result[2], epsilon)); | |
| 373 | try expect(math.approxEqAbs(f32, @ceil(@as(f32, -0.4)), result[3], epsilon)); | |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | test "@trunc" { |
| 378 | comptime testTrunc(); | |
| 379 | testTrunc(); | |
| 378 | comptime try testTrunc(); | |
| 379 | try testTrunc(); | |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | fn testTrunc() void { | |
| 382 | fn testTrunc() !void { | |
| 383 | 383 | // TODO test f128, and c_longdouble |
| 384 | 384 | // https://github.com/ziglang/zig/issues/4026 |
| 385 | 385 | { |
| 386 | 386 | var a: f16 = 2.1; |
| 387 | expect(@trunc(a) == 2); | |
| 387 | try expect(@trunc(a) == 2); | |
| 388 | 388 | } |
| 389 | 389 | { |
| 390 | 390 | var a: f32 = 2.1; |
| 391 | expect(@trunc(a) == 2); | |
| 391 | try expect(@trunc(a) == 2); | |
| 392 | 392 | } |
| 393 | 393 | { |
| 394 | 394 | var a: f64 = -3.5; |
| 395 | expect(@trunc(a) == -3); | |
| 395 | try expect(@trunc(a) == -3); | |
| 396 | 396 | } |
| 397 | 397 | { |
| 398 | 398 | var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 }; |
| 399 | 399 | var result = @trunc(v); |
| 400 | expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); | |
| 401 | expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); | |
| 402 | expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); | |
| 403 | expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon)); | |
| 400 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 1.1)), result[0], epsilon)); | |
| 401 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -2.2)), result[1], epsilon)); | |
| 402 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, 0.3)), result[2], epsilon)); | |
| 403 | try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon)); | |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | test "floating point comparisons" { |
| 408 | testFloatComparisons(); | |
| 409 | comptime testFloatComparisons(); | |
| 408 | try testFloatComparisons(); | |
| 409 | comptime try testFloatComparisons(); | |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | fn testFloatComparisons() void { | |
| 412 | fn testFloatComparisons() !void { | |
| 413 | 413 | inline for ([_]type{ f16, f32, f64, f128 }) |ty| { |
| 414 | 414 | // No decimal part |
| 415 | 415 | { |
| 416 | 416 | const x: ty = 1.0; |
| 417 | expect(x == 1); | |
| 418 | expect(x != 0); | |
| 419 | expect(x > 0); | |
| 420 | expect(x < 2); | |
| 421 | expect(x >= 1); | |
| 422 | expect(x <= 1); | |
| 417 | try expect(x == 1); | |
| 418 | try expect(x != 0); | |
| 419 | try expect(x > 0); | |
| 420 | try expect(x < 2); | |
| 421 | try expect(x >= 1); | |
| 422 | try expect(x <= 1); | |
| 423 | 423 | } |
| 424 | 424 | // Non-zero decimal part |
| 425 | 425 | { |
| 426 | 426 | const x: ty = 1.5; |
| 427 | expect(x != 1); | |
| 428 | expect(x != 2); | |
| 429 | expect(x > 1); | |
| 430 | expect(x < 2); | |
| 431 | expect(x >= 1); | |
| 432 | expect(x <= 2); | |
| 427 | try expect(x != 1); | |
| 428 | try expect(x != 2); | |
| 429 | try expect(x > 1); | |
| 430 | try expect(x < 2); | |
| 431 | try expect(x >= 1); | |
| 432 | try expect(x <= 2); | |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | test "different sized float comparisons" { |
| 438 | testDifferentSizedFloatComparisons(); | |
| 439 | comptime testDifferentSizedFloatComparisons(); | |
| 438 | try testDifferentSizedFloatComparisons(); | |
| 439 | comptime try testDifferentSizedFloatComparisons(); | |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | fn testDifferentSizedFloatComparisons() void { | |
| 442 | fn testDifferentSizedFloatComparisons() !void { | |
| 443 | 443 | var a: f16 = 1; |
| 444 | 444 | var b: f64 = 2; |
| 445 | expect(a < b); | |
| 445 | try expect(a < b); | |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 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 | 456 | // // https://github.com/ziglang/zig/issues/4026 |
| 457 | 457 | // { |
| 458 | 458 | // var a: f32 = 2.1; |
| 459 | // expect(@nearbyint(a) == 2); | |
| 459 | // try expect(@nearbyint(a) == 2); | |
| 460 | 460 | // } |
| 461 | 461 | // { |
| 462 | 462 | // var a: f64 = -3.75; |
| 463 | // expect(@nearbyint(a) == -4); | |
| 463 | // try expect(@nearbyint(a) == -4); | |
| 464 | 464 | // } |
| 465 | 465 | //} |
test/stage1/behavior/fn.zig+41-41| ... | ... | @@ -4,7 +4,7 @@ const expect = testing.expect; |
| 4 | 4 | const expectEqual = testing.expectEqual; |
| 5 | 5 | |
| 6 | 6 | test "params" { |
| 7 | expect(testParamsAdd(22, 11) == 33); | |
| 7 | try expect(testParamsAdd(22, 11) == 33); | |
| 8 | 8 | } |
| 9 | 9 | fn testParamsAdd(a: i32, b: i32) i32 { |
| 10 | 10 | return a + b; |
| ... | ... | @@ -19,37 +19,37 @@ fn testLocVars(b: i32) void { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "void parameters" { |
| 22 | voidFun(1, void{}, 2, {}); | |
| 22 | try voidFun(1, void{}, 2, {}); | |
| 23 | 23 | } |
| 24 | fn voidFun(a: i32, b: void, c: i32, d: void) void { | |
| 24 | fn voidFun(a: i32, b: void, c: i32, d: void) !void { | |
| 25 | 25 | const v = b; |
| 26 | 26 | const vv: void = if (a == 1) v else {}; |
| 27 | expect(a + c == 3); | |
| 27 | try expect(a + c == 3); | |
| 28 | 28 | return vv; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | test "mutable local variables" { |
| 32 | 32 | var zero: i32 = 0; |
| 33 | expect(zero == 0); | |
| 33 | try expect(zero == 0); | |
| 34 | 34 | |
| 35 | 35 | var i = @as(i32, 0); |
| 36 | 36 | while (i != 3) { |
| 37 | 37 | i += 1; |
| 38 | 38 | } |
| 39 | expect(i == 3); | |
| 39 | try expect(i == 3); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | test "separate block scopes" { |
| 43 | 43 | { |
| 44 | 44 | const no_conflict: i32 = 5; |
| 45 | expect(no_conflict == 5); | |
| 45 | try expect(no_conflict == 5); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | const c = x: { |
| 49 | 49 | const no_conflict = @as(i32, 10); |
| 50 | 50 | break :x no_conflict; |
| 51 | 51 | }; |
| 52 | expect(c == 10); | |
| 52 | try expect(c == 10); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "call function with empty string" { |
| ... | ... | @@ -62,7 +62,7 @@ fn @"weird function name"() i32 { |
| 62 | 62 | return 1234; |
| 63 | 63 | } |
| 64 | 64 | test "weird function name" { |
| 65 | expect(@"weird function name"() == 1234); | |
| 65 | try expect(@"weird function name"() == 1234); | |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | test "implicit cast function unreachable return" { |
| ... | ... | @@ -83,7 +83,7 @@ test "function pointers" { |
| 83 | 83 | fn4, |
| 84 | 84 | }; |
| 85 | 85 | for (fns) |f, i| { |
| 86 | expect(f() == @intCast(u32, i) + 5); | |
| 86 | try expect(f() == @intCast(u32, i) + 5); | |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | fn fn1() u32 { |
| ... | ... | @@ -100,12 +100,12 @@ fn fn4() u32 { |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "number literal as an argument" { |
| 103 | numberLiteralArg(3); | |
| 104 | comptime numberLiteralArg(3); | |
| 103 | try numberLiteralArg(3); | |
| 104 | comptime try numberLiteralArg(3); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | fn numberLiteralArg(a: anytype) void { | |
| 108 | expect(a == 3); | |
| 107 | fn numberLiteralArg(a: anytype) !void { | |
| 108 | try expect(a == 3); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | test "assign inline fn to const variable" { |
| ... | ... | @@ -116,7 +116,7 @@ test "assign inline fn to const variable" { |
| 116 | 116 | fn inlineFn() callconv(.Inline) void {} |
| 117 | 117 | |
| 118 | 118 | test "pass by non-copying value" { |
| 119 | expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); | |
| 119 | try expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | const Point = struct { |
| ... | ... | @@ -129,17 +129,17 @@ fn addPointCoords(pt: Point) i32 { |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "pass by non-copying value through var arg" { |
| 132 | expect(addPointCoordsVar(Point{ .x = 1, .y = 2 }) == 3); | |
| 132 | try expect((try addPointCoordsVar(Point{ .x = 1, .y = 2 })) == 3); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | fn addPointCoordsVar(pt: anytype) i32 { | |
| 136 | comptime expect(@TypeOf(pt) == Point); | |
| 135 | fn addPointCoordsVar(pt: anytype) !i32 { | |
| 136 | comptime try expect(@TypeOf(pt) == Point); | |
| 137 | 137 | return pt.x + pt.y; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | test "pass by non-copying value as method" { |
| 141 | 141 | var pt = Point2{ .x = 1, .y = 2 }; |
| 142 | expect(pt.addPointCoords() == 3); | |
| 142 | try expect(pt.addPointCoords() == 3); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | const Point2 = struct { |
| ... | ... | @@ -153,7 +153,7 @@ const Point2 = struct { |
| 153 | 153 | |
| 154 | 154 | test "pass by non-copying value as method, which is generic" { |
| 155 | 155 | var pt = Point3{ .x = 1, .y = 2 }; |
| 156 | expect(pt.addPointCoords(i32) == 3); | |
| 156 | try expect(pt.addPointCoords(i32) == 3); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | const Point3 = struct { |
| ... | ... | @@ -168,7 +168,7 @@ const Point3 = struct { |
| 168 | 168 | test "pass by non-copying value as method, at comptime" { |
| 169 | 169 | comptime { |
| 170 | 170 | var pt = Point2{ .x = 1, .y = 2 }; |
| 171 | expect(pt.addPointCoords() == 3); | |
| 171 | try expect(pt.addPointCoords() == 3); | |
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
| ... | ... | @@ -184,7 +184,7 @@ fn outer(y: u32) fn (u32) u32 { |
| 184 | 184 | |
| 185 | 185 | test "return inner function which references comptime variable of outer function" { |
| 186 | 186 | var func = outer(10); |
| 187 | expect(func(3) == 7); | |
| 187 | try expect(func(3) == 7); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | test "extern struct with stdcallcc fn pointer" { |
| ... | ... | @@ -198,16 +198,16 @@ test "extern struct with stdcallcc fn pointer" { |
| 198 | 198 | |
| 199 | 199 | var s: S = undefined; |
| 200 | 200 | s.ptr = S.foo; |
| 201 | expect(s.ptr() == 1234); | |
| 201 | try expect(s.ptr() == 1234); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "implicit cast fn call result to optional in field result" { |
| 205 | 205 | const S = struct { |
| 206 | fn entry() void { | |
| 206 | fn entry() !void { | |
| 207 | 207 | var x = Foo{ |
| 208 | 208 | .field = optionalPtr(), |
| 209 | 209 | }; |
| 210 | expect(x.field.?.* == 999); | |
| 210 | try expect(x.field.?.* == 999); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | const glob: i32 = 999; |
| ... | ... | @@ -220,8 +220,8 @@ test "implicit cast fn call result to optional in field result" { |
| 220 | 220 | field: ?*const i32, |
| 221 | 221 | }; |
| 222 | 222 | }; |
| 223 | S.entry(); | |
| 224 | comptime S.entry(); | |
| 223 | try S.entry(); | |
| 224 | comptime try S.entry(); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | test "discard the result of a function that returns a struct" { |
| ... | ... | @@ -245,26 +245,26 @@ test "discard the result of a function that returns a struct" { |
| 245 | 245 | |
| 246 | 246 | test "function call with anon list literal" { |
| 247 | 247 | const S = struct { |
| 248 | fn doTheTest() void { | |
| 249 | consumeVec(.{ 9, 8, 7 }); | |
| 248 | fn doTheTest() !void { | |
| 249 | try consumeVec(.{ 9, 8, 7 }); | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | fn consumeVec(vec: [3]f32) void { | |
| 253 | expect(vec[0] == 9); | |
| 254 | expect(vec[1] == 8); | |
| 255 | expect(vec[2] == 7); | |
| 252 | fn consumeVec(vec: [3]f32) !void { | |
| 253 | try expect(vec[0] == 9); | |
| 254 | try expect(vec[1] == 8); | |
| 255 | try expect(vec[2] == 7); | |
| 256 | 256 | } |
| 257 | 257 | }; |
| 258 | S.doTheTest(); | |
| 259 | comptime S.doTheTest(); | |
| 258 | try S.doTheTest(); | |
| 259 | comptime try S.doTheTest(); | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | test "ability to give comptime types and non comptime types to same parameter" { |
| 263 | 263 | const S = struct { |
| 264 | fn doTheTest() void { | |
| 264 | fn doTheTest() !void { | |
| 265 | 265 | var x: i32 = 1; |
| 266 | expect(foo(x) == 10); | |
| 267 | expect(foo(i32) == 20); | |
| 266 | try expect(foo(x) == 10); | |
| 267 | try expect(foo(i32) == 20); | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | fn foo(arg: anytype) i32 { |
| ... | ... | @@ -272,8 +272,8 @@ test "ability to give comptime types and non comptime types to same parameter" { |
| 272 | 272 | return 9 + arg; |
| 273 | 273 | } |
| 274 | 274 | }; |
| 275 | S.doTheTest(); | |
| 276 | comptime S.doTheTest(); | |
| 275 | try S.doTheTest(); | |
| 276 | comptime try S.doTheTest(); | |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | test "function with inferred error set but returning no error" { |
| ... | ... | @@ -282,5 +282,5 @@ test "function with inferred error set but returning no error" { |
| 282 | 282 | }; |
| 283 | 283 | |
| 284 | 284 | const return_ty = @typeInfo(@TypeOf(S.foo)).Fn.return_type.?; |
| 285 | expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len); | |
| 285 | try expectEqual(0, @typeInfo(@typeInfo(return_ty).ErrorUnion.error_set).ErrorSet.?.len); | |
| 286 | 286 | } |
test/stage1/behavior/fn_delegation.zig+4-4| ... | ... | @@ -32,8 +32,8 @@ fn custom(comptime T: type, comptime num: u64) fn (T) u64 { |
| 32 | 32 | |
| 33 | 33 | test "fn delegation" { |
| 34 | 34 | const foo = Foo{}; |
| 35 | expect(foo.one() == 11); | |
| 36 | expect(foo.two() == 12); | |
| 37 | expect(foo.three() == 13); | |
| 38 | expect(foo.four() == 14); | |
| 35 | try expect(foo.one() == 11); | |
| 36 | try expect(foo.two() == 12); | |
| 37 | try expect(foo.three() == 13); | |
| 38 | try expect(foo.four() == 14); | |
| 39 | 39 | } |
test/stage1/behavior/fn_in_struct_in_comptime.zig+1-1| ... | ... | @@ -13,5 +13,5 @@ fn get_foo() fn (*u8) usize { |
| 13 | 13 | |
| 14 | 14 | test "define a function in an anonymous struct in comptime" { |
| 15 | 15 | const foo = get_foo(); |
| 16 | expect(foo(@intToPtr(*u8, 12345)) == 12345); | |
| 16 | try expect(foo(@intToPtr(*u8, 12345)) == 12345); | |
| 17 | 17 | } |
test/stage1/behavior/for.zig+28-28| ... | ... | @@ -27,12 +27,12 @@ test "for loop with pointer elem var" { |
| 27 | 27 | var target: [source.len]u8 = undefined; |
| 28 | 28 | mem.copy(u8, target[0..], source); |
| 29 | 29 | mangleString(target[0..]); |
| 30 | expect(mem.eql(u8, &target, "bcdefgh")); | |
| 30 | try expect(mem.eql(u8, &target, "bcdefgh")); | |
| 31 | 31 | |
| 32 | 32 | for (source) |*c, i| |
| 33 | expect(@TypeOf(c) == *const u8); | |
| 33 | try expect(@TypeOf(c) == *const u8); | |
| 34 | 34 | for (target) |*c, i| |
| 35 | expect(@TypeOf(c) == *u8); | |
| 35 | try expect(@TypeOf(c) == *u8); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | fn mangleString(s: []u8) void { |
| ... | ... | @@ -75,15 +75,15 @@ test "basic for loop" { |
| 75 | 75 | buf_index += 1; |
| 76 | 76 | } |
| 77 | 77 | |
| 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 | } |
| 80 | 80 | |
| 81 | 81 | test "break from outer for loop" { |
| 82 | testBreakOuter(); | |
| 83 | comptime testBreakOuter(); | |
| 82 | try testBreakOuter(); | |
| 83 | comptime try testBreakOuter(); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | fn testBreakOuter() void { | |
| 86 | fn testBreakOuter() !void { | |
| 87 | 87 | var array = "aoeu"; |
| 88 | 88 | var count: usize = 0; |
| 89 | 89 | outer: for (array) |_| { |
| ... | ... | @@ -92,15 +92,15 @@ fn testBreakOuter() void { |
| 92 | 92 | break :outer; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | expect(count == 1); | |
| 95 | try expect(count == 1); | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | test "continue outer for loop" { |
| 99 | testContinueOuter(); | |
| 100 | comptime testContinueOuter(); | |
| 99 | try testContinueOuter(); | |
| 100 | comptime try testContinueOuter(); | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | fn testContinueOuter() void { | |
| 103 | fn testContinueOuter() !void { | |
| 104 | 104 | var array = "aoeu"; |
| 105 | 105 | var counter: usize = 0; |
| 106 | 106 | outer: for (array) |_| { |
| ... | ... | @@ -109,28 +109,28 @@ fn testContinueOuter() void { |
| 109 | 109 | continue :outer; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | expect(counter == array.len); | |
| 112 | try expect(counter == array.len); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "2 break statements and an else" { |
| 116 | 116 | const S = struct { |
| 117 | fn entry(t: bool, f: bool) void { | |
| 117 | fn entry(t: bool, f: bool) !void { | |
| 118 | 118 | var buf: [10]u8 = undefined; |
| 119 | 119 | var ok = false; |
| 120 | 120 | ok = for (buf) |item| { |
| 121 | 121 | if (f) break false; |
| 122 | 122 | if (t) break true; |
| 123 | 123 | } else false; |
| 124 | expect(ok); | |
| 124 | try expect(ok); | |
| 125 | 125 | } |
| 126 | 126 | }; |
| 127 | S.entry(true, false); | |
| 128 | comptime S.entry(true, false); | |
| 127 | try S.entry(true, false); | |
| 128 | comptime try S.entry(true, false); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | test "for with null and T peer types and inferred result location type" { |
| 132 | 132 | const S = struct { |
| 133 | fn doTheTest(slice: []const u8) void { | |
| 133 | fn doTheTest(slice: []const u8) !void { | |
| 134 | 134 | if (for (slice) |item| { |
| 135 | 135 | if (item == 10) { |
| 136 | 136 | break item; |
| ... | ... | @@ -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 }); | |
| 144 | comptime S.doTheTest(&[_]u8{ 1, 2 }); | |
| 143 | try S.doTheTest(&[_]u8{ 1, 2 }); | |
| 144 | comptime try S.doTheTest(&[_]u8{ 1, 2 }); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | test "for copies its payload" { |
| 148 | 148 | const S = struct { |
| 149 | fn doTheTest() void { | |
| 149 | fn doTheTest() !void { | |
| 150 | 150 | var x = [_]usize{ 1, 2, 3 }; |
| 151 | 151 | for (x) |value, i| { |
| 152 | 152 | // Modify the original array |
| 153 | 153 | x[i] += 99; |
| 154 | expectEqual(value, i + 1); | |
| 154 | try expectEqual(value, i + 1); | |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | }; |
| 158 | S.doTheTest(); | |
| 159 | comptime S.doTheTest(); | |
| 158 | try S.doTheTest(); | |
| 159 | comptime try S.doTheTest(); | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | test "for on slice with allowzero ptr" { |
| 163 | 163 | const S = struct { |
| 164 | fn doTheTest(slice: []const u8) void { | |
| 164 | fn doTheTest(slice: []const u8) !void { | |
| 165 | 165 | var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len]; |
| 166 | for (ptr) |x, i| expect(x == i + 1); | |
| 167 | for (ptr) |*x, i| expect(x.* == i + 1); | |
| 166 | for (ptr) |x, i| try expect(x == i + 1); | |
| 167 | for (ptr) |*x, i| try expect(x.* == i + 1); | |
| 168 | 168 | } |
| 169 | 169 | }; |
| 170 | S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 171 | comptime S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 170 | try S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 171 | comptime try S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | |
| 172 | 172 | } |
test/stage1/behavior/generics.zig+25-25| ... | ... | @@ -4,9 +4,9 @@ const expect = testing.expect; |
| 4 | 4 | const expectEqual = testing.expectEqual; |
| 5 | 5 | |
| 6 | 6 | test "simple generic fn" { |
| 7 | expect(max(i32, 3, -1) == 3); | |
| 8 | expect(max(f32, 0.123, 0.456) == 0.456); | |
| 9 | expect(add(2, 3) == 5); | |
| 7 | try expect(max(i32, 3, -1) == 3); | |
| 8 | try expect(max(f32, 0.123, 0.456) == 0.456); | |
| 9 | try expect(add(2, 3) == 5); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn max(comptime T: type, a: T, b: T) T { |
| ... | ... | @@ -19,7 +19,7 @@ fn add(comptime a: i32, b: i32) i32 { |
| 19 | 19 | |
| 20 | 20 | const the_max = max(u32, 1234, 5678); |
| 21 | 21 | test "compile time generic eval" { |
| 22 | expect(the_max == 5678); | |
| 22 | try expect(the_max == 5678); | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | fn gimmeTheBigOne(a: u32, b: u32) u32 { |
| ... | ... | @@ -35,19 +35,19 @@ fn sameButWithFloats(a: f64, b: f64) f64 { |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test "fn with comptime args" { |
| 38 | expect(gimmeTheBigOne(1234, 5678) == 5678); | |
| 39 | expect(shouldCallSameInstance(34, 12) == 34); | |
| 40 | expect(sameButWithFloats(0.43, 0.49) == 0.49); | |
| 38 | try expect(gimmeTheBigOne(1234, 5678) == 5678); | |
| 39 | try expect(shouldCallSameInstance(34, 12) == 34); | |
| 40 | try expect(sameButWithFloats(0.43, 0.49) == 0.49); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | test "var params" { |
| 44 | expect(max_i32(12, 34) == 34); | |
| 45 | expect(max_f64(1.2, 3.4) == 3.4); | |
| 44 | try expect(max_i32(12, 34) == 34); | |
| 45 | try expect(max_f64(1.2, 3.4) == 3.4); | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | comptime { |
| 49 | expect(max_i32(12, 34) == 34); | |
| 50 | expect(max_f64(1.2, 3.4) == 3.4); | |
| 49 | try expect(max_i32(12, 34) == 34); | |
| 50 | try expect(max_f64(1.2, 3.4) == 3.4); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | fn max_var(a: anytype, b: anytype) @TypeOf(a + b) { |
| ... | ... | @@ -79,8 +79,8 @@ test "function with return type type" { |
| 79 | 79 | var list2: List(i32) = undefined; |
| 80 | 80 | list.length = 10; |
| 81 | 81 | list2.length = 10; |
| 82 | expect(list.prealloc_items.len == 8); | |
| 83 | expect(list2.prealloc_items.len == 8); | |
| 82 | try expect(list.prealloc_items.len == 8); | |
| 83 | try expect(list2.prealloc_items.len == 8); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "generic struct" { |
| ... | ... | @@ -92,9 +92,9 @@ test "generic struct" { |
| 92 | 92 | .value = true, |
| 93 | 93 | .next = null, |
| 94 | 94 | }; |
| 95 | expect(a1.value == 13); | |
| 96 | expect(a1.value == a1.getVal()); | |
| 97 | expect(b1.getVal()); | |
| 95 | try expect(a1.value == 13); | |
| 96 | try expect(a1.value == a1.getVal()); | |
| 97 | try expect(b1.getVal()); | |
| 98 | 98 | } |
| 99 | 99 | fn GenNode(comptime T: type) type { |
| 100 | 100 | return struct { |
| ... | ... | @@ -107,7 +107,7 @@ fn GenNode(comptime T: type) type { |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "const decls in struct" { |
| 110 | expect(GenericDataThing(3).count_plus_one == 4); | |
| 110 | try expect(GenericDataThing(3).count_plus_one == 4); | |
| 111 | 111 | } |
| 112 | 112 | fn GenericDataThing(comptime count: isize) type { |
| 113 | 113 | return struct { |
| ... | ... | @@ -116,15 +116,15 @@ fn GenericDataThing(comptime count: isize) type { |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | test "use generic param in generic param" { |
| 119 | expect(aGenericFn(i32, 3, 4) == 7); | |
| 119 | try expect(aGenericFn(i32, 3, 4) == 7); | |
| 120 | 120 | } |
| 121 | 121 | fn aGenericFn(comptime T: type, comptime a: T, b: T) T { |
| 122 | 122 | return a + b; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "generic fn with implicit cast" { |
| 126 | expect(getFirstByte(u8, &[_]u8{13}) == 13); | |
| 127 | expect(getFirstByte(u16, &[_]u16{ | |
| 126 | try expect(getFirstByte(u8, &[_]u8{13}) == 13); | |
| 127 | try expect(getFirstByte(u16, &[_]u16{ | |
| 128 | 128 | 0, |
| 129 | 129 | 13, |
| 130 | 130 | }) == 0); |
| ... | ... | @@ -149,21 +149,21 @@ fn foo2(arg: anytype) bool { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "array of generic fns" { |
| 152 | expect(foos[0](true)); | |
| 153 | expect(!foos[1](true)); | |
| 152 | try expect(foos[0](true)); | |
| 153 | try expect(!foos[1](true)); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | test "generic fn keeps non-generic parameter types" { |
| 157 | 157 | const A = 128; |
| 158 | 158 | |
| 159 | 159 | const S = struct { |
| 160 | fn f(comptime T: type, s: []T) void { | |
| 161 | expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment); | |
| 160 | fn f(comptime T: type, s: []T) !void { | |
| 161 | try expect(A != @typeInfo(@TypeOf(s)).Pointer.alignment); | |
| 162 | 162 | } |
| 163 | 163 | }; |
| 164 | 164 | |
| 165 | 165 | // The compiler monomorphizes `S.f` for `T=u8` on its first use, check that |
| 166 | 166 | // `x` type not affect `s` parameter type. |
| 167 | 167 | var x: [16]u8 align(A) = undefined; |
| 168 | S.f(u8, &x); | |
| 168 | try S.f(u8, &x); | |
| 169 | 169 | } |
test/stage1/behavior/hasdecl.zig+6-6| ... | ... | @@ -11,11 +11,11 @@ const Bar = struct { |
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | 13 | test "@hasDecl" { |
| 14 | expect(@hasDecl(Foo, "public_thing")); | |
| 15 | expect(!@hasDecl(Foo, "private_thing")); | |
| 16 | expect(!@hasDecl(Foo, "no_thing")); | |
| 14 | try expect(@hasDecl(Foo, "public_thing")); | |
| 15 | try expect(!@hasDecl(Foo, "private_thing")); | |
| 16 | try expect(!@hasDecl(Foo, "no_thing")); | |
| 17 | 17 | |
| 18 | expect(@hasDecl(Bar, "hi")); | |
| 19 | expect(@hasDecl(Bar, "blah")); | |
| 20 | expect(!@hasDecl(Bar, "nope")); | |
| 18 | try expect(@hasDecl(Bar, "hi")); | |
| 19 | try expect(@hasDecl(Bar, "blah")); | |
| 20 | try expect(!@hasDecl(Bar, "nope")); | |
| 21 | 21 | } |
test/stage1/behavior/hasfield.zig+12-12| ... | ... | @@ -8,10 +8,10 @@ test "@hasField" { |
| 8 | 8 | |
| 9 | 9 | pub const nope = 1; |
| 10 | 10 | }; |
| 11 | expect(@hasField(struc, "a") == true); | |
| 12 | expect(@hasField(struc, "b") == true); | |
| 13 | expect(@hasField(struc, "non-existant") == false); | |
| 14 | expect(@hasField(struc, "nope") == false); | |
| 11 | try expect(@hasField(struc, "a") == true); | |
| 12 | try expect(@hasField(struc, "b") == true); | |
| 13 | try expect(@hasField(struc, "non-existant") == false); | |
| 14 | try expect(@hasField(struc, "nope") == false); | |
| 15 | 15 | |
| 16 | 16 | const unin = union { |
| 17 | 17 | a: u64, |
| ... | ... | @@ -19,10 +19,10 @@ test "@hasField" { |
| 19 | 19 | |
| 20 | 20 | pub const nope = 1; |
| 21 | 21 | }; |
| 22 | expect(@hasField(unin, "a") == true); | |
| 23 | expect(@hasField(unin, "b") == true); | |
| 24 | expect(@hasField(unin, "non-existant") == false); | |
| 25 | expect(@hasField(unin, "nope") == false); | |
| 22 | try expect(@hasField(unin, "a") == true); | |
| 23 | try expect(@hasField(unin, "b") == true); | |
| 24 | try expect(@hasField(unin, "non-existant") == false); | |
| 25 | try expect(@hasField(unin, "nope") == false); | |
| 26 | 26 | |
| 27 | 27 | const enm = enum { |
| 28 | 28 | a, |
| ... | ... | @@ -30,8 +30,8 @@ test "@hasField" { |
| 30 | 30 | |
| 31 | 31 | pub const nope = 1; |
| 32 | 32 | }; |
| 33 | expect(@hasField(enm, "a") == true); | |
| 34 | expect(@hasField(enm, "b") == true); | |
| 35 | expect(@hasField(enm, "non-existant") == false); | |
| 36 | expect(@hasField(enm, "nope") == false); | |
| 33 | try expect(@hasField(enm, "a") == true); | |
| 34 | try expect(@hasField(enm, "b") == true); | |
| 35 | try expect(@hasField(enm, "non-existant") == false); | |
| 36 | try expect(@hasField(enm, "nope") == false); | |
| 37 | 37 | } |
test/stage1/behavior/if.zig+14-14| ... | ... | @@ -26,7 +26,7 @@ fn firstEqlThird(a: i32, b: i32, c: i32) void { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "else if expression" { |
| 29 | expect(elseIfExpressionF(1) == 1); | |
| 29 | try expect(elseIfExpressionF(1) == 1); | |
| 30 | 30 | } |
| 31 | 31 | fn elseIfExpressionF(c: u8) u8 { |
| 32 | 32 | if (c == 0) { |
| ... | ... | @@ -44,14 +44,14 @@ var global_with_err: anyerror!u32 = error.SomeError; |
| 44 | 44 | |
| 45 | 45 | test "unwrap mutable global var" { |
| 46 | 46 | if (global_with_val) |v| { |
| 47 | expect(v == 0); | |
| 47 | try expect(v == 0); | |
| 48 | 48 | } else |e| { |
| 49 | 49 | unreachable; |
| 50 | 50 | } |
| 51 | 51 | if (global_with_err) |_| { |
| 52 | 52 | unreachable; |
| 53 | 53 | } else |e| { |
| 54 | expect(e == error.SomeError); | |
| 54 | try expect(e == error.SomeError); | |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| ... | ... | @@ -63,7 +63,7 @@ test "labeled break inside comptime if inside runtime if" { |
| 63 | 63 | break :blk @as(i32, 42); |
| 64 | 64 | }; |
| 65 | 65 | } |
| 66 | expect(answer == 42); | |
| 66 | try expect(answer == 42); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | test "const result loc, runtime if cond, else unreachable" { |
| ... | ... | @@ -74,36 +74,36 @@ test "const result loc, runtime if cond, else unreachable" { |
| 74 | 74 | |
| 75 | 75 | var t = true; |
| 76 | 76 | const x = if (t) Num.Two else unreachable; |
| 77 | expect(x == .Two); | |
| 77 | try expect(x == .Two); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | test "if prongs cast to expected type instead of peer type resolution" { |
| 81 | 81 | const S = struct { |
| 82 | fn doTheTest(f: bool) void { | |
| 82 | fn doTheTest(f: bool) !void { | |
| 83 | 83 | var x: i32 = 0; |
| 84 | 84 | x = if (f) 1 else 2; |
| 85 | expect(x == 2); | |
| 85 | try expect(x == 2); | |
| 86 | 86 | |
| 87 | 87 | var b = true; |
| 88 | 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); | |
| 93 | comptime S.doTheTest(false); | |
| 92 | try S.doTheTest(false); | |
| 93 | comptime try S.doTheTest(false); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "while copies its payload" { |
| 97 | 97 | const S = struct { |
| 98 | fn doTheTest() void { | |
| 98 | fn doTheTest() !void { | |
| 99 | 99 | var tmp: ?i32 = 10; |
| 100 | 100 | if (tmp) |value| { |
| 101 | 101 | // Modify the original variable |
| 102 | 102 | tmp = null; |
| 103 | expectEqual(@as(i32, 10), value); | |
| 103 | try expectEqual(@as(i32, 10), value); | |
| 104 | 104 | } else unreachable; |
| 105 | 105 | } |
| 106 | 106 | }; |
| 107 | S.doTheTest(); | |
| 108 | comptime S.doTheTest(); | |
| 107 | try S.doTheTest(); | |
| 108 | comptime try S.doTheTest(); | |
| 109 | 109 | } |
test/stage1/behavior/import.zig+3-3| ... | ... | @@ -3,18 +3,18 @@ const expectEqual = @import("std").testing.expectEqual; |
| 3 | 3 | const a_namespace = @import("import/a_namespace.zig"); |
| 4 | 4 | |
| 5 | 5 | test "call fn via namespace lookup" { |
| 6 | expectEqual(@as(i32, 1234), a_namespace.foo()); | |
| 6 | try expectEqual(@as(i32, 1234), a_namespace.foo()); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "importing the same thing gives the same import" { |
| 10 | expect(@import("std") == @import("std")); | |
| 10 | try expect(@import("std") == @import("std")); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "import in non-toplevel scope" { |
| 14 | 14 | const S = struct { |
| 15 | 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 | } |
| 19 | 19 | |
| 20 | 20 | test "import empty file" { |
test/stage1/behavior/incomplete_struct_param_tld.zig+1-1| ... | ... | @@ -26,5 +26,5 @@ test "incomplete struct param top level declaration" { |
| 26 | 26 | .c = C{ .x = 13 }, |
| 27 | 27 | }, |
| 28 | 28 | }; |
| 29 | expect(foo(a) == 13); | |
| 29 | try expect(foo(a) == 13); | |
| 30 | 30 | } |
test/stage1/behavior/inttoptr.zig-4| ... | ... | @@ -1,7 +1,3 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const std = @import("std"); | |
| 3 | const expect = std.testing.expect; | |
| 4 | ||
| 5 | 1 | test "casting random address to function pointer" { |
| 6 | 2 | randomAddressToFunction(); |
| 7 | 3 | comptime randomAddressToFunction(); |
test/stage1/behavior/ir_block_deps.zig+2-2| ... | ... | @@ -16,6 +16,6 @@ fn getErrInt() anyerror!i32 { |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "ir block deps" { |
| 19 | expect((foo(1) catch unreachable) == 0); | |
| 20 | expect((foo(2) catch unreachable) == 0); | |
| 19 | try expect((foo(1) catch unreachable) == 0); | |
| 20 | try expect((foo(2) catch unreachable) == 0); | |
| 21 | 21 | } |
test/stage1/behavior/math.zig+357-357| ... | ... | @@ -7,71 +7,71 @@ const minInt = std.math.minInt; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | |
| 9 | 9 | test "division" { |
| 10 | testDivision(); | |
| 11 | comptime testDivision(); | |
| 12 | } | |
| 13 | fn testDivision() void { | |
| 14 | expect(div(u32, 13, 3) == 4); | |
| 15 | expect(div(f16, 1.0, 2.0) == 0.5); | |
| 16 | expect(div(f32, 1.0, 2.0) == 0.5); | |
| 17 | ||
| 18 | expect(divExact(u32, 55, 11) == 5); | |
| 19 | expect(divExact(i32, -55, 11) == -5); | |
| 20 | expect(divExact(f16, 55.0, 11.0) == 5.0); | |
| 21 | expect(divExact(f16, -55.0, 11.0) == -5.0); | |
| 22 | expect(divExact(f32, 55.0, 11.0) == 5.0); | |
| 23 | expect(divExact(f32, -55.0, 11.0) == -5.0); | |
| 24 | ||
| 25 | expect(divFloor(i32, 5, 3) == 1); | |
| 26 | expect(divFloor(i32, -5, 3) == -2); | |
| 27 | expect(divFloor(f16, 5.0, 3.0) == 1.0); | |
| 28 | expect(divFloor(f16, -5.0, 3.0) == -2.0); | |
| 29 | expect(divFloor(f32, 5.0, 3.0) == 1.0); | |
| 30 | expect(divFloor(f32, -5.0, 3.0) == -2.0); | |
| 31 | expect(divFloor(i32, -0x80000000, -2) == 0x40000000); | |
| 32 | expect(divFloor(i32, 0, -0x80000000) == 0); | |
| 33 | expect(divFloor(i32, -0x40000001, 0x40000000) == -2); | |
| 34 | expect(divFloor(i32, -0x80000000, 1) == -0x80000000); | |
| 35 | expect(divFloor(i32, 10, 12) == 0); | |
| 36 | expect(divFloor(i32, -14, 12) == -2); | |
| 37 | expect(divFloor(i32, -2, 12) == -1); | |
| 38 | ||
| 39 | expect(divTrunc(i32, 5, 3) == 1); | |
| 40 | expect(divTrunc(i32, -5, 3) == -1); | |
| 41 | expect(divTrunc(f16, 5.0, 3.0) == 1.0); | |
| 42 | expect(divTrunc(f16, -5.0, 3.0) == -1.0); | |
| 43 | expect(divTrunc(f32, 5.0, 3.0) == 1.0); | |
| 44 | expect(divTrunc(f32, -5.0, 3.0) == -1.0); | |
| 45 | expect(divTrunc(f64, 5.0, 3.0) == 1.0); | |
| 46 | expect(divTrunc(f64, -5.0, 3.0) == -1.0); | |
| 47 | expect(divTrunc(i32, 10, 12) == 0); | |
| 48 | expect(divTrunc(i32, -14, 12) == -1); | |
| 49 | expect(divTrunc(i32, -2, 12) == 0); | |
| 50 | ||
| 51 | expect(mod(i32, 10, 12) == 10); | |
| 52 | expect(mod(i32, -14, 12) == 10); | |
| 53 | expect(mod(i32, -2, 12) == 10); | |
| 10 | try testDivision(); | |
| 11 | comptime try testDivision(); | |
| 12 | } | |
| 13 | fn testDivision() !void { | |
| 14 | try expect(div(u32, 13, 3) == 4); | |
| 15 | try expect(div(f16, 1.0, 2.0) == 0.5); | |
| 16 | try expect(div(f32, 1.0, 2.0) == 0.5); | |
| 17 | ||
| 18 | try expect(divExact(u32, 55, 11) == 5); | |
| 19 | try expect(divExact(i32, -55, 11) == -5); | |
| 20 | try expect(divExact(f16, 55.0, 11.0) == 5.0); | |
| 21 | try expect(divExact(f16, -55.0, 11.0) == -5.0); | |
| 22 | try expect(divExact(f32, 55.0, 11.0) == 5.0); | |
| 23 | try expect(divExact(f32, -55.0, 11.0) == -5.0); | |
| 24 | ||
| 25 | try expect(divFloor(i32, 5, 3) == 1); | |
| 26 | try expect(divFloor(i32, -5, 3) == -2); | |
| 27 | try expect(divFloor(f16, 5.0, 3.0) == 1.0); | |
| 28 | try expect(divFloor(f16, -5.0, 3.0) == -2.0); | |
| 29 | try expect(divFloor(f32, 5.0, 3.0) == 1.0); | |
| 30 | try expect(divFloor(f32, -5.0, 3.0) == -2.0); | |
| 31 | try expect(divFloor(i32, -0x80000000, -2) == 0x40000000); | |
| 32 | try expect(divFloor(i32, 0, -0x80000000) == 0); | |
| 33 | try expect(divFloor(i32, -0x40000001, 0x40000000) == -2); | |
| 34 | try expect(divFloor(i32, -0x80000000, 1) == -0x80000000); | |
| 35 | try expect(divFloor(i32, 10, 12) == 0); | |
| 36 | try expect(divFloor(i32, -14, 12) == -2); | |
| 37 | try expect(divFloor(i32, -2, 12) == -1); | |
| 38 | ||
| 39 | try expect(divTrunc(i32, 5, 3) == 1); | |
| 40 | try expect(divTrunc(i32, -5, 3) == -1); | |
| 41 | try expect(divTrunc(f16, 5.0, 3.0) == 1.0); | |
| 42 | try expect(divTrunc(f16, -5.0, 3.0) == -1.0); | |
| 43 | try expect(divTrunc(f32, 5.0, 3.0) == 1.0); | |
| 44 | try expect(divTrunc(f32, -5.0, 3.0) == -1.0); | |
| 45 | try expect(divTrunc(f64, 5.0, 3.0) == 1.0); | |
| 46 | try expect(divTrunc(f64, -5.0, 3.0) == -1.0); | |
| 47 | try expect(divTrunc(i32, 10, 12) == 0); | |
| 48 | try expect(divTrunc(i32, -14, 12) == -1); | |
| 49 | try expect(divTrunc(i32, -2, 12) == 0); | |
| 50 | ||
| 51 | try expect(mod(i32, 10, 12) == 10); | |
| 52 | try expect(mod(i32, -14, 12) == 10); | |
| 53 | try expect(mod(i32, -2, 12) == 10); | |
| 54 | 54 | |
| 55 | 55 | comptime { |
| 56 | expect( | |
| 56 | try expect( | |
| 57 | 57 | 1194735857077236777412821811143690633098347576 % 508740759824825164163191790951174292733114988 == 177254337427586449086438229241342047632117600, |
| 58 | 58 | ); |
| 59 | expect( | |
| 59 | try expect( | |
| 60 | 60 | @rem(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -177254337427586449086438229241342047632117600, |
| 61 | 61 | ); |
| 62 | expect( | |
| 62 | try expect( | |
| 63 | 63 | 1194735857077236777412821811143690633098347576 / 508740759824825164163191790951174292733114988 == 2, |
| 64 | 64 | ); |
| 65 | expect( | |
| 65 | try expect( | |
| 66 | 66 | @divTrunc(-1194735857077236777412821811143690633098347576, 508740759824825164163191790951174292733114988) == -2, |
| 67 | 67 | ); |
| 68 | expect( | |
| 68 | try expect( | |
| 69 | 69 | @divTrunc(1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == -2, |
| 70 | 70 | ); |
| 71 | expect( | |
| 71 | try expect( | |
| 72 | 72 | @divTrunc(-1194735857077236777412821811143690633098347576, -508740759824825164163191790951174292733114988) == 2, |
| 73 | 73 | ); |
| 74 | expect( | |
| 74 | try expect( | |
| 75 | 75 | 4126227191251978491697987544882340798050766755606969681711 % 10 == 1, |
| 76 | 76 | ); |
| 77 | 77 | } |
| ... | ... | @@ -94,9 +94,9 @@ fn mod(comptime T: type, a: T, b: T) T { |
| 94 | 94 | |
| 95 | 95 | test "@addWithOverflow" { |
| 96 | 96 | var result: u8 = undefined; |
| 97 | expect(@addWithOverflow(u8, 250, 100, &result)); | |
| 98 | expect(!@addWithOverflow(u8, 100, 150, &result)); | |
| 99 | expect(result == 250); | |
| 97 | try expect(@addWithOverflow(u8, 250, 100, &result)); | |
| 98 | try expect(!@addWithOverflow(u8, 100, 150, &result)); | |
| 99 | try expect(result == 250); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // TODO test mulWithOverflow |
| ... | ... | @@ -104,31 +104,31 @@ test "@addWithOverflow" { |
| 104 | 104 | |
| 105 | 105 | test "@shlWithOverflow" { |
| 106 | 106 | var result: u16 = undefined; |
| 107 | expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); | |
| 108 | expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); | |
| 109 | expect(result == 0b1011111111111100); | |
| 107 | try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); | |
| 108 | try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); | |
| 109 | try expect(result == 0b1011111111111100); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "@*WithOverflow with u0 values" { |
| 113 | 113 | var result: u0 = undefined; |
| 114 | expect(!@addWithOverflow(u0, 0, 0, &result)); | |
| 115 | expect(!@subWithOverflow(u0, 0, 0, &result)); | |
| 116 | expect(!@mulWithOverflow(u0, 0, 0, &result)); | |
| 117 | expect(!@shlWithOverflow(u0, 0, 0, &result)); | |
| 114 | try expect(!@addWithOverflow(u0, 0, 0, &result)); | |
| 115 | try expect(!@subWithOverflow(u0, 0, 0, &result)); | |
| 116 | try expect(!@mulWithOverflow(u0, 0, 0, &result)); | |
| 117 | try expect(!@shlWithOverflow(u0, 0, 0, &result)); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "@clz" { |
| 121 | testClz(); | |
| 122 | comptime testClz(); | |
| 121 | try testClz(); | |
| 122 | comptime try testClz(); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | fn testClz() void { | |
| 126 | expect(clz(u8, 0b10001010) == 0); | |
| 127 | expect(clz(u8, 0b00001010) == 4); | |
| 128 | expect(clz(u8, 0b00011010) == 3); | |
| 129 | expect(clz(u8, 0b00000000) == 8); | |
| 130 | expect(clz(u128, 0xffffffffffffffff) == 64); | |
| 131 | expect(clz(u128, 0x10000000000000000) == 63); | |
| 125 | fn testClz() !void { | |
| 126 | try expect(clz(u8, 0b10001010) == 0); | |
| 127 | try expect(clz(u8, 0b00001010) == 4); | |
| 128 | try expect(clz(u8, 0b00011010) == 3); | |
| 129 | try expect(clz(u8, 0b00000000) == 8); | |
| 130 | try expect(clz(u128, 0xffffffffffffffff) == 64); | |
| 131 | try expect(clz(u128, 0x10000000000000000) == 63); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | fn clz(comptime T: type, x: T) usize { |
| ... | ... | @@ -136,15 +136,15 @@ fn clz(comptime T: type, x: T) usize { |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | test "@ctz" { |
| 139 | testCtz(); | |
| 140 | comptime testCtz(); | |
| 139 | try testCtz(); | |
| 140 | comptime try testCtz(); | |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | fn testCtz() void { | |
| 144 | expect(ctz(u8, 0b10100000) == 5); | |
| 145 | expect(ctz(u8, 0b10001010) == 1); | |
| 146 | expect(ctz(u8, 0b00000000) == 8); | |
| 147 | expect(ctz(u16, 0b00000000) == 16); | |
| 143 | fn testCtz() !void { | |
| 144 | try expect(ctz(u8, 0b10100000) == 5); | |
| 145 | try expect(ctz(u8, 0b10001010) == 1); | |
| 146 | try expect(ctz(u8, 0b00000000) == 8); | |
| 147 | try expect(ctz(u16, 0b00000000) == 16); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | fn ctz(comptime T: type, x: T) usize { |
| ... | ... | @@ -154,109 +154,109 @@ fn ctz(comptime T: type, x: T) usize { |
| 154 | 154 | test "assignment operators" { |
| 155 | 155 | var i: u32 = 0; |
| 156 | 156 | i += 5; |
| 157 | expect(i == 5); | |
| 157 | try expect(i == 5); | |
| 158 | 158 | i -= 2; |
| 159 | expect(i == 3); | |
| 159 | try expect(i == 3); | |
| 160 | 160 | i *= 20; |
| 161 | expect(i == 60); | |
| 161 | try expect(i == 60); | |
| 162 | 162 | i /= 3; |
| 163 | expect(i == 20); | |
| 163 | try expect(i == 20); | |
| 164 | 164 | i %= 11; |
| 165 | expect(i == 9); | |
| 165 | try expect(i == 9); | |
| 166 | 166 | i <<= 1; |
| 167 | expect(i == 18); | |
| 167 | try expect(i == 18); | |
| 168 | 168 | i >>= 2; |
| 169 | expect(i == 4); | |
| 169 | try expect(i == 4); | |
| 170 | 170 | i = 6; |
| 171 | 171 | i &= 5; |
| 172 | expect(i == 4); | |
| 172 | try expect(i == 4); | |
| 173 | 173 | i ^= 6; |
| 174 | expect(i == 2); | |
| 174 | try expect(i == 2); | |
| 175 | 175 | i = 6; |
| 176 | 176 | i |= 3; |
| 177 | expect(i == 7); | |
| 177 | try expect(i == 7); | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | test "three expr in a row" { |
| 181 | testThreeExprInARow(false, true); | |
| 182 | comptime testThreeExprInARow(false, true); | |
| 183 | } | |
| 184 | fn testThreeExprInARow(f: bool, t: bool) void { | |
| 185 | assertFalse(f or f or f); | |
| 186 | assertFalse(t and t and f); | |
| 187 | assertFalse(1 | 2 | 4 != 7); | |
| 188 | assertFalse(3 ^ 6 ^ 8 != 13); | |
| 189 | assertFalse(7 & 14 & 28 != 4); | |
| 190 | assertFalse(9 << 1 << 2 != 9 << 3); | |
| 191 | assertFalse(90 >> 1 >> 2 != 90 >> 3); | |
| 192 | assertFalse(100 - 1 + 1000 != 1099); | |
| 193 | assertFalse(5 * 4 / 2 % 3 != 1); | |
| 194 | assertFalse(@as(i32, @as(i32, 5)) != 5); | |
| 195 | assertFalse(!!false); | |
| 196 | assertFalse(@as(i32, 7) != --(@as(i32, 7))); | |
| 197 | } | |
| 198 | fn assertFalse(b: bool) void { | |
| 199 | expect(!b); | |
| 181 | try testThreeExprInARow(false, true); | |
| 182 | comptime try testThreeExprInARow(false, true); | |
| 183 | } | |
| 184 | fn testThreeExprInARow(f: bool, t: bool) !void { | |
| 185 | try assertFalse(f or f or f); | |
| 186 | try assertFalse(t and t and f); | |
| 187 | try assertFalse(1 | 2 | 4 != 7); | |
| 188 | try assertFalse(3 ^ 6 ^ 8 != 13); | |
| 189 | try assertFalse(7 & 14 & 28 != 4); | |
| 190 | try assertFalse(9 << 1 << 2 != 9 << 3); | |
| 191 | try assertFalse(90 >> 1 >> 2 != 90 >> 3); | |
| 192 | try assertFalse(100 - 1 + 1000 != 1099); | |
| 193 | try assertFalse(5 * 4 / 2 % 3 != 1); | |
| 194 | try assertFalse(@as(i32, @as(i32, 5)) != 5); | |
| 195 | try assertFalse(!!false); | |
| 196 | try assertFalse(@as(i32, 7) != --(@as(i32, 7))); | |
| 197 | } | |
| 198 | fn assertFalse(b: bool) !void { | |
| 199 | try expect(!b); | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | test "const number literal" { |
| 203 | 203 | const one = 1; |
| 204 | 204 | const eleven = ten + one; |
| 205 | 205 | |
| 206 | expect(eleven == 11); | |
| 206 | try expect(eleven == 11); | |
| 207 | 207 | } |
| 208 | 208 | const ten = 10; |
| 209 | 209 | |
| 210 | 210 | test "unsigned wrapping" { |
| 211 | testUnsignedWrappingEval(maxInt(u32)); | |
| 212 | comptime testUnsignedWrappingEval(maxInt(u32)); | |
| 211 | try testUnsignedWrappingEval(maxInt(u32)); | |
| 212 | comptime try testUnsignedWrappingEval(maxInt(u32)); | |
| 213 | 213 | } |
| 214 | fn testUnsignedWrappingEval(x: u32) void { | |
| 214 | fn testUnsignedWrappingEval(x: u32) !void { | |
| 215 | 215 | const zero = x +% 1; |
| 216 | expect(zero == 0); | |
| 216 | try expect(zero == 0); | |
| 217 | 217 | const orig = zero -% 1; |
| 218 | expect(orig == maxInt(u32)); | |
| 218 | try expect(orig == maxInt(u32)); | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | test "signed wrapping" { |
| 222 | testSignedWrappingEval(maxInt(i32)); | |
| 223 | comptime testSignedWrappingEval(maxInt(i32)); | |
| 222 | try testSignedWrappingEval(maxInt(i32)); | |
| 223 | comptime try testSignedWrappingEval(maxInt(i32)); | |
| 224 | 224 | } |
| 225 | fn testSignedWrappingEval(x: i32) void { | |
| 225 | fn testSignedWrappingEval(x: i32) !void { | |
| 226 | 226 | const min_val = x +% 1; |
| 227 | expect(min_val == minInt(i32)); | |
| 227 | try expect(min_val == minInt(i32)); | |
| 228 | 228 | const max_val = min_val -% 1; |
| 229 | expect(max_val == maxInt(i32)); | |
| 229 | try expect(max_val == maxInt(i32)); | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | test "signed negation wrapping" { |
| 233 | testSignedNegationWrappingEval(minInt(i16)); | |
| 234 | comptime testSignedNegationWrappingEval(minInt(i16)); | |
| 233 | try testSignedNegationWrappingEval(minInt(i16)); | |
| 234 | comptime try testSignedNegationWrappingEval(minInt(i16)); | |
| 235 | 235 | } |
| 236 | fn testSignedNegationWrappingEval(x: i16) void { | |
| 237 | expect(x == -32768); | |
| 236 | fn testSignedNegationWrappingEval(x: i16) !void { | |
| 237 | try expect(x == -32768); | |
| 238 | 238 | const neg = -%x; |
| 239 | expect(neg == -32768); | |
| 239 | try expect(neg == -32768); | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | test "unsigned negation wrapping" { |
| 243 | testUnsignedNegationWrappingEval(1); | |
| 244 | comptime testUnsignedNegationWrappingEval(1); | |
| 243 | try testUnsignedNegationWrappingEval(1); | |
| 244 | comptime try testUnsignedNegationWrappingEval(1); | |
| 245 | 245 | } |
| 246 | fn testUnsignedNegationWrappingEval(x: u16) void { | |
| 247 | expect(x == 1); | |
| 246 | fn testUnsignedNegationWrappingEval(x: u16) !void { | |
| 247 | try expect(x == 1); | |
| 248 | 248 | const neg = -%x; |
| 249 | expect(neg == maxInt(u16)); | |
| 249 | try expect(neg == maxInt(u16)); | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | test "unsigned 64-bit division" { |
| 253 | test_u64_div(); | |
| 254 | comptime test_u64_div(); | |
| 253 | try test_u64_div(); | |
| 254 | comptime try test_u64_div(); | |
| 255 | 255 | } |
| 256 | fn test_u64_div() void { | |
| 256 | fn test_u64_div() !void { | |
| 257 | 257 | const result = divWithResult(1152921504606846976, 34359738365); |
| 258 | expect(result.quotient == 33554432); | |
| 259 | expect(result.remainder == 100663296); | |
| 258 | try expect(result.quotient == 33554432); | |
| 259 | try expect(result.remainder == 100663296); | |
| 260 | 260 | } |
| 261 | 261 | fn divWithResult(a: u64, b: u64) DivResult { |
| 262 | 262 | return DivResult{ |
| ... | ... | @@ -270,62 +270,62 @@ const DivResult = struct { |
| 270 | 270 | }; |
| 271 | 271 | |
| 272 | 272 | test "binary not" { |
| 273 | expect(comptime x: { | |
| 273 | try expect(comptime x: { | |
| 274 | 274 | break :x ~@as(u16, 0b1010101010101010) == 0b0101010101010101; |
| 275 | 275 | }); |
| 276 | expect(comptime x: { | |
| 276 | try expect(comptime x: { | |
| 277 | 277 | break :x ~@as(u64, 2147483647) == 18446744071562067968; |
| 278 | 278 | }); |
| 279 | testBinaryNot(0b1010101010101010); | |
| 279 | try testBinaryNot(0b1010101010101010); | |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | fn testBinaryNot(x: u16) void { | |
| 283 | expect(~x == 0b0101010101010101); | |
| 282 | fn testBinaryNot(x: u16) !void { | |
| 283 | try expect(~x == 0b0101010101010101); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | test "small int addition" { |
| 287 | 287 | var x: u2 = 0; |
| 288 | expect(x == 0); | |
| 288 | try expect(x == 0); | |
| 289 | 289 | |
| 290 | 290 | x += 1; |
| 291 | expect(x == 1); | |
| 291 | try expect(x == 1); | |
| 292 | 292 | |
| 293 | 293 | x += 1; |
| 294 | expect(x == 2); | |
| 294 | try expect(x == 2); | |
| 295 | 295 | |
| 296 | 296 | x += 1; |
| 297 | expect(x == 3); | |
| 297 | try expect(x == 3); | |
| 298 | 298 | |
| 299 | 299 | var result: @TypeOf(x) = 3; |
| 300 | expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); | |
| 300 | try expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); | |
| 301 | 301 | |
| 302 | expect(result == 0); | |
| 302 | try expect(result == 0); | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | test "float equality" { |
| 306 | 306 | const x: f64 = 0.012; |
| 307 | 307 | const y: f64 = x + 1.0; |
| 308 | 308 | |
| 309 | testFloatEqualityImpl(x, y); | |
| 310 | comptime testFloatEqualityImpl(x, y); | |
| 309 | try testFloatEqualityImpl(x, y); | |
| 310 | comptime try testFloatEqualityImpl(x, y); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | fn testFloatEqualityImpl(x: f64, y: f64) void { | |
| 313 | fn testFloatEqualityImpl(x: f64, y: f64) !void { | |
| 314 | 314 | const y2 = x + 1.0; |
| 315 | expect(y == y2); | |
| 315 | try expect(y == y2); | |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | test "allow signed integer division/remainder when values are comptime known and positive or exact" { |
| 319 | expect(5 / 3 == 1); | |
| 320 | expect(-5 / -3 == 1); | |
| 321 | expect(-6 / 3 == -2); | |
| 319 | try expect(5 / 3 == 1); | |
| 320 | try expect(-5 / -3 == 1); | |
| 321 | try expect(-6 / 3 == -2); | |
| 322 | 322 | |
| 323 | expect(5 % 3 == 2); | |
| 324 | expect(-6 % 3 == 0); | |
| 323 | try expect(5 % 3 == 2); | |
| 324 | try expect(-6 % 3 == 0); | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | test "hex float literal parsing" { |
| 328 | comptime expect(0x1.0 == 1.0); | |
| 328 | comptime try expect(0x1.0 == 1.0); | |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | test "quad hex float literal parsing in range" { |
| ... | ... | @@ -340,29 +340,29 @@ test "quad hex float literal parsing accurate" { |
| 340 | 340 | |
| 341 | 341 | // implied 1 is dropped, with an exponent of 0 (0x3fff) after biasing. |
| 342 | 342 | const expected: u128 = 0x3fff1111222233334444555566667777; |
| 343 | expect(@bitCast(u128, a) == expected); | |
| 343 | try expect(@bitCast(u128, a) == expected); | |
| 344 | 344 | |
| 345 | 345 | // non-normalized |
| 346 | 346 | const b: f128 = 0x11.111222233334444555566667777p-4; |
| 347 | expect(@bitCast(u128, b) == expected); | |
| 347 | try expect(@bitCast(u128, b) == expected); | |
| 348 | 348 | |
| 349 | 349 | const S = struct { |
| 350 | fn doTheTest() void { | |
| 350 | fn doTheTest() !void { | |
| 351 | 351 | { |
| 352 | 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 | 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 | 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 | 364 | var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9; |
| 365 | expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568); | |
| 365 | try expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568); | |
| 366 | 366 | } |
| 367 | 367 | const exp2ft = [_]f64{ |
| 368 | 368 | 0x1.6a09e667f3bcdp-1, |
| ... | ... | @@ -417,40 +417,40 @@ test "quad hex float literal parsing accurate" { |
| 417 | 417 | }; |
| 418 | 418 | |
| 419 | 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(); | |
| 425 | comptime S.doTheTest(); | |
| 424 | try S.doTheTest(); | |
| 425 | comptime try S.doTheTest(); | |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | test "underscore separator parsing" { |
| 429 | expect(0_0_0_0 == 0); | |
| 430 | expect(1_234_567 == 1234567); | |
| 431 | expect(001_234_567 == 1234567); | |
| 432 | expect(0_0_1_2_3_4_5_6_7 == 1234567); | |
| 429 | try expect(0_0_0_0 == 0); | |
| 430 | try expect(1_234_567 == 1234567); | |
| 431 | try expect(001_234_567 == 1234567); | |
| 432 | try expect(0_0_1_2_3_4_5_6_7 == 1234567); | |
| 433 | 433 | |
| 434 | expect(0b0_0_0_0 == 0); | |
| 435 | expect(0b1010_1010 == 0b10101010); | |
| 436 | expect(0b0000_1010_1010 == 0b10101010); | |
| 437 | expect(0b1_0_1_0_1_0_1_0 == 0b10101010); | |
| 434 | try expect(0b0_0_0_0 == 0); | |
| 435 | try expect(0b1010_1010 == 0b10101010); | |
| 436 | try expect(0b0000_1010_1010 == 0b10101010); | |
| 437 | try expect(0b1_0_1_0_1_0_1_0 == 0b10101010); | |
| 438 | 438 | |
| 439 | expect(0o0_0_0_0 == 0); | |
| 440 | expect(0o1010_1010 == 0o10101010); | |
| 441 | expect(0o0000_1010_1010 == 0o10101010); | |
| 442 | expect(0o1_0_1_0_1_0_1_0 == 0o10101010); | |
| 439 | try expect(0o0_0_0_0 == 0); | |
| 440 | try expect(0o1010_1010 == 0o10101010); | |
| 441 | try expect(0o0000_1010_1010 == 0o10101010); | |
| 442 | try expect(0o1_0_1_0_1_0_1_0 == 0o10101010); | |
| 443 | 443 | |
| 444 | expect(0x0_0_0_0 == 0); | |
| 445 | expect(0x1010_1010 == 0x10101010); | |
| 446 | expect(0x0000_1010_1010 == 0x10101010); | |
| 447 | expect(0x1_0_1_0_1_0_1_0 == 0x10101010); | |
| 444 | try expect(0x0_0_0_0 == 0); | |
| 445 | try expect(0x1010_1010 == 0x10101010); | |
| 446 | try expect(0x0000_1010_1010 == 0x10101010); | |
| 447 | try expect(0x1_0_1_0_1_0_1_0 == 0x10101010); | |
| 448 | 448 | |
| 449 | expect(123_456.789_000e1_0 == 123456.789000e10); | |
| 450 | expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10); | |
| 449 | try expect(123_456.789_000e1_0 == 123456.789000e10); | |
| 450 | try expect(0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0 == 123456.789000e10); | |
| 451 | 451 | |
| 452 | expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10); | |
| 453 | expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10); | |
| 452 | try expect(0x1234_5678.9ABC_DEF0p-1_0 == 0x12345678.9ABCDEF0p-10); | |
| 453 | try expect(0x1_2_3_4_5_6_7_8.9_A_B_C_D_E_F_0p-0_0_0_1_0 == 0x12345678.9ABCDEF0p-10); | |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | test "hex float literal within range" { |
| ... | ... | @@ -460,73 +460,73 @@ test "hex float literal within range" { |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | test "truncating shift left" { |
| 463 | testShlTrunc(maxInt(u16)); | |
| 464 | comptime testShlTrunc(maxInt(u16)); | |
| 463 | try testShlTrunc(maxInt(u16)); | |
| 464 | comptime try testShlTrunc(maxInt(u16)); | |
| 465 | 465 | } |
| 466 | fn testShlTrunc(x: u16) void { | |
| 466 | fn testShlTrunc(x: u16) !void { | |
| 467 | 467 | const shifted = x << 1; |
| 468 | expect(shifted == 65534); | |
| 468 | try expect(shifted == 65534); | |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | test "truncating shift right" { |
| 472 | testShrTrunc(maxInt(u16)); | |
| 473 | comptime testShrTrunc(maxInt(u16)); | |
| 472 | try testShrTrunc(maxInt(u16)); | |
| 473 | comptime try testShrTrunc(maxInt(u16)); | |
| 474 | 474 | } |
| 475 | fn testShrTrunc(x: u16) void { | |
| 475 | fn testShrTrunc(x: u16) !void { | |
| 476 | 476 | const shifted = x >> 1; |
| 477 | expect(shifted == 32767); | |
| 477 | try expect(shifted == 32767); | |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | test "exact shift left" { |
| 481 | testShlExact(0b00110101); | |
| 482 | comptime testShlExact(0b00110101); | |
| 481 | try testShlExact(0b00110101); | |
| 482 | comptime try testShlExact(0b00110101); | |
| 483 | 483 | } |
| 484 | fn testShlExact(x: u8) void { | |
| 484 | fn testShlExact(x: u8) !void { | |
| 485 | 485 | const shifted = @shlExact(x, 2); |
| 486 | expect(shifted == 0b11010100); | |
| 486 | try expect(shifted == 0b11010100); | |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | test "exact shift right" { |
| 490 | testShrExact(0b10110100); | |
| 491 | comptime testShrExact(0b10110100); | |
| 490 | try testShrExact(0b10110100); | |
| 491 | comptime try testShrExact(0b10110100); | |
| 492 | 492 | } |
| 493 | fn testShrExact(x: u8) void { | |
| 493 | fn testShrExact(x: u8) !void { | |
| 494 | 494 | const shifted = @shrExact(x, 2); |
| 495 | expect(shifted == 0b00101101); | |
| 495 | try expect(shifted == 0b00101101); | |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | test "shift left/right on u0 operand" { |
| 499 | 499 | const S = struct { |
| 500 | fn doTheTest() void { | |
| 500 | fn doTheTest() !void { | |
| 501 | 501 | var x: u0 = 0; |
| 502 | 502 | var y: u0 = 0; |
| 503 | expectEqual(@as(u0, 0), x << 0); | |
| 504 | expectEqual(@as(u0, 0), x >> 0); | |
| 505 | expectEqual(@as(u0, 0), x << y); | |
| 506 | expectEqual(@as(u0, 0), x >> y); | |
| 507 | expectEqual(@as(u0, 0), @shlExact(x, 0)); | |
| 508 | expectEqual(@as(u0, 0), @shrExact(x, 0)); | |
| 509 | expectEqual(@as(u0, 0), @shlExact(x, y)); | |
| 510 | expectEqual(@as(u0, 0), @shrExact(x, y)); | |
| 503 | try expectEqual(@as(u0, 0), x << 0); | |
| 504 | try expectEqual(@as(u0, 0), x >> 0); | |
| 505 | try expectEqual(@as(u0, 0), x << y); | |
| 506 | try expectEqual(@as(u0, 0), x >> y); | |
| 507 | try expectEqual(@as(u0, 0), @shlExact(x, 0)); | |
| 508 | try expectEqual(@as(u0, 0), @shrExact(x, 0)); | |
| 509 | try expectEqual(@as(u0, 0), @shlExact(x, y)); | |
| 510 | try expectEqual(@as(u0, 0), @shrExact(x, y)); | |
| 511 | 511 | } |
| 512 | 512 | }; |
| 513 | S.doTheTest(); | |
| 514 | comptime S.doTheTest(); | |
| 513 | try S.doTheTest(); | |
| 514 | comptime try S.doTheTest(); | |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | test "comptime_int addition" { |
| 518 | 518 | comptime { |
| 519 | expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950); | |
| 520 | expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380); | |
| 519 | try expect(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950); | |
| 520 | try expect(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380); | |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | test "comptime_int multiplication" { |
| 525 | 525 | comptime { |
| 526 | expect( | |
| 526 | try expect( | |
| 527 | 527 | 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567, |
| 528 | 528 | ); |
| 529 | expect( | |
| 529 | try expect( | |
| 530 | 530 | 594491908217841670578297176641415611445982232488944558774612 * 390603545391089362063884922208143568023166603618446395589768 == 232210647056203049913662402532976186578842425262306016094292237500303028346593132411865381225871291702600263463125370016, |
| 531 | 531 | ); |
| 532 | 532 | } |
| ... | ... | @@ -534,7 +534,7 @@ test "comptime_int multiplication" { |
| 534 | 534 | |
| 535 | 535 | test "comptime_int shifting" { |
| 536 | 536 | comptime { |
| 537 | expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000); | |
| 537 | try expect((@as(u128, 1) << 127) == 0x80000000000000000000000000000000); | |
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | |
| ... | ... | @@ -542,16 +542,16 @@ test "comptime_int multi-limb shift and mask" { |
| 542 | 542 | comptime { |
| 543 | 543 | var a = 0xefffffffa0000001eeeeeeefaaaaaaab; |
| 544 | 544 | |
| 545 | expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab); | |
| 545 | try expect(@as(u32, a & 0xffffffff) == 0xaaaaaaab); | |
| 546 | 546 | a >>= 32; |
| 547 | expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef); | |
| 547 | try expect(@as(u32, a & 0xffffffff) == 0xeeeeeeef); | |
| 548 | 548 | a >>= 32; |
| 549 | expect(@as(u32, a & 0xffffffff) == 0xa0000001); | |
| 549 | try expect(@as(u32, a & 0xffffffff) == 0xa0000001); | |
| 550 | 550 | a >>= 32; |
| 551 | expect(@as(u32, a & 0xffffffff) == 0xefffffff); | |
| 551 | try expect(@as(u32, a & 0xffffffff) == 0xefffffff); | |
| 552 | 552 | a >>= 32; |
| 553 | 553 | |
| 554 | expect(a == 0); | |
| 554 | try expect(a == 0); | |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| ... | ... | @@ -559,227 +559,227 @@ test "comptime_int multi-limb partial shift right" { |
| 559 | 559 | comptime { |
| 560 | 560 | var a = 0x1ffffffffeeeeeeee; |
| 561 | 561 | a >>= 16; |
| 562 | expect(a == 0x1ffffffffeeee); | |
| 562 | try expect(a == 0x1ffffffffeeee); | |
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | test "xor" { |
| 567 | test_xor(); | |
| 568 | comptime test_xor(); | |
| 567 | try test_xor(); | |
| 568 | comptime try test_xor(); | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | fn test_xor() void { | |
| 572 | expect(0xFF ^ 0x00 == 0xFF); | |
| 573 | expect(0xF0 ^ 0x0F == 0xFF); | |
| 574 | expect(0xFF ^ 0xF0 == 0x0F); | |
| 575 | expect(0xFF ^ 0x0F == 0xF0); | |
| 576 | expect(0xFF ^ 0xFF == 0x00); | |
| 571 | fn test_xor() !void { | |
| 572 | try expect(0xFF ^ 0x00 == 0xFF); | |
| 573 | try expect(0xF0 ^ 0x0F == 0xFF); | |
| 574 | try expect(0xFF ^ 0xF0 == 0x0F); | |
| 575 | try expect(0xFF ^ 0x0F == 0xF0); | |
| 576 | try expect(0xFF ^ 0xFF == 0x00); | |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | test "comptime_int xor" { |
| 580 | 580 | comptime { |
| 581 | expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 582 | expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 583 | expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF); | |
| 584 | expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000); | |
| 585 | expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000); | |
| 586 | expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 587 | expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF); | |
| 588 | expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000); | |
| 581 | try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 582 | try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 583 | try expect(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x0000000000000000FFFFFFFFFFFFFFFF); | |
| 584 | try expect(0x0000000000000000FFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF0000000000000000); | |
| 585 | try expect(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000000000000000000000000000); | |
| 586 | try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0x00000000FFFFFFFF00000000FFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); | |
| 587 | try expect(0xFFFFFFFF00000000FFFFFFFF00000000 ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0x00000000FFFFFFFF00000000FFFFFFFF); | |
| 588 | try expect(0x00000000FFFFFFFF00000000FFFFFFFF ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF == 0xFFFFFFFF00000000FFFFFFFF00000000); | |
| 589 | 589 | } |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | test "f128" { |
| 593 | test_f128(); | |
| 594 | comptime test_f128(); | |
| 593 | try test_f128(); | |
| 594 | comptime try test_f128(); | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | fn make_f128(x: f128) f128 { |
| 598 | 598 | return x; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | fn test_f128() void { | |
| 602 | expect(@sizeOf(f128) == 16); | |
| 603 | expect(make_f128(1.0) == 1.0); | |
| 604 | expect(make_f128(1.0) != 1.1); | |
| 605 | expect(make_f128(1.0) > 0.9); | |
| 606 | expect(make_f128(1.0) >= 0.9); | |
| 607 | expect(make_f128(1.0) >= 1.0); | |
| 608 | should_not_be_zero(1.0); | |
| 601 | fn test_f128() !void { | |
| 602 | try expect(@sizeOf(f128) == 16); | |
| 603 | try expect(make_f128(1.0) == 1.0); | |
| 604 | try expect(make_f128(1.0) != 1.1); | |
| 605 | try expect(make_f128(1.0) > 0.9); | |
| 606 | try expect(make_f128(1.0) >= 0.9); | |
| 607 | try expect(make_f128(1.0) >= 1.0); | |
| 608 | try should_not_be_zero(1.0); | |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | fn should_not_be_zero(x: f128) void { | |
| 612 | expect(x != 0.0); | |
| 611 | fn should_not_be_zero(x: f128) !void { | |
| 612 | try expect(x != 0.0); | |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | test "comptime float rem int" { |
| 616 | 616 | comptime { |
| 617 | 617 | var x = @as(f32, 1) % 2; |
| 618 | expect(x == 1.0); | |
| 618 | try expect(x == 1.0); | |
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | test "remainder division" { |
| 623 | comptime remdiv(f16); | |
| 624 | comptime remdiv(f32); | |
| 625 | comptime remdiv(f64); | |
| 626 | comptime remdiv(f128); | |
| 627 | remdiv(f16); | |
| 628 | remdiv(f64); | |
| 629 | remdiv(f128); | |
| 623 | comptime try remdiv(f16); | |
| 624 | comptime try remdiv(f32); | |
| 625 | comptime try remdiv(f64); | |
| 626 | comptime try remdiv(f128); | |
| 627 | try remdiv(f16); | |
| 628 | try remdiv(f64); | |
| 629 | try remdiv(f128); | |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | fn remdiv(comptime T: type) void { | |
| 633 | expect(@as(T, 1) == @as(T, 1) % @as(T, 2)); | |
| 634 | expect(@as(T, 1) == @as(T, 7) % @as(T, 3)); | |
| 632 | fn remdiv(comptime T: type) !void { | |
| 633 | try expect(@as(T, 1) == @as(T, 1) % @as(T, 2)); | |
| 634 | try expect(@as(T, 1) == @as(T, 7) % @as(T, 3)); | |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | test "@sqrt" { |
| 638 | testSqrt(f64, 12.0); | |
| 639 | comptime testSqrt(f64, 12.0); | |
| 640 | testSqrt(f32, 13.0); | |
| 641 | comptime testSqrt(f32, 13.0); | |
| 642 | testSqrt(f16, 13.0); | |
| 643 | comptime testSqrt(f16, 13.0); | |
| 638 | try testSqrt(f64, 12.0); | |
| 639 | comptime try testSqrt(f64, 12.0); | |
| 640 | try testSqrt(f32, 13.0); | |
| 641 | comptime try testSqrt(f32, 13.0); | |
| 642 | try testSqrt(f16, 13.0); | |
| 643 | comptime try testSqrt(f16, 13.0); | |
| 644 | 644 | |
| 645 | 645 | const x = 14.0; |
| 646 | 646 | const y = x * x; |
| 647 | 647 | const z = @sqrt(y); |
| 648 | comptime expect(z == x); | |
| 648 | comptime try expect(z == x); | |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | fn testSqrt(comptime T: type, x: T) void { | |
| 652 | expect(@sqrt(x * x) == x); | |
| 651 | fn testSqrt(comptime T: type, x: T) !void { | |
| 652 | try expect(@sqrt(x * x) == x); | |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | test "@fabs" { |
| 656 | testFabs(f128, 12.0); | |
| 657 | comptime testFabs(f128, 12.0); | |
| 658 | testFabs(f64, 12.0); | |
| 659 | comptime testFabs(f64, 12.0); | |
| 660 | testFabs(f32, 12.0); | |
| 661 | comptime testFabs(f32, 12.0); | |
| 662 | testFabs(f16, 12.0); | |
| 663 | comptime testFabs(f16, 12.0); | |
| 656 | try testFabs(f128, 12.0); | |
| 657 | comptime try testFabs(f128, 12.0); | |
| 658 | try testFabs(f64, 12.0); | |
| 659 | comptime try testFabs(f64, 12.0); | |
| 660 | try testFabs(f32, 12.0); | |
| 661 | comptime try testFabs(f32, 12.0); | |
| 662 | try testFabs(f16, 12.0); | |
| 663 | comptime try testFabs(f16, 12.0); | |
| 664 | 664 | |
| 665 | 665 | const x = 14.0; |
| 666 | 666 | const y = -x; |
| 667 | 667 | const z = @fabs(y); |
| 668 | comptime expectEqual(x, z); | |
| 668 | comptime try expectEqual(x, z); | |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | fn testFabs(comptime T: type, x: T) void { | |
| 671 | fn testFabs(comptime T: type, x: T) !void { | |
| 672 | 672 | const y = -x; |
| 673 | 673 | const z = @fabs(y); |
| 674 | expectEqual(x, z); | |
| 674 | try expectEqual(x, z); | |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | test "@floor" { |
| 678 | 678 | // FIXME: Generates a floorl function call |
| 679 | 679 | // testFloor(f128, 12.0); |
| 680 | comptime testFloor(f128, 12.0); | |
| 681 | testFloor(f64, 12.0); | |
| 682 | comptime testFloor(f64, 12.0); | |
| 683 | testFloor(f32, 12.0); | |
| 684 | comptime testFloor(f32, 12.0); | |
| 685 | testFloor(f16, 12.0); | |
| 686 | comptime testFloor(f16, 12.0); | |
| 680 | comptime try testFloor(f128, 12.0); | |
| 681 | try testFloor(f64, 12.0); | |
| 682 | comptime try testFloor(f64, 12.0); | |
| 683 | try testFloor(f32, 12.0); | |
| 684 | comptime try testFloor(f32, 12.0); | |
| 685 | try testFloor(f16, 12.0); | |
| 686 | comptime try testFloor(f16, 12.0); | |
| 687 | 687 | |
| 688 | 688 | const x = 14.0; |
| 689 | 689 | const y = x + 0.7; |
| 690 | 690 | const z = @floor(y); |
| 691 | comptime expectEqual(x, z); | |
| 691 | comptime try expectEqual(x, z); | |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | fn testFloor(comptime T: type, x: T) void { | |
| 694 | fn testFloor(comptime T: type, x: T) !void { | |
| 695 | 695 | const y = x + 0.6; |
| 696 | 696 | const z = @floor(y); |
| 697 | expectEqual(x, z); | |
| 697 | try expectEqual(x, z); | |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | test "@ceil" { |
| 701 | 701 | // FIXME: Generates a ceill function call |
| 702 | 702 | //testCeil(f128, 12.0); |
| 703 | comptime testCeil(f128, 12.0); | |
| 704 | testCeil(f64, 12.0); | |
| 705 | comptime testCeil(f64, 12.0); | |
| 706 | testCeil(f32, 12.0); | |
| 707 | comptime testCeil(f32, 12.0); | |
| 708 | testCeil(f16, 12.0); | |
| 709 | comptime testCeil(f16, 12.0); | |
| 703 | comptime try testCeil(f128, 12.0); | |
| 704 | try testCeil(f64, 12.0); | |
| 705 | comptime try testCeil(f64, 12.0); | |
| 706 | try testCeil(f32, 12.0); | |
| 707 | comptime try testCeil(f32, 12.0); | |
| 708 | try testCeil(f16, 12.0); | |
| 709 | comptime try testCeil(f16, 12.0); | |
| 710 | 710 | |
| 711 | 711 | const x = 14.0; |
| 712 | 712 | const y = x - 0.7; |
| 713 | 713 | const z = @ceil(y); |
| 714 | comptime expectEqual(x, z); | |
| 714 | comptime try expectEqual(x, z); | |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | fn testCeil(comptime T: type, x: T) void { | |
| 717 | fn testCeil(comptime T: type, x: T) !void { | |
| 718 | 718 | const y = x - 0.8; |
| 719 | 719 | const z = @ceil(y); |
| 720 | expectEqual(x, z); | |
| 720 | try expectEqual(x, z); | |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | test "@trunc" { |
| 724 | 724 | // FIXME: Generates a truncl function call |
| 725 | 725 | //testTrunc(f128, 12.0); |
| 726 | comptime testTrunc(f128, 12.0); | |
| 727 | testTrunc(f64, 12.0); | |
| 728 | comptime testTrunc(f64, 12.0); | |
| 729 | testTrunc(f32, 12.0); | |
| 730 | comptime testTrunc(f32, 12.0); | |
| 731 | testTrunc(f16, 12.0); | |
| 732 | comptime testTrunc(f16, 12.0); | |
| 726 | comptime try testTrunc(f128, 12.0); | |
| 727 | try testTrunc(f64, 12.0); | |
| 728 | comptime try testTrunc(f64, 12.0); | |
| 729 | try testTrunc(f32, 12.0); | |
| 730 | comptime try testTrunc(f32, 12.0); | |
| 731 | try testTrunc(f16, 12.0); | |
| 732 | comptime try testTrunc(f16, 12.0); | |
| 733 | 733 | |
| 734 | 734 | const x = 14.0; |
| 735 | 735 | const y = x + 0.7; |
| 736 | 736 | const z = @trunc(y); |
| 737 | comptime expectEqual(x, z); | |
| 737 | comptime try expectEqual(x, z); | |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | fn testTrunc(comptime T: type, x: T) void { | |
| 740 | fn testTrunc(comptime T: type, x: T) !void { | |
| 741 | 741 | { |
| 742 | 742 | const y = x + 0.8; |
| 743 | 743 | const z = @trunc(y); |
| 744 | expectEqual(x, z); | |
| 744 | try expectEqual(x, z); | |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | { |
| 748 | 748 | const y = -x - 0.8; |
| 749 | 749 | const z = @trunc(y); |
| 750 | expectEqual(-x, z); | |
| 750 | try expectEqual(-x, z); | |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | test "@round" { |
| 755 | 755 | // FIXME: Generates a roundl function call |
| 756 | 756 | //testRound(f128, 12.0); |
| 757 | comptime testRound(f128, 12.0); | |
| 758 | testRound(f64, 12.0); | |
| 759 | comptime testRound(f64, 12.0); | |
| 760 | testRound(f32, 12.0); | |
| 761 | comptime testRound(f32, 12.0); | |
| 762 | testRound(f16, 12.0); | |
| 763 | comptime testRound(f16, 12.0); | |
| 757 | comptime try testRound(f128, 12.0); | |
| 758 | try testRound(f64, 12.0); | |
| 759 | comptime try testRound(f64, 12.0); | |
| 760 | try testRound(f32, 12.0); | |
| 761 | comptime try testRound(f32, 12.0); | |
| 762 | try testRound(f16, 12.0); | |
| 763 | comptime try testRound(f16, 12.0); | |
| 764 | 764 | |
| 765 | 765 | const x = 14.0; |
| 766 | 766 | const y = x + 0.4; |
| 767 | 767 | const z = @round(y); |
| 768 | comptime expectEqual(x, z); | |
| 768 | comptime try expectEqual(x, z); | |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | fn testRound(comptime T: type, x: T) void { | |
| 771 | fn testRound(comptime T: type, x: T) !void { | |
| 772 | 772 | const y = x - 0.5; |
| 773 | 773 | const z = @round(y); |
| 774 | expectEqual(x, z); | |
| 774 | try expectEqual(x, z); | |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | test "comptime_int param and return" { |
| 778 | 778 | const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702); |
| 779 | expect(a == 137114567242441932203689521744947848950); | |
| 779 | try expect(a == 137114567242441932203689521744947848950); | |
| 780 | 780 | |
| 781 | 781 | const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768); |
| 782 | expect(b == 985095453608931032642182098849559179469148836107390954364380); | |
| 782 | try expect(b == 985095453608931032642182098849559179469148836107390954364380); | |
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | 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 |
| 788 | 788 | |
| 789 | 789 | test "vector integer addition" { |
| 790 | 790 | const S = struct { |
| 791 | fn doTheTest() void { | |
| 791 | fn doTheTest() !void { | |
| 792 | 792 | var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 793 | 793 | var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 }; |
| 794 | 794 | var result = a + b; |
| 795 | 795 | var result_array: [4]i32 = result; |
| 796 | 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(); | |
| 801 | comptime S.doTheTest(); | |
| 800 | try S.doTheTest(); | |
| 801 | comptime try S.doTheTest(); | |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | test "NaN comparison" { |
| 805 | testNanEqNan(f16); | |
| 806 | testNanEqNan(f32); | |
| 807 | testNanEqNan(f64); | |
| 808 | testNanEqNan(f128); | |
| 809 | comptime testNanEqNan(f16); | |
| 810 | comptime testNanEqNan(f32); | |
| 811 | comptime testNanEqNan(f64); | |
| 812 | comptime testNanEqNan(f128); | |
| 805 | try testNanEqNan(f16); | |
| 806 | try testNanEqNan(f32); | |
| 807 | try testNanEqNan(f64); | |
| 808 | try testNanEqNan(f128); | |
| 809 | comptime try testNanEqNan(f16); | |
| 810 | comptime try testNanEqNan(f32); | |
| 811 | comptime try testNanEqNan(f64); | |
| 812 | comptime try testNanEqNan(f128); | |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | fn testNanEqNan(comptime F: type) void { | |
| 815 | fn testNanEqNan(comptime F: type) !void { | |
| 816 | 816 | var nan1 = std.math.nan(F); |
| 817 | 817 | var nan2 = std.math.nan(F); |
| 818 | expect(nan1 != nan2); | |
| 819 | expect(!(nan1 == nan2)); | |
| 820 | expect(!(nan1 > nan2)); | |
| 821 | expect(!(nan1 >= nan2)); | |
| 822 | expect(!(nan1 < nan2)); | |
| 823 | expect(!(nan1 <= nan2)); | |
| 818 | try expect(nan1 != nan2); | |
| 819 | try expect(!(nan1 == nan2)); | |
| 820 | try expect(!(nan1 > nan2)); | |
| 821 | try expect(!(nan1 >= nan2)); | |
| 822 | try expect(!(nan1 < nan2)); | |
| 823 | try expect(!(nan1 <= nan2)); | |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | test "128-bit multiplication" { |
| 827 | 827 | var a: i128 = 3; |
| 828 | 828 | var b: i128 = 2; |
| 829 | 829 | var c = a * b; |
| 830 | expect(c == 6); | |
| 830 | try expect(c == 6); | |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | test "vector comparison" { |
| 834 | 834 | const S = struct { |
| 835 | fn doTheTest() void { | |
| 835 | fn doTheTest() !void { | |
| 836 | 836 | var a: std.meta.Vector(6, i32) = [_]i32{ 1, 3, -1, 5, 7, 9 }; |
| 837 | 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 })); | |
| 839 | expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); | |
| 840 | expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); | |
| 841 | expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true })); | |
| 842 | expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true })); | |
| 843 | expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true })); | |
| 838 | try expect(mem.eql(bool, &@as([6]bool, a < b), &[_]bool{ false, false, true, true, true, false })); | |
| 839 | try expect(mem.eql(bool, &@as([6]bool, a <= b), &[_]bool{ false, true, true, true, true, false })); | |
| 840 | try expect(mem.eql(bool, &@as([6]bool, a == b), &[_]bool{ false, true, false, false, false, false })); | |
| 841 | try expect(mem.eql(bool, &@as([6]bool, a != b), &[_]bool{ true, false, true, true, true, true })); | |
| 842 | try expect(mem.eql(bool, &@as([6]bool, a > b), &[_]bool{ true, false, false, false, false, true })); | |
| 843 | try expect(mem.eql(bool, &@as([6]bool, a >= b), &[_]bool{ true, true, false, false, false, true })); | |
| 844 | 844 | } |
| 845 | 845 | }; |
| 846 | S.doTheTest(); | |
| 847 | comptime S.doTheTest(); | |
| 846 | try S.doTheTest(); | |
| 847 | comptime try S.doTheTest(); | |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | test "compare undefined literal with comptime_int" { |
| 851 | 851 | var x = undefined == 1; |
| 852 | 852 | // x is now undefined with type bool |
| 853 | 853 | x = true; |
| 854 | expect(x); | |
| 854 | try expect(x); | |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | test "signed zeros are represented properly" { |
| 858 | 858 | const S = struct { |
| 859 | fn doTheTest() void { | |
| 859 | fn doTheTest() !void { | |
| 860 | 860 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
| 861 | 861 | const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); |
| 862 | 862 | var as_fp_val = -@as(T, 0.0); |
| 863 | 863 | var as_uint_val = @bitCast(ST, as_fp_val); |
| 864 | 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 | }; |
| 869 | 869 | |
| 870 | S.doTheTest(); | |
| 871 | comptime S.doTheTest(); | |
| 870 | try S.doTheTest(); | |
| 871 | comptime try S.doTheTest(); | |
| 872 | 872 | } |
test/stage1/behavior/misc.zig+107-107| ... | ... | @@ -25,18 +25,18 @@ test "call disabled extern fn" { |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | test "short circuit" { |
| 28 | testShortCircuit(false, true); | |
| 29 | comptime testShortCircuit(false, true); | |
| 28 | try testShortCircuit(false, true); | |
| 29 | comptime try testShortCircuit(false, true); | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | fn testShortCircuit(f: bool, t: bool) void { | |
| 32 | fn testShortCircuit(f: bool, t: bool) !void { | |
| 33 | 33 | var hit_1 = f; |
| 34 | 34 | var hit_2 = f; |
| 35 | 35 | var hit_3 = f; |
| 36 | 36 | var hit_4 = f; |
| 37 | 37 | |
| 38 | 38 | if (t or x: { |
| 39 | expect(f); | |
| 39 | try expect(f); | |
| 40 | 40 | break :x f; |
| 41 | 41 | }) { |
| 42 | 42 | hit_1 = t; |
| ... | ... | @@ -45,31 +45,31 @@ fn testShortCircuit(f: bool, t: bool) void { |
| 45 | 45 | hit_2 = t; |
| 46 | 46 | break :x f; |
| 47 | 47 | }) { |
| 48 | expect(f); | |
| 48 | try expect(f); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if (t and x: { |
| 52 | 52 | hit_3 = t; |
| 53 | 53 | break :x f; |
| 54 | 54 | }) { |
| 55 | expect(f); | |
| 55 | try expect(f); | |
| 56 | 56 | } |
| 57 | 57 | if (f and x: { |
| 58 | expect(f); | |
| 58 | try expect(f); | |
| 59 | 59 | break :x f; |
| 60 | 60 | }) { |
| 61 | expect(f); | |
| 61 | try expect(f); | |
| 62 | 62 | } else { |
| 63 | 63 | hit_4 = t; |
| 64 | 64 | } |
| 65 | expect(hit_1); | |
| 66 | expect(hit_2); | |
| 67 | expect(hit_3); | |
| 68 | expect(hit_4); | |
| 65 | try expect(hit_1); | |
| 66 | try expect(hit_2); | |
| 67 | try expect(hit_3); | |
| 68 | try expect(hit_4); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "truncate" { |
| 72 | expect(testTruncate(0x10fd) == 0xfd); | |
| 72 | try expect(testTruncate(0x10fd) == 0xfd); | |
| 73 | 73 | } |
| 74 | 74 | fn testTruncate(x: u32) u8 { |
| 75 | 75 | return @truncate(u8, x); |
| ... | ... | @@ -80,16 +80,16 @@ fn first4KeysOfHomeRow() []const u8 { |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | test "return string from function" { |
| 83 | expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); | |
| 83 | try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu")); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | const g1: i32 = 1233 + 1; |
| 87 | 87 | var g2: i32 = 0; |
| 88 | 88 | |
| 89 | 89 | test "global variables" { |
| 90 | expect(g2 == 0); | |
| 90 | try expect(g2 == 0); | |
| 91 | 91 | g2 = g1; |
| 92 | expect(g2 == 1234); | |
| 92 | try expect(g2 == 1234); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "memcpy and memset intrinsics" { |
| ... | ... | @@ -106,7 +106,7 @@ test "builtin static eval" { |
| 106 | 106 | const x: i32 = comptime x: { |
| 107 | 107 | break :x 1 + 2 + 3; |
| 108 | 108 | }; |
| 109 | expect(x == comptime 6); | |
| 109 | try expect(x == comptime 6); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "slicing" { |
| ... | ... | @@ -127,7 +127,7 @@ test "slicing" { |
| 127 | 127 | |
| 128 | 128 | test "constant equal function pointers" { |
| 129 | 129 | const alias = emptyFn; |
| 130 | expect(comptime x: { | |
| 130 | try expect(comptime x: { | |
| 131 | 131 | break :x emptyFn == alias; |
| 132 | 132 | }); |
| 133 | 133 | } |
| ... | ... | @@ -135,25 +135,25 @@ test "constant equal function pointers" { |
| 135 | 135 | fn emptyFn() void {} |
| 136 | 136 | |
| 137 | 137 | test "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 | } |
| 140 | 140 | |
| 141 | 141 | test "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 | } |
| 144 | 144 | |
| 145 | 145 | test "array mult operator" { |
| 146 | expect(mem.eql(u8, "ab" ** 5, "ababababab")); | |
| 146 | try expect(mem.eql(u8, "ab" ** 5, "ababababab")); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | test "string escapes" { |
| 150 | expect(mem.eql(u8, "\"", "\x22")); | |
| 151 | expect(mem.eql(u8, "\'", "\x27")); | |
| 152 | expect(mem.eql(u8, "\n", "\x0a")); | |
| 153 | expect(mem.eql(u8, "\r", "\x0d")); | |
| 154 | expect(mem.eql(u8, "\t", "\x09")); | |
| 155 | expect(mem.eql(u8, "\\", "\x5c")); | |
| 156 | expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01")); | |
| 150 | try expect(mem.eql(u8, "\"", "\x22")); | |
| 151 | try expect(mem.eql(u8, "\'", "\x27")); | |
| 152 | try expect(mem.eql(u8, "\n", "\x0a")); | |
| 153 | try expect(mem.eql(u8, "\r", "\x0d")); | |
| 154 | try expect(mem.eql(u8, "\t", "\x09")); | |
| 155 | try expect(mem.eql(u8, "\\", "\x5c")); | |
| 156 | try expect(mem.eql(u8, "\u{1234}\u{069}\u{1}", "\xe1\x88\xb4\x69\x01")); | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | test "multiline string" { |
| ... | ... | @@ -163,7 +163,7 @@ test "multiline string" { |
| 163 | 163 | \\three |
| 164 | 164 | ; |
| 165 | 165 | const s2 = "one\ntwo)\nthree"; |
| 166 | expect(mem.eql(u8, s1, s2)); | |
| 166 | try expect(mem.eql(u8, s1, s2)); | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | test "multiline string comments at start" { |
| ... | ... | @@ -173,7 +173,7 @@ test "multiline string comments at start" { |
| 173 | 173 | \\three |
| 174 | 174 | ; |
| 175 | 175 | const s2 = "two)\nthree"; |
| 176 | expect(mem.eql(u8, s1, s2)); | |
| 176 | try expect(mem.eql(u8, s1, s2)); | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | test "multiline string comments at end" { |
| ... | ... | @@ -183,7 +183,7 @@ test "multiline string comments at end" { |
| 183 | 183 | //\\three |
| 184 | 184 | ; |
| 185 | 185 | const s2 = "one\ntwo)"; |
| 186 | expect(mem.eql(u8, s1, s2)); | |
| 186 | try expect(mem.eql(u8, s1, s2)); | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | test "multiline string comments in middle" { |
| ... | ... | @@ -193,7 +193,7 @@ test "multiline string comments in middle" { |
| 193 | 193 | \\three |
| 194 | 194 | ; |
| 195 | 195 | const s2 = "one\nthree"; |
| 196 | expect(mem.eql(u8, s1, s2)); | |
| 196 | try expect(mem.eql(u8, s1, s2)); | |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | test "multiline string comments at multiple places" { |
| ... | ... | @@ -205,7 +205,7 @@ test "multiline string comments at multiple places" { |
| 205 | 205 | \\five |
| 206 | 206 | ; |
| 207 | 207 | const s2 = "one\nthree\nfive"; |
| 208 | expect(mem.eql(u8, s1, s2)); | |
| 208 | try expect(mem.eql(u8, s1, s2)); | |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | test "multiline C string" { |
| ... | ... | @@ -215,11 +215,11 @@ test "multiline C string" { |
| 215 | 215 | \\three |
| 216 | 216 | ; |
| 217 | 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 | } |
| 220 | 220 | |
| 221 | 221 | test "type equality" { |
| 222 | expect(*const u8 != *u8); | |
| 222 | try expect(*const u8 != *u8); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | const global_a: i32 = 1234; |
| ... | ... | @@ -227,7 +227,7 @@ const global_b: *const i32 = &global_a; |
| 227 | 227 | const global_c: *const f32 = @ptrCast(*const f32, global_b); |
| 228 | 228 | test "compile time global reinterpret" { |
| 229 | 229 | const d = @ptrCast(*const i32, global_c); |
| 230 | expect(d.* == 1234); | |
| 230 | try expect(d.* == 1234); | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | test "explicit cast maybe pointers" { |
| ... | ... | @@ -253,8 +253,8 @@ test "cast undefined" { |
| 253 | 253 | fn testCastUndefined(x: []const u8) void {} |
| 254 | 254 | |
| 255 | 255 | test "cast small unsigned to larger signed" { |
| 256 | expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200)); | |
| 257 | expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999)); | |
| 256 | try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200)); | |
| 257 | try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999)); | |
| 258 | 258 | } |
| 259 | 259 | fn castSmallUnsignedToLargerSigned1(x: u8) i16 { |
| 260 | 260 | return x; |
| ... | ... | @@ -264,7 +264,7 @@ fn castSmallUnsignedToLargerSigned2(x: u16) i64 { |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | test "implicit cast after unreachable" { |
| 267 | expect(outer() == 1234); | |
| 267 | try expect(outer() == 1234); | |
| 268 | 268 | } |
| 269 | 269 | fn inner() i32 { |
| 270 | 270 | return 1234; |
| ... | ... | @@ -279,13 +279,13 @@ test "pointer dereferencing" { |
| 279 | 279 | |
| 280 | 280 | y.* += 1; |
| 281 | 281 | |
| 282 | expect(x == 4); | |
| 283 | expect(y.* == 4); | |
| 282 | try expect(x == 4); | |
| 283 | try expect(y.* == 4); | |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | test "call result of if else expression" { |
| 287 | expect(mem.eql(u8, f2(true), "a")); | |
| 288 | expect(mem.eql(u8, f2(false), "b")); | |
| 287 | try expect(mem.eql(u8, f2(true), "a")); | |
| 288 | try expect(mem.eql(u8, f2(false), "b")); | |
| 289 | 289 | } |
| 290 | 290 | fn f2(x: bool) []const u8 { |
| 291 | 291 | return (if (x) fA else fB)(); |
| ... | ... | @@ -305,8 +305,8 @@ test "const expression eval handling of variables" { |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | test "constant enum initialization with differing sizes" { |
| 308 | test3_1(test3_foo); | |
| 309 | test3_2(test3_bar); | |
| 308 | try test3_1(test3_foo); | |
| 309 | try test3_2(test3_bar); | |
| 310 | 310 | } |
| 311 | 311 | const Test3Foo = union(enum) { |
| 312 | 312 | One: void, |
| ... | ... | @@ -324,41 +324,41 @@ const test3_foo = Test3Foo{ |
| 324 | 324 | }, |
| 325 | 325 | }; |
| 326 | 326 | const test3_bar = Test3Foo{ .Two = 13 }; |
| 327 | fn test3_1(f: Test3Foo) void { | |
| 327 | fn test3_1(f: Test3Foo) !void { | |
| 328 | 328 | switch (f) { |
| 329 | 329 | Test3Foo.Three => |pt| { |
| 330 | expect(pt.x == 3); | |
| 331 | expect(pt.y == 4); | |
| 330 | try expect(pt.x == 3); | |
| 331 | try expect(pt.y == 4); | |
| 332 | 332 | }, |
| 333 | 333 | else => unreachable, |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | fn test3_2(f: Test3Foo) void { | |
| 336 | fn test3_2(f: Test3Foo) !void { | |
| 337 | 337 | switch (f) { |
| 338 | 338 | Test3Foo.Two => |x| { |
| 339 | expect(x == 13); | |
| 339 | try expect(x == 13); | |
| 340 | 340 | }, |
| 341 | 341 | else => unreachable, |
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | test "character literals" { |
| 346 | expect('\'' == single_quote); | |
| 346 | try expect('\'' == single_quote); | |
| 347 | 347 | } |
| 348 | 348 | const single_quote = '\''; |
| 349 | 349 | |
| 350 | 350 | test "take address of parameter" { |
| 351 | testTakeAddressOfParameter(12.34); | |
| 351 | try testTakeAddressOfParameter(12.34); | |
| 352 | 352 | } |
| 353 | fn testTakeAddressOfParameter(f: f32) void { | |
| 353 | fn testTakeAddressOfParameter(f: f32) !void { | |
| 354 | 354 | const f_ptr = &f; |
| 355 | expect(f_ptr.* == 12.34); | |
| 355 | try expect(f_ptr.* == 12.34); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | test "pointer comparison" { |
| 359 | 359 | const a = @as([]const u8, "a"); |
| 360 | 360 | const b = &a; |
| 361 | expect(ptrEql(b, b)); | |
| 361 | try expect(ptrEql(b, b)); | |
| 362 | 362 | } |
| 363 | 363 | fn ptrEql(a: *const []const u8, b: *const []const u8) bool { |
| 364 | 364 | return a == b; |
| ... | ... | @@ -368,19 +368,19 @@ test "string concatenation" { |
| 368 | 368 | const a = "OK" ++ " IT " ++ "WORKED"; |
| 369 | 369 | const b = "OK IT WORKED"; |
| 370 | 370 | |
| 371 | comptime expect(@TypeOf(a) == *const [12:0]u8); | |
| 372 | comptime expect(@TypeOf(b) == *const [12:0]u8); | |
| 371 | comptime try expect(@TypeOf(a) == *const [12:0]u8); | |
| 372 | comptime try expect(@TypeOf(b) == *const [12:0]u8); | |
| 373 | 373 | |
| 374 | 374 | const len = mem.len(b); |
| 375 | 375 | const len_with_null = len + 1; |
| 376 | 376 | { |
| 377 | 377 | var i: u32 = 0; |
| 378 | 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); | |
| 383 | expect(b[len] == 0); | |
| 382 | try expect(a[len] == 0); | |
| 383 | try expect(b[len] == 0); | |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | test "pointer to void return type" { |
| ... | ... | @@ -397,7 +397,7 @@ fn testPointerToVoidReturnType2() *const void { |
| 397 | 397 | |
| 398 | 398 | test "non const ptr to aliased type" { |
| 399 | 399 | const int = i32; |
| 400 | expect(?*int == ?*i32); | |
| 400 | try expect(?*int == ?*i32); | |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | test "array 2D const double ptr" { |
| ... | ... | @@ -405,13 +405,13 @@ test "array 2D const double ptr" { |
| 405 | 405 | [_]f32{1.0}, |
| 406 | 406 | [_]f32{2.0}, |
| 407 | 407 | }; |
| 408 | testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]); | |
| 408 | try testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]); | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | fn testArray2DConstDoublePtr(ptr: *const f32) void { | |
| 411 | fn testArray2DConstDoublePtr(ptr: *const f32) !void { | |
| 412 | 412 | const ptr2 = @ptrCast([*]const f32, ptr); |
| 413 | expect(ptr2[0] == 1.0); | |
| 414 | expect(ptr2[1] == 2.0); | |
| 413 | try expect(ptr2[0] == 1.0); | |
| 414 | try expect(ptr2[1] == 2.0); | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | const AStruct = struct { |
| ... | ... | @@ -439,13 +439,13 @@ test "@typeName" { |
| 439 | 439 | Unused, |
| 440 | 440 | }; |
| 441 | 441 | comptime { |
| 442 | expect(mem.eql(u8, @typeName(i64), "i64")); | |
| 443 | expect(mem.eql(u8, @typeName(*usize), "*usize")); | |
| 442 | try expect(mem.eql(u8, @typeName(i64), "i64")); | |
| 443 | try expect(mem.eql(u8, @typeName(*usize), "*usize")); | |
| 444 | 444 | // https://github.com/ziglang/zig/issues/675 |
| 445 | expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8)))); | |
| 446 | expect(mem.eql(u8, @typeName(Struct), "Struct")); | |
| 447 | expect(mem.eql(u8, @typeName(Union), "Union")); | |
| 448 | expect(mem.eql(u8, @typeName(Enum), "Enum")); | |
| 445 | try expect(mem.eql(u8, "behavior.misc.TypeFromFn(u8)", @typeName(TypeFromFn(u8)))); | |
| 446 | try expect(mem.eql(u8, @typeName(Struct), "Struct")); | |
| 447 | try expect(mem.eql(u8, @typeName(Union), "Union")); | |
| 448 | try expect(mem.eql(u8, @typeName(Enum), "Enum")); | |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
| ... | ... | @@ -455,14 +455,14 @@ fn TypeFromFn(comptime T: type) type { |
| 455 | 455 | |
| 456 | 456 | test "double implicit cast in same expression" { |
| 457 | 457 | var x = @as(i32, @as(u16, nine())); |
| 458 | expect(x == 9); | |
| 458 | try expect(x == 9); | |
| 459 | 459 | } |
| 460 | 460 | fn nine() u8 { |
| 461 | 461 | return 9; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | test "global variable initialized to global variable array element" { |
| 465 | expect(global_ptr == &gdt[0]); | |
| 465 | try expect(global_ptr == &gdt[0]); | |
| 466 | 466 | } |
| 467 | 467 | const GDTEntry = struct { |
| 468 | 468 | field: i32, |
| ... | ... | @@ -483,9 +483,9 @@ export fn writeToVRam() void { |
| 483 | 483 | const OpaqueA = opaque {}; |
| 484 | 484 | const OpaqueB = opaque {}; |
| 485 | 485 | test "opaque types" { |
| 486 | expect(*OpaqueA != *OpaqueB); | |
| 487 | expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); | |
| 488 | expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB")); | |
| 486 | try expect(*OpaqueA != *OpaqueB); | |
| 487 | try expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); | |
| 488 | try expect(mem.eql(u8, @typeName(OpaqueB), "OpaqueB")); | |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | test "variable is allowed to be a pointer to an opaque type" { |
| ... | ... | @@ -525,7 +525,7 @@ fn fnThatClosesOverLocalConst() type { |
| 525 | 525 | |
| 526 | 526 | test "function closes over local const" { |
| 527 | 527 | const x = fnThatClosesOverLocalConst().g(); |
| 528 | expect(x == 1); | |
| 528 | try expect(x == 1); | |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | test "cold function" { |
| ... | ... | @@ -562,21 +562,21 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack |
| 562 | 562 | test "slicing zero length array" { |
| 563 | 563 | const s1 = ""[0..]; |
| 564 | 564 | const s2 = ([_]u32{})[0..]; |
| 565 | expect(s1.len == 0); | |
| 566 | expect(s2.len == 0); | |
| 567 | expect(mem.eql(u8, s1, "")); | |
| 568 | expect(mem.eql(u32, s2, &[_]u32{})); | |
| 565 | try expect(s1.len == 0); | |
| 566 | try expect(s2.len == 0); | |
| 567 | try expect(mem.eql(u8, s1, "")); | |
| 568 | try expect(mem.eql(u32, s2, &[_]u32{})); | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | const addr1 = @ptrCast(*const u8, emptyFn); |
| 572 | 572 | test "comptime cast fn to ptr" { |
| 573 | 573 | const addr2 = @ptrCast(*const u8, emptyFn); |
| 574 | comptime expect(addr1 == addr2); | |
| 574 | comptime try expect(addr1 == addr2); | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | test "equality compare fn ptrs" { |
| 578 | 578 | var a = emptyFn; |
| 579 | expect(a == a); | |
| 579 | try expect(a == a); | |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | test "self reference through fn ptr field" { |
| ... | ... | @@ -591,34 +591,34 @@ test "self reference through fn ptr field" { |
| 591 | 591 | }; |
| 592 | 592 | var a: S.A = undefined; |
| 593 | 593 | a.f = S.foo; |
| 594 | expect(a.f(a) == 12); | |
| 594 | try expect(a.f(a) == 12); | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | test "volatile load and store" { |
| 598 | 598 | var number: i32 = 1234; |
| 599 | 599 | const ptr = @as(*volatile i32, &number); |
| 600 | 600 | ptr.* += 1; |
| 601 | expect(ptr.* == 1235); | |
| 601 | try expect(ptr.* == 1235); | |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | test "slice string literal has correct type" { |
| 605 | 605 | comptime { |
| 606 | expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8); | |
| 606 | try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8); | |
| 607 | 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 | 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 | 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 | } |
| 615 | 615 | |
| 616 | 616 | test "struct inside function" { |
| 617 | testStructInFn(); | |
| 618 | comptime testStructInFn(); | |
| 617 | try testStructInFn(); | |
| 618 | comptime try testStructInFn(); | |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | fn testStructInFn() void { | |
| 621 | fn testStructInFn() !void { | |
| 622 | 622 | const BlockKind = u32; |
| 623 | 623 | |
| 624 | 624 | const Block = struct { |
| ... | ... | @@ -629,11 +629,11 @@ fn testStructInFn() void { |
| 629 | 629 | |
| 630 | 630 | block.kind += 1; |
| 631 | 631 | |
| 632 | expect(block.kind == 1235); | |
| 632 | try expect(block.kind == 1235); | |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | test "fn call returning scalar optional in equality expression" { |
| 636 | expect(getNull() == null); | |
| 636 | try expect(getNull() == null); | |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | fn getNull() ?*i32 { |
| ... | ... | @@ -645,16 +645,16 @@ test "thread local variable" { |
| 645 | 645 | threadlocal var t: i32 = 1234; |
| 646 | 646 | }; |
| 647 | 647 | S.t += 1; |
| 648 | expect(S.t == 1235); | |
| 648 | try expect(S.t == 1235); | |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | test "unicode escape in character literal" { |
| 652 | 652 | var a: u24 = '\u{01f4a9}'; |
| 653 | expect(a == 128169); | |
| 653 | try expect(a == 128169); | |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | test "unicode character in character literal" { |
| 657 | expect('💩' == 128169); | |
| 657 | try expect('💩' == 128169); | |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | test "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 | 662 | entries: []u32, |
| 663 | 663 | }; |
| 664 | 664 | var foo = E{ .entries = &[_]u32{} }; |
| 665 | expect(foo.entries.len == 0); | |
| 665 | try expect(foo.entries.len == 0); | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | var global_foo: *i32 = undefined; |
| ... | ... | @@ -677,7 +677,7 @@ test "global variable assignment with optional unwrapping with var initialized t |
| 677 | 677 | global_foo = S.foo() orelse { |
| 678 | 678 | @panic("bad"); |
| 679 | 679 | }; |
| 680 | expect(global_foo.* == 1234); | |
| 680 | try expect(global_foo.* == 1234); | |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | 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 | 696 | bleh: i32, |
| 697 | 697 | }; |
| 698 | 698 | }; |
| 699 | expect(S.doTheTest(0) == 1234); | |
| 700 | expect(S.doTheTest(1) == 1234); | |
| 699 | try expect(S.doTheTest(0) == 1234); | |
| 700 | try expect(S.doTheTest(1) == 1234); | |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | test "nested optional field in struct" { |
| ... | ... | @@ -710,7 +710,7 @@ test "nested optional field in struct" { |
| 710 | 710 | var s = S1{ |
| 711 | 711 | .x = S2{ .y = 127 }, |
| 712 | 712 | }; |
| 713 | expect(s.x.?.y == 127); | |
| 713 | try expect(s.x.?.y == 127); | |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | fn maybe(x: bool) anyerror!?u32 { |
| ... | ... | @@ -722,7 +722,7 @@ fn maybe(x: bool) anyerror!?u32 { |
| 722 | 722 | |
| 723 | 723 | test "result location is optional inside error union" { |
| 724 | 724 | const x = maybe(true) catch unreachable; |
| 725 | expect(x.? == 42); | |
| 725 | try expect(x.? == 42); | |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | threadlocal var buffer: [11]u8 = undefined; |
| ... | ... | @@ -730,7 +730,7 @@ threadlocal var buffer: [11]u8 = undefined; |
| 730 | 730 | test "pointer to thread local array" { |
| 731 | 731 | const s = "Hello world"; |
| 732 | 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 | } |
| 735 | 735 | |
| 736 | 736 | test "auto created variables have correct alignment" { |
| ... | ... | @@ -742,15 +742,15 @@ test "auto created variables have correct alignment" { |
| 742 | 742 | return 0; |
| 743 | 743 | } |
| 744 | 744 | }; |
| 745 | expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 746 | comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 745 | try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 746 | comptime try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | extern var opaque_extern_var: opaque {}; |
| 750 | 750 | var var_to_export: u32 = 42; |
| 751 | 751 | test "extern variable with non-pointer opaque type" { |
| 752 | 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 | } |
| 755 | 755 | |
| 756 | 756 | test "lazy typeInfo value as generic parameter" { |
test/stage1/behavior/muladd.zig+7-7| ... | ... | @@ -1,34 +1,34 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "@mulAdd" { |
| 4 | comptime testMulAdd(); | |
| 5 | testMulAdd(); | |
| 4 | comptime try testMulAdd(); | |
| 5 | try testMulAdd(); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | fn testMulAdd() void { | |
| 8 | fn testMulAdd() !void { | |
| 9 | 9 | { |
| 10 | 10 | var a: f16 = 5.5; |
| 11 | 11 | var b: f16 = 2.5; |
| 12 | 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 | 16 | var a: f32 = 5.5; |
| 17 | 17 | var b: f32 = 2.5; |
| 18 | 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 | 22 | var a: f64 = 5.5; |
| 23 | 23 | var b: f64 = 2.5; |
| 24 | 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 | 27 | // Awaits implementation in libm.zig |
| 28 | 28 | //{ |
| 29 | 29 | // var a: f16 = 5.5; |
| 30 | 30 | // var b: f128 = 2.5; |
| 31 | 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/stage1/behavior/namespace_depends_on_compile_var.zig+2-2| ... | ... | @@ -3,9 +3,9 @@ const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "namespace depends on compile var" { |
| 5 | 5 | if (some_namespace.a_bool) { |
| 6 | expect(some_namespace.a_bool); | |
| 6 | try expect(some_namespace.a_bool); | |
| 7 | 7 | } else { |
| 8 | expect(!some_namespace.a_bool); | |
| 8 | try expect(!some_namespace.a_bool); | |
| 9 | 9 | } |
| 10 | 10 | } |
| 11 | 11 | const some_namespace = switch (std.builtin.os.tag) { |
test/stage1/behavior/null.zig+24-24| ... | ... | @@ -17,13 +17,13 @@ test "optional type" { |
| 17 | 17 | |
| 18 | 18 | const z = next_x orelse 1234; |
| 19 | 19 | |
| 20 | expect(z == 1234); | |
| 20 | try expect(z == 1234); | |
| 21 | 21 | |
| 22 | 22 | const final_x: ?i32 = 13; |
| 23 | 23 | |
| 24 | 24 | const num = final_x orelse unreachable; |
| 25 | 25 | |
| 26 | expect(num == 13); | |
| 26 | try expect(num == 13); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | 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 | 33 | b.* = false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | expect(maybe_bool.? == false); | |
| 36 | try expect(maybe_bool.? == false); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "rhs maybe unwrap return" { |
| ... | ... | @@ -42,14 +42,14 @@ test "rhs maybe unwrap return" { |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | test "maybe return" { |
| 45 | maybeReturnImpl(); | |
| 46 | comptime maybeReturnImpl(); | |
| 45 | try maybeReturnImpl(); | |
| 46 | comptime try maybeReturnImpl(); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | fn maybeReturnImpl() void { | |
| 50 | expect(foo(1235).?); | |
| 49 | fn maybeReturnImpl() !void { | |
| 50 | try expect(foo(1235).?); | |
| 51 | 51 | if (foo(null) != null) unreachable; |
| 52 | expect(!foo(1234).?); | |
| 52 | try expect(!foo(1234).?); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn foo(x: ?i32) ?bool { |
| ... | ... | @@ -58,7 +58,7 @@ fn foo(x: ?i32) ?bool { |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | test "if var maybe pointer" { |
| 61 | expect(shouldBeAPlus1(Particle{ | |
| 61 | try expect(shouldBeAPlus1(Particle{ | |
| 62 | 62 | .a = 14, |
| 63 | 63 | .b = 1, |
| 64 | 64 | .c = 1, |
| ... | ... | @@ -84,10 +84,10 @@ const Particle = struct { |
| 84 | 84 | |
| 85 | 85 | test "null literal outside function" { |
| 86 | 86 | const is_null = here_is_a_null_literal.context == null; |
| 87 | expect(is_null); | |
| 87 | try expect(is_null); | |
| 88 | 88 | |
| 89 | 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 | } |
| 92 | 92 | const SillyStruct = struct { |
| 93 | 93 | context: ?i32, |
| ... | ... | @@ -95,21 +95,21 @@ const SillyStruct = struct { |
| 95 | 95 | const here_is_a_null_literal = SillyStruct{ .context = null }; |
| 96 | 96 | |
| 97 | 97 | test "test null runtime" { |
| 98 | testTestNullRuntime(null); | |
| 98 | try testTestNullRuntime(null); | |
| 99 | 99 | } |
| 100 | fn testTestNullRuntime(x: ?i32) void { | |
| 101 | expect(x == null); | |
| 102 | expect(!(x != null)); | |
| 100 | fn testTestNullRuntime(x: ?i32) !void { | |
| 101 | try expect(x == null); | |
| 102 | try expect(!(x != null)); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | test "optional void" { |
| 106 | optionalVoidImpl(); | |
| 107 | comptime optionalVoidImpl(); | |
| 106 | try optionalVoidImpl(); | |
| 107 | comptime try optionalVoidImpl(); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | fn optionalVoidImpl() void { | |
| 111 | expect(bar(null) == null); | |
| 112 | expect(bar({}) != null); | |
| 110 | fn optionalVoidImpl() !void { | |
| 111 | try expect(bar(null) == null); | |
| 112 | try expect(bar({}) != null); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | fn bar(x: ?void) ?void { |
| ... | ... | @@ -133,7 +133,7 @@ test "unwrap optional which is field of global var" { |
| 133 | 133 | } |
| 134 | 134 | struct_with_optional.field = 1234; |
| 135 | 135 | if (struct_with_optional.field) |payload| { |
| 136 | expect(payload == 1234); | |
| 136 | try expect(payload == 1234); | |
| 137 | 137 | } else { |
| 138 | 138 | unreachable; |
| 139 | 139 | } |
| ... | ... | @@ -141,13 +141,13 @@ test "unwrap optional which is field of global var" { |
| 141 | 141 | |
| 142 | 142 | test "null with default unwrap" { |
| 143 | 143 | const x: i32 = null orelse 1; |
| 144 | expect(x == 1); | |
| 144 | try expect(x == 1); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | test "optional types" { |
| 148 | 148 | comptime { |
| 149 | 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 | } |
| 153 | 153 | |
| ... | ... | @@ -158,5 +158,5 @@ const StructWithOptionalType = struct { |
| 158 | 158 | test "optional pointer to 0 bit type null value at runtime" { |
| 159 | 159 | const EmptyStruct = struct {}; |
| 160 | 160 | var x: ?*EmptyStruct = null; |
| 161 | expect(x == null); | |
| 161 | try expect(x == null); | |
| 162 | 162 | } |
test/stage1/behavior/optional.zig+51-51| ... | ... | @@ -8,28 +8,28 @@ pub const EmptyStruct = struct {}; |
| 8 | 8 | test "optional pointer to size zero struct" { |
| 9 | 9 | var e = EmptyStruct{}; |
| 10 | 10 | var o: ?*EmptyStruct = &e; |
| 11 | expect(o != null); | |
| 11 | try expect(o != null); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "equality compare nullable pointers" { |
| 15 | testNullPtrsEql(); | |
| 16 | comptime testNullPtrsEql(); | |
| 15 | try testNullPtrsEql(); | |
| 16 | comptime try testNullPtrsEql(); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | fn testNullPtrsEql() void { | |
| 19 | fn testNullPtrsEql() !void { | |
| 20 | 20 | var number: i32 = 1234; |
| 21 | 21 | |
| 22 | 22 | var x: ?*i32 = null; |
| 23 | 23 | var y: ?*i32 = null; |
| 24 | expect(x == y); | |
| 24 | try expect(x == y); | |
| 25 | 25 | y = &number; |
| 26 | expect(x != y); | |
| 27 | expect(x != &number); | |
| 28 | expect(&number != x); | |
| 26 | try expect(x != y); | |
| 27 | try expect(x != &number); | |
| 28 | try expect(&number != x); | |
| 29 | 29 | x = &number; |
| 30 | expect(x == y); | |
| 31 | expect(x == &number); | |
| 32 | expect(&number == x); | |
| 30 | try expect(x == y); | |
| 31 | try expect(x == &number); | |
| 32 | try expect(&number == x); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | test "address of unwrap optional" { |
| ... | ... | @@ -46,23 +46,23 @@ test "address of unwrap optional" { |
| 46 | 46 | }; |
| 47 | 47 | S.global = S.Foo{ .a = 1234 }; |
| 48 | 48 | const foo = S.getFoo() catch unreachable; |
| 49 | expect(foo.a == 1234); | |
| 49 | try expect(foo.a == 1234); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | test "equality compare optional with non-optional" { |
| 53 | test_cmp_optional_non_optional(); | |
| 54 | comptime test_cmp_optional_non_optional(); | |
| 53 | try test_cmp_optional_non_optional(); | |
| 54 | comptime try test_cmp_optional_non_optional(); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | fn test_cmp_optional_non_optional() void { | |
| 57 | fn test_cmp_optional_non_optional() !void { | |
| 58 | 58 | var ten: i32 = 10; |
| 59 | 59 | var opt_ten: ?i32 = 10; |
| 60 | 60 | var five: i32 = 5; |
| 61 | 61 | var int_n: ?i32 = null; |
| 62 | 62 | |
| 63 | expect(int_n != ten); | |
| 64 | expect(opt_ten == ten); | |
| 65 | expect(opt_ten != five); | |
| 63 | try expect(int_n != ten); | |
| 64 | try expect(opt_ten == ten); | |
| 65 | try expect(opt_ten != five); | |
| 66 | 66 | |
| 67 | 67 | // test evaluation is always lexical |
| 68 | 68 | // ensure that the optional isn't always computed before the non-optional |
| ... | ... | @@ -71,14 +71,14 @@ fn test_cmp_optional_non_optional() void { |
| 71 | 71 | mutable_state += 1; |
| 72 | 72 | break :blk1 @as(?f64, 10.0); |
| 73 | 73 | } != blk2: { |
| 74 | expect(mutable_state == 1); | |
| 74 | try expect(mutable_state == 1); | |
| 75 | 75 | break :blk2 @as(f64, 5.0); |
| 76 | 76 | }; |
| 77 | 77 | _ = blk1: { |
| 78 | 78 | mutable_state += 1; |
| 79 | 79 | break :blk1 @as(f64, 10.0); |
| 80 | 80 | } != blk2: { |
| 81 | expect(mutable_state == 2); | |
| 81 | try expect(mutable_state == 2); | |
| 82 | 82 | break :blk2 @as(?f64, 5.0); |
| 83 | 83 | }; |
| 84 | 84 | } |
| ... | ... | @@ -94,15 +94,15 @@ test "passing an optional integer as a parameter" { |
| 94 | 94 | return x.? == 1234; |
| 95 | 95 | } |
| 96 | 96 | }; |
| 97 | expect(S.entry()); | |
| 98 | comptime expect(S.entry()); | |
| 97 | try expect(S.entry()); | |
| 98 | comptime try expect(S.entry()); | |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | test "unwrap function call with optional pointer return value" { |
| 102 | 102 | const S = struct { |
| 103 | fn entry() void { | |
| 104 | expect(foo().?.* == 1234); | |
| 105 | expect(bar() == null); | |
| 103 | fn entry() !void { | |
| 104 | try expect(foo().?.* == 1234); | |
| 105 | try expect(bar() == null); | |
| 106 | 106 | } |
| 107 | 107 | const global: i32 = 1234; |
| 108 | 108 | fn foo() ?*const i32 { |
| ... | ... | @@ -112,14 +112,14 @@ test "unwrap function call with optional pointer return value" { |
| 112 | 112 | return null; |
| 113 | 113 | } |
| 114 | 114 | }; |
| 115 | S.entry(); | |
| 116 | comptime S.entry(); | |
| 115 | try S.entry(); | |
| 116 | comptime try S.entry(); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | test "nested orelse" { |
| 120 | 120 | const S = struct { |
| 121 | fn entry() void { | |
| 122 | expect(func() == null); | |
| 121 | fn entry() !void { | |
| 122 | try expect(func() == null); | |
| 123 | 123 | } |
| 124 | 124 | fn maybe() ?Foo { |
| 125 | 125 | return null; |
| ... | ... | @@ -134,8 +134,8 @@ test "nested orelse" { |
| 134 | 134 | field: i32, |
| 135 | 135 | }; |
| 136 | 136 | }; |
| 137 | S.entry(); | |
| 138 | comptime S.entry(); | |
| 137 | try S.entry(); | |
| 138 | comptime try S.entry(); | |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | test "self-referential struct through a slice of optional" { |
| ... | ... | @@ -154,7 +154,7 @@ test "self-referential struct through a slice of optional" { |
| 154 | 154 | }; |
| 155 | 155 | |
| 156 | 156 | var n = S.Node.new(); |
| 157 | expect(n.data == null); | |
| 157 | try expect(n.data == null); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | test "assigning to an unwrapped optional field in an inline loop" { |
| ... | ... | @@ -173,14 +173,14 @@ test "coerce an anon struct literal to optional struct" { |
| 173 | 173 | const Struct = struct { |
| 174 | 174 | field: u32, |
| 175 | 175 | }; |
| 176 | export fn doTheTest() void { | |
| 176 | fn doTheTest() !void { | |
| 177 | 177 | var maybe_dims: ?Struct = null; |
| 178 | 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(); | |
| 183 | comptime S.doTheTest(); | |
| 182 | try S.doTheTest(); | |
| 183 | comptime try S.doTheTest(); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | test "optional with void type" { |
| ... | ... | @@ -188,15 +188,15 @@ test "optional with void type" { |
| 188 | 188 | x: ?void, |
| 189 | 189 | }; |
| 190 | 190 | var x = Foo{ .x = null }; |
| 191 | expect(x.x == null); | |
| 191 | try expect(x.x == null); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | test "0-bit child type coerced to optional return ptr result location" { |
| 195 | 195 | const S = struct { |
| 196 | fn doTheTest() void { | |
| 196 | fn doTheTest() !void { | |
| 197 | 197 | var y = Foo{}; |
| 198 | 198 | var z = y.thing(); |
| 199 | expect(z != null); | |
| 199 | try expect(z != null); | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | const Foo = struct { |
| ... | ... | @@ -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(); | |
| 213 | comptime S.doTheTest(); | |
| 212 | try S.doTheTest(); | |
| 213 | comptime try S.doTheTest(); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | test "0-bit child type coerced to optional" { |
| 217 | 217 | const S = struct { |
| 218 | fn doTheTest() void { | |
| 218 | fn doTheTest() !void { | |
| 219 | 219 | var it: Foo = .{ |
| 220 | 220 | .list = undefined, |
| 221 | 221 | }; |
| 222 | expect(it.foo() != null); | |
| 222 | try expect(it.foo() != null); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | const Empty = struct {}; |
| ... | ... | @@ -232,8 +232,8 @@ test "0-bit child type coerced to optional" { |
| 232 | 232 | } |
| 233 | 233 | }; |
| 234 | 234 | }; |
| 235 | S.doTheTest(); | |
| 236 | comptime S.doTheTest(); | |
| 235 | try S.doTheTest(); | |
| 236 | comptime try S.doTheTest(); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | test "array of optional unaligned types" { |
| ... | ... | @@ -255,15 +255,15 @@ test "array of optional unaligned types" { |
| 255 | 255 | |
| 256 | 256 | // The index must be a runtime value |
| 257 | 257 | var i: usize = 0; |
| 258 | expectEqual(Enum.one, values[i].?.Num); | |
| 258 | try expectEqual(Enum.one, values[i].?.Num); | |
| 259 | 259 | i += 1; |
| 260 | expectEqual(Enum.two, values[i].?.Num); | |
| 260 | try expectEqual(Enum.two, values[i].?.Num); | |
| 261 | 261 | i += 1; |
| 262 | expectEqual(Enum.three, values[i].?.Num); | |
| 262 | try expectEqual(Enum.three, values[i].?.Num); | |
| 263 | 263 | i += 1; |
| 264 | expectEqual(Enum.one, values[i].?.Num); | |
| 264 | try expectEqual(Enum.one, values[i].?.Num); | |
| 265 | 265 | i += 1; |
| 266 | expectEqual(Enum.two, values[i].?.Num); | |
| 266 | try expectEqual(Enum.two, values[i].?.Num); | |
| 267 | 267 | i += 1; |
| 268 | expectEqual(Enum.three, values[i].?.Num); | |
| 268 | try expectEqual(Enum.three, values[i].?.Num); | |
| 269 | 269 | } |
test/stage1/behavior/pointers.zig+108-108| ... | ... | @@ -4,15 +4,15 @@ const expect = testing.expect; |
| 4 | 4 | const expectError = testing.expectError; |
| 5 | 5 | |
| 6 | 6 | test "dereference pointer" { |
| 7 | comptime testDerefPtr(); | |
| 8 | testDerefPtr(); | |
| 7 | comptime try testDerefPtr(); | |
| 8 | try testDerefPtr(); | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | fn testDerefPtr() void { | |
| 11 | fn testDerefPtr() !void { | |
| 12 | 12 | var x: i32 = 1234; |
| 13 | 13 | var y = &x; |
| 14 | 14 | y.* += 1; |
| 15 | expect(x == 1235); | |
| 15 | try expect(x == 1235); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | const Foo1 = struct { |
| ... | ... | @@ -20,41 +20,41 @@ const Foo1 = struct { |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | test "dereference pointer again" { |
| 23 | testDerefPtrOneVal(); | |
| 24 | comptime testDerefPtrOneVal(); | |
| 23 | try testDerefPtrOneVal(); | |
| 24 | comptime try testDerefPtrOneVal(); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | fn testDerefPtrOneVal() void { | |
| 27 | fn testDerefPtrOneVal() !void { | |
| 28 | 28 | // Foo1 satisfies the OnePossibleValueYes criteria |
| 29 | 29 | const x = &Foo1{ .x = {} }; |
| 30 | 30 | const y = x.*; |
| 31 | expect(@TypeOf(y.x) == void); | |
| 31 | try expect(@TypeOf(y.x) == void); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "pointer arithmetic" { |
| 35 | 35 | var ptr: [*]const u8 = "abcd"; |
| 36 | 36 | |
| 37 | expect(ptr[0] == 'a'); | |
| 37 | try expect(ptr[0] == 'a'); | |
| 38 | 38 | ptr += 1; |
| 39 | expect(ptr[0] == 'b'); | |
| 39 | try expect(ptr[0] == 'b'); | |
| 40 | 40 | ptr += 1; |
| 41 | expect(ptr[0] == 'c'); | |
| 41 | try expect(ptr[0] == 'c'); | |
| 42 | 42 | ptr += 1; |
| 43 | expect(ptr[0] == 'd'); | |
| 43 | try expect(ptr[0] == 'd'); | |
| 44 | 44 | ptr += 1; |
| 45 | expect(ptr[0] == 0); | |
| 45 | try expect(ptr[0] == 0); | |
| 46 | 46 | ptr -= 1; |
| 47 | expect(ptr[0] == 'd'); | |
| 47 | try expect(ptr[0] == 'd'); | |
| 48 | 48 | ptr -= 1; |
| 49 | expect(ptr[0] == 'c'); | |
| 49 | try expect(ptr[0] == 'c'); | |
| 50 | 50 | ptr -= 1; |
| 51 | expect(ptr[0] == 'b'); | |
| 51 | try expect(ptr[0] == 'b'); | |
| 52 | 52 | ptr -= 1; |
| 53 | expect(ptr[0] == 'a'); | |
| 53 | try expect(ptr[0] == 'a'); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | test "double pointer parsing" { |
| 57 | comptime expect(PtrOf(PtrOf(i32)) == **i32); | |
| 57 | comptime try expect(PtrOf(PtrOf(i32)) == **i32); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | fn PtrOf(comptime T: type) type { |
| ... | ... | @@ -72,33 +72,33 @@ test "implicit cast single item pointer to C pointer and back" { |
| 72 | 72 | var x: [*c]u8 = &y; |
| 73 | 73 | var z: *u8 = x; |
| 74 | 74 | z.* += 1; |
| 75 | expect(y == 12); | |
| 75 | try expect(y == 12); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | test "C pointer comparison and arithmetic" { |
| 79 | 79 | const S = struct { |
| 80 | fn doTheTest() void { | |
| 80 | fn doTheTest() !void { | |
| 81 | 81 | var one: usize = 1; |
| 82 | 82 | var ptr1: [*c]u32 = 0; |
| 83 | 83 | var ptr2 = ptr1 + 10; |
| 84 | expect(ptr1 == 0); | |
| 85 | expect(ptr1 >= 0); | |
| 86 | expect(ptr1 <= 0); | |
| 84 | try expect(ptr1 == 0); | |
| 85 | try expect(ptr1 >= 0); | |
| 86 | try expect(ptr1 <= 0); | |
| 87 | 87 | // expect(ptr1 < 1); |
| 88 | 88 | // expect(ptr1 < one); |
| 89 | 89 | // expect(1 > ptr1); |
| 90 | 90 | // expect(one > ptr1); |
| 91 | expect(ptr1 < ptr2); | |
| 92 | expect(ptr2 > ptr1); | |
| 93 | expect(ptr2 >= 40); | |
| 94 | expect(ptr2 == 40); | |
| 95 | expect(ptr2 <= 40); | |
| 91 | try expect(ptr1 < ptr2); | |
| 92 | try expect(ptr2 > ptr1); | |
| 93 | try expect(ptr2 >= 40); | |
| 94 | try expect(ptr2 == 40); | |
| 95 | try expect(ptr2 <= 40); | |
| 96 | 96 | ptr2 -= 10; |
| 97 | expect(ptr1 == ptr2); | |
| 97 | try expect(ptr1 == ptr2); | |
| 98 | 98 | } |
| 99 | 99 | }; |
| 100 | S.doTheTest(); | |
| 101 | comptime S.doTheTest(); | |
| 100 | try S.doTheTest(); | |
| 101 | comptime try S.doTheTest(); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | test "peer type resolution with C pointers" { |
| ... | ... | @@ -110,10 +110,10 @@ test "peer type resolution with C pointers" { |
| 110 | 110 | var x2 = if (t) ptr_many else ptr_c; |
| 111 | 111 | var x3 = if (t) ptr_c else ptr_one; |
| 112 | 112 | var x4 = if (t) ptr_c else ptr_many; |
| 113 | expect(@TypeOf(x1) == [*c]u8); | |
| 114 | expect(@TypeOf(x2) == [*c]u8); | |
| 115 | expect(@TypeOf(x3) == [*c]u8); | |
| 116 | expect(@TypeOf(x4) == [*c]u8); | |
| 113 | try expect(@TypeOf(x1) == [*c]u8); | |
| 114 | try expect(@TypeOf(x2) == [*c]u8); | |
| 115 | try expect(@TypeOf(x3) == [*c]u8); | |
| 116 | try expect(@TypeOf(x4) == [*c]u8); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | 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 | 121 | const opt_many_ptr: ?[*]const u8 = slice.ptr; |
| 122 | 122 | var ptr_opt_many_ptr = &opt_many_ptr; |
| 123 | 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 | 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 | } |
| 128 | 128 | |
| 129 | 129 | test "implicit cast error unions with non-optional to optional pointer" { |
| 130 | 130 | const S = struct { |
| 131 | fn doTheTest() void { | |
| 132 | expectError(error.Fail, foo()); | |
| 131 | fn doTheTest() !void { | |
| 132 | try expectError(error.Fail, foo()); | |
| 133 | 133 | } |
| 134 | 134 | fn foo() anyerror!?*u8 { |
| 135 | 135 | return bar() orelse error.Fail; |
| ... | ... | @@ -138,111 +138,111 @@ test "implicit cast error unions with non-optional to optional pointer" { |
| 138 | 138 | return null; |
| 139 | 139 | } |
| 140 | 140 | }; |
| 141 | S.doTheTest(); | |
| 142 | comptime S.doTheTest(); | |
| 141 | try S.doTheTest(); | |
| 142 | comptime try S.doTheTest(); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | test "initialize const optional C pointer to null" { |
| 146 | 146 | const a: ?[*c]i32 = null; |
| 147 | expect(a == null); | |
| 148 | comptime expect(a == null); | |
| 147 | try expect(a == null); | |
| 148 | comptime try expect(a == null); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "compare equality of optional and non-optional pointer" { |
| 152 | 152 | const a = @intToPtr(*const usize, 0x12345678); |
| 153 | 153 | const b = @intToPtr(?*usize, 0x12345678); |
| 154 | expect(a == b); | |
| 155 | expect(b == a); | |
| 154 | try expect(a == b); | |
| 155 | try expect(b == a); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | test "allowzero pointer and slice" { |
| 159 | 159 | var ptr = @intToPtr([*]allowzero i32, 0); |
| 160 | 160 | var opt_ptr: ?[*]allowzero i32 = ptr; |
| 161 | expect(opt_ptr != null); | |
| 162 | expect(@ptrToInt(ptr) == 0); | |
| 161 | try expect(opt_ptr != null); | |
| 162 | try expect(@ptrToInt(ptr) == 0); | |
| 163 | 163 | var runtime_zero: usize = 0; |
| 164 | 164 | var slice = ptr[runtime_zero..10]; |
| 165 | comptime expect(@TypeOf(slice) == []allowzero i32); | |
| 166 | expect(@ptrToInt(&slice[5]) == 20); | |
| 165 | comptime try expect(@TypeOf(slice) == []allowzero i32); | |
| 166 | try expect(@ptrToInt(&slice[5]) == 20); | |
| 167 | 167 | |
| 168 | comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); | |
| 169 | comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); | |
| 168 | comptime try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); | |
| 169 | comptime try expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | test "assign null directly to C pointer and test null equality" { |
| 173 | 173 | var x: [*c]i32 = null; |
| 174 | expect(x == null); | |
| 175 | expect(null == x); | |
| 176 | expect(!(x != null)); | |
| 177 | expect(!(null != x)); | |
| 174 | try expect(x == null); | |
| 175 | try expect(null == x); | |
| 176 | try expect(!(x != null)); | |
| 177 | try expect(!(null != x)); | |
| 178 | 178 | if (x) |same_x| { |
| 179 | 179 | @panic("fail"); |
| 180 | 180 | } |
| 181 | 181 | var otherx: i32 = undefined; |
| 182 | expect((x orelse &otherx) == &otherx); | |
| 182 | try expect((x orelse &otherx) == &otherx); | |
| 183 | 183 | |
| 184 | 184 | const y: [*c]i32 = null; |
| 185 | comptime expect(y == null); | |
| 186 | comptime expect(null == y); | |
| 187 | comptime expect(!(y != null)); | |
| 188 | comptime expect(!(null != y)); | |
| 185 | comptime try expect(y == null); | |
| 186 | comptime try expect(null == y); | |
| 187 | comptime try expect(!(y != null)); | |
| 188 | comptime try expect(!(null != y)); | |
| 189 | 189 | if (y) |same_y| @panic("fail"); |
| 190 | 190 | const othery: i32 = undefined; |
| 191 | comptime expect((y orelse &othery) == &othery); | |
| 191 | comptime try expect((y orelse &othery) == &othery); | |
| 192 | 192 | |
| 193 | 193 | var n: i32 = 1234; |
| 194 | 194 | var x1: [*c]i32 = &n; |
| 195 | expect(!(x1 == null)); | |
| 196 | expect(!(null == x1)); | |
| 197 | expect(x1 != null); | |
| 198 | expect(null != x1); | |
| 199 | expect(x1.?.* == 1234); | |
| 195 | try expect(!(x1 == null)); | |
| 196 | try expect(!(null == x1)); | |
| 197 | try expect(x1 != null); | |
| 198 | try expect(null != x1); | |
| 199 | try expect(x1.?.* == 1234); | |
| 200 | 200 | if (x1) |same_x1| { |
| 201 | expect(same_x1.* == 1234); | |
| 201 | try expect(same_x1.* == 1234); | |
| 202 | 202 | } else { |
| 203 | 203 | @panic("fail"); |
| 204 | 204 | } |
| 205 | expect((x1 orelse &otherx) == x1); | |
| 205 | try expect((x1 orelse &otherx) == x1); | |
| 206 | 206 | |
| 207 | 207 | const nc: i32 = 1234; |
| 208 | 208 | const y1: [*c]const i32 = &nc; |
| 209 | comptime expect(!(y1 == null)); | |
| 210 | comptime expect(!(null == y1)); | |
| 211 | comptime expect(y1 != null); | |
| 212 | comptime expect(null != y1); | |
| 213 | comptime expect(y1.?.* == 1234); | |
| 209 | comptime try expect(!(y1 == null)); | |
| 210 | comptime try expect(!(null == y1)); | |
| 211 | comptime try expect(y1 != null); | |
| 212 | comptime try expect(null != y1); | |
| 213 | comptime try expect(y1.?.* == 1234); | |
| 214 | 214 | if (y1) |same_y1| { |
| 215 | expect(same_y1.* == 1234); | |
| 215 | try expect(same_y1.* == 1234); | |
| 216 | 216 | } else { |
| 217 | 217 | @compileError("fail"); |
| 218 | 218 | } |
| 219 | comptime expect((y1 orelse &othery) == y1); | |
| 219 | comptime try expect((y1 orelse &othery) == y1); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | test "null terminated pointer" { |
| 223 | 223 | const S = struct { |
| 224 | fn doTheTest() void { | |
| 224 | fn doTheTest() !void { | |
| 225 | 225 | var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; |
| 226 | 226 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 227 | 227 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 228 | 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(); | |
| 233 | comptime S.doTheTest(); | |
| 232 | try S.doTheTest(); | |
| 233 | comptime try S.doTheTest(); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | test "allow any sentinel" { |
| 237 | 237 | const S = struct { |
| 238 | fn doTheTest() void { | |
| 238 | fn doTheTest() !void { | |
| 239 | 239 | var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; |
| 240 | 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(); | |
| 245 | comptime S.doTheTest(); | |
| 244 | try S.doTheTest(); | |
| 245 | comptime try S.doTheTest(); | |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | test "pointer sentinel with enums" { |
| ... | ... | @@ -253,42 +253,42 @@ test "pointer sentinel with enums" { |
| 253 | 253 | sentinel, |
| 254 | 254 | }; |
| 255 | 255 | |
| 256 | fn doTheTest() void { | |
| 256 | fn doTheTest() !void { | |
| 257 | 257 | var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; |
| 258 | expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731 | |
| 258 | try expect(ptr[4] == .sentinel); // TODO this should be comptime try expect, see #3731 | |
| 259 | 259 | } |
| 260 | 260 | }; |
| 261 | S.doTheTest(); | |
| 262 | comptime S.doTheTest(); | |
| 261 | try S.doTheTest(); | |
| 262 | comptime try S.doTheTest(); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | test "pointer sentinel with optional element" { |
| 266 | 266 | const S = struct { |
| 267 | fn doTheTest() void { | |
| 267 | fn doTheTest() !void { | |
| 268 | 268 | var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; |
| 269 | expect(ptr[4] == null); // TODO this should be comptime expect, see #3731 | |
| 269 | try expect(ptr[4] == null); // TODO this should be comptime try expect, see #3731 | |
| 270 | 270 | } |
| 271 | 271 | }; |
| 272 | S.doTheTest(); | |
| 273 | comptime S.doTheTest(); | |
| 272 | try S.doTheTest(); | |
| 273 | comptime try S.doTheTest(); | |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | test "pointer sentinel with +inf" { |
| 277 | 277 | const S = struct { |
| 278 | fn doTheTest() void { | |
| 278 | fn doTheTest() !void { | |
| 279 | 279 | const inf = std.math.inf_f32; |
| 280 | 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 #3731 | |
| 281 | try expect(ptr[4] == inf); // TODO this should be comptime try expect, see #3731 | |
| 282 | 282 | } |
| 283 | 283 | }; |
| 284 | S.doTheTest(); | |
| 285 | comptime S.doTheTest(); | |
| 284 | try S.doTheTest(); | |
| 285 | comptime try S.doTheTest(); | |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | test "pointer to array at fixed address" { |
| 289 | 289 | const array = @intToPtr(*volatile [1]u32, 0x10); |
| 290 | 290 | // Silly check just to reference `array` |
| 291 | expect(@ptrToInt(&array[0]) == 0x10); | |
| 291 | try expect(@ptrToInt(&array[0]) == 0x10); | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | test "pointer arithmetic affects the alignment" { |
| ... | ... | @@ -296,28 +296,28 @@ test "pointer arithmetic affects the alignment" { |
| 296 | 296 | var ptr: [*]align(8) u32 = undefined; |
| 297 | 297 | var x: usize = 1; |
| 298 | 298 | |
| 299 | expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); | |
| 299 | try expect(@typeInfo(@TypeOf(ptr)).Pointer.alignment == 8); | |
| 300 | 300 | 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 | 302 | 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 | 304 | const ptr3 = ptr + 0; // no-op |
| 305 | expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8); | |
| 305 | try expect(@typeInfo(@TypeOf(ptr3)).Pointer.alignment == 8); | |
| 306 | 306 | 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 | 310 | var ptr: [*]align(8) [3]u8 = undefined; |
| 311 | 311 | var x: usize = 1; |
| 312 | 312 | |
| 313 | 313 | 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 | 315 | 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 | 317 | 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 | 319 | 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 | } |
| 323 | 323 | |
| ... | ... | @@ -325,15 +325,15 @@ test "@ptrToInt on null optional at comptime" { |
| 325 | 325 | { |
| 326 | 326 | const pointer = @intToPtr(?*u8, 0x000); |
| 327 | 327 | const x = @ptrToInt(pointer); |
| 328 | comptime expect(0 == @ptrToInt(pointer)); | |
| 328 | comptime try expect(0 == @ptrToInt(pointer)); | |
| 329 | 329 | } |
| 330 | 330 | { |
| 331 | 331 | const pointer = @intToPtr(?*u8, 0xf00); |
| 332 | comptime expect(0xf00 == @ptrToInt(pointer)); | |
| 332 | comptime try expect(0xf00 == @ptrToInt(pointer)); | |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | test "indexing array with sentinel returns correct type" { |
| 337 | 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/stage1/behavior/popcount.zig+12-12| ... | ... | @@ -1,43 +1,43 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "@popCount" { |
| 4 | comptime testPopCount(); | |
| 5 | testPopCount(); | |
| 4 | comptime try testPopCount(); | |
| 5 | try testPopCount(); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | fn testPopCount() void { | |
| 8 | fn testPopCount() !void { | |
| 9 | 9 | { |
| 10 | 10 | var x: u32 = 0xffffffff; |
| 11 | expect(@popCount(u32, x) == 32); | |
| 11 | try expect(@popCount(u32, x) == 32); | |
| 12 | 12 | } |
| 13 | 13 | { |
| 14 | 14 | var x: u5 = 0x1f; |
| 15 | expect(@popCount(u5, x) == 5); | |
| 15 | try expect(@popCount(u5, x) == 5); | |
| 16 | 16 | } |
| 17 | 17 | { |
| 18 | 18 | var x: u32 = 0xaa; |
| 19 | expect(@popCount(u32, x) == 4); | |
| 19 | try expect(@popCount(u32, x) == 4); | |
| 20 | 20 | } |
| 21 | 21 | { |
| 22 | 22 | var x: u32 = 0xaaaaaaaa; |
| 23 | expect(@popCount(u32, x) == 16); | |
| 23 | try expect(@popCount(u32, x) == 16); | |
| 24 | 24 | } |
| 25 | 25 | { |
| 26 | 26 | var x: u32 = 0xaaaaaaaa; |
| 27 | expect(@popCount(u32, x) == 16); | |
| 27 | try expect(@popCount(u32, x) == 16); | |
| 28 | 28 | } |
| 29 | 29 | { |
| 30 | 30 | var x: i16 = -1; |
| 31 | expect(@popCount(i16, x) == 16); | |
| 31 | try expect(@popCount(i16, x) == 16); | |
| 32 | 32 | } |
| 33 | 33 | { |
| 34 | 34 | var x: i8 = -120; |
| 35 | expect(@popCount(i8, x) == 2); | |
| 35 | try expect(@popCount(i8, x) == 2); | |
| 36 | 36 | } |
| 37 | 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 | 40 | comptime { |
| 41 | expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); | |
| 41 | try expect(@popCount(i128, 0b11111111000110001100010000100001000011000011100101010001) == 24); | |
| 42 | 42 | } |
| 43 | 43 | } |
test/stage1/behavior/ptrcast.zig+12-12| ... | ... | @@ -3,25 +3,25 @@ const builtin = std.builtin; |
| 3 | 3 | const expect = std.testing.expect; |
| 4 | 4 | |
| 5 | 5 | test "reinterpret bytes as integer with nonzero offset" { |
| 6 | testReinterpretBytesAsInteger(); | |
| 7 | comptime testReinterpretBytesAsInteger(); | |
| 6 | try testReinterpretBytesAsInteger(); | |
| 7 | comptime try testReinterpretBytesAsInteger(); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn testReinterpretBytesAsInteger() void { | |
| 10 | fn testReinterpretBytesAsInteger() !void { | |
| 11 | 11 | const bytes = "\x12\x34\x56\x78\xab"; |
| 12 | 12 | const expected = switch (builtin.endian) { |
| 13 | 13 | builtin.Endian.Little => 0xab785634, |
| 14 | 14 | builtin.Endian.Big => 0x345678ab, |
| 15 | 15 | }; |
| 16 | expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected); | |
| 16 | try expect(@ptrCast(*align(1) const u32, bytes[1..5]).* == expected); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "reinterpret bytes of an array into an extern struct" { |
| 20 | testReinterpretBytesAsExternStruct(); | |
| 21 | comptime testReinterpretBytesAsExternStruct(); | |
| 20 | try testReinterpretBytesAsExternStruct(); | |
| 21 | comptime try testReinterpretBytesAsExternStruct(); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | fn testReinterpretBytesAsExternStruct() void { | |
| 24 | fn testReinterpretBytesAsExternStruct() !void { | |
| 25 | 25 | var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 }; |
| 26 | 26 | |
| 27 | 27 | const S = extern struct { |
| ... | ... | @@ -32,15 +32,15 @@ fn testReinterpretBytesAsExternStruct() void { |
| 32 | 32 | |
| 33 | 33 | var ptr = @ptrCast(*const S, &bytes); |
| 34 | 34 | var val = ptr.c; |
| 35 | expect(val == 5); | |
| 35 | try expect(val == 5); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "reinterpret struct field at comptime" { |
| 39 | 39 | const numNative = comptime Bytes.init(0x12345678); |
| 40 | 40 | if (builtin.endian != .Little) { |
| 41 | expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); | |
| 41 | try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); | |
| 42 | 42 | } else { |
| 43 | expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); | |
| 43 | try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); | |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| ... | ... | @@ -59,7 +59,7 @@ test "comptime ptrcast keeps larger alignment" { |
| 59 | 59 | comptime { |
| 60 | 60 | const a: u32 = 1234; |
| 61 | 61 | const p = @ptrCast([*]const u8, &a); |
| 62 | std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8); | |
| 62 | try expect(@TypeOf(p) == [*]align(@alignOf(u32)) const u8); | |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| ... | ... | @@ -68,5 +68,5 @@ test "implicit optional pointer to optional c_void pointer" { |
| 68 | 68 | var x: ?[*]u8 = &buf; |
| 69 | 69 | var y: ?*c_void = x; |
| 70 | 70 | var z = @ptrCast(*[4]u8, y); |
| 71 | expect(std.mem.eql(u8, z, "aoeu")); | |
| 71 | try expect(std.mem.eql(u8, z, "aoeu")); | |
| 72 | 72 | } |
test/stage1/behavior/pub_enum.zig+4-4| ... | ... | @@ -2,12 +2,12 @@ const other = @import("pub_enum/other.zig"); |
| 2 | 2 | const expect = @import("std").testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "pub enum" { |
| 5 | pubEnumTest(other.APubEnum.Two); | |
| 5 | try pubEnumTest(other.APubEnum.Two); | |
| 6 | 6 | } |
| 7 | fn pubEnumTest(foo: other.APubEnum) void { | |
| 8 | expect(foo == other.APubEnum.Two); | |
| 7 | fn pubEnumTest(foo: other.APubEnum) !void { | |
| 8 | try expect(foo == other.APubEnum.Two); | |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | test "cast with imported symbol" { |
| 12 | expect(@as(other.size_t, 42) == 42); | |
| 12 | try expect(@as(other.size_t, 42) == 42); | |
| 13 | 13 | } |
test/stage1/behavior/ref_var_in_if_after_if_2nd_switch_prong.zig+10-10| ... | ... | @@ -3,12 +3,12 @@ const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | 4 | var ok: bool = false; |
| 5 | 5 | test "reference a variable in an if after an if in the 2nd switch prong" { |
| 6 | foo(true, Num.Two, false, "aoeu"); | |
| 7 | expect(!ok); | |
| 8 | foo(false, Num.One, false, "aoeu"); | |
| 9 | expect(!ok); | |
| 10 | foo(true, Num.One, false, "aoeu"); | |
| 11 | expect(ok); | |
| 6 | try foo(true, Num.Two, false, "aoeu"); | |
| 7 | try expect(!ok); | |
| 8 | try foo(false, Num.One, false, "aoeu"); | |
| 9 | try expect(!ok); | |
| 10 | try foo(true, Num.One, false, "aoeu"); | |
| 11 | try expect(ok); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | const Num = enum { |
| ... | ... | @@ -16,7 +16,7 @@ const Num = enum { |
| 16 | 16 | Two, |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | fn foo(c: bool, k: Num, c2: bool, b: []const u8) void { | |
| 19 | fn foo(c: bool, k: Num, c2: bool, b: []const u8) !void { | |
| 20 | 20 | switch (k) { |
| 21 | 21 | Num.Two => {}, |
| 22 | 22 | Num.One => { |
| ... | ... | @@ -25,13 +25,13 @@ fn foo(c: bool, k: Num, c2: bool, b: []const u8) void { |
| 25 | 25 | |
| 26 | 26 | if (c2) {} |
| 27 | 27 | |
| 28 | a(output_path); | |
| 28 | try a(output_path); | |
| 29 | 29 | } |
| 30 | 30 | }, |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | fn a(x: []const u8) void { | |
| 35 | expect(mem.eql(u8, x, "aoeu")); | |
| 34 | fn a(x: []const u8) !void { | |
| 35 | try expect(mem.eql(u8, x, "aoeu")); | |
| 36 | 36 | ok = true; |
| 37 | 37 | } |
test/stage1/behavior/reflection.zig+17-17| ... | ... | @@ -5,12 +5,12 @@ const reflection = @This(); |
| 5 | 5 | test "reflection: function return type, var args, and param types" { |
| 6 | 6 | comptime { |
| 7 | 7 | const info = @typeInfo(@TypeOf(dummy)).Fn; |
| 8 | expect(info.return_type.? == i32); | |
| 9 | expect(!info.is_var_args); | |
| 10 | expect(info.args.len == 3); | |
| 11 | expect(info.args[0].arg_type.? == bool); | |
| 12 | expect(info.args[1].arg_type.? == i32); | |
| 13 | expect(info.args[2].arg_type.? == f32); | |
| 8 | try expect(info.return_type.? == i32); | |
| 9 | try expect(!info.is_var_args); | |
| 10 | try expect(info.args.len == 3); | |
| 11 | try expect(info.args[0].arg_type.? == bool); | |
| 12 | try expect(info.args[1].arg_type.? == i32); | |
| 13 | try expect(info.args[2].arg_type.? == f32); | |
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | |
| ... | ... | @@ -25,18 +25,18 @@ test "reflection: @field" { |
| 25 | 25 | .three = void{}, |
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | expect(f.one == f.one); | |
| 29 | expect(@field(f, "o" ++ "ne") == f.one); | |
| 30 | expect(@field(f, "t" ++ "wo") == f.two); | |
| 31 | expect(@field(f, "th" ++ "ree") == f.three); | |
| 32 | expect(@field(Foo, "const" ++ "ant") == Foo.constant); | |
| 33 | expect(@field(Bar, "O" ++ "ne") == Bar.One); | |
| 34 | expect(@field(Bar, "T" ++ "wo") == Bar.Two); | |
| 35 | expect(@field(Bar, "Th" ++ "ree") == Bar.Three); | |
| 36 | expect(@field(Bar, "F" ++ "our") == Bar.Four); | |
| 37 | expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2)); | |
| 28 | try expect(f.one == f.one); | |
| 29 | try expect(@field(f, "o" ++ "ne") == f.one); | |
| 30 | try expect(@field(f, "t" ++ "wo") == f.two); | |
| 31 | try expect(@field(f, "th" ++ "ree") == f.three); | |
| 32 | try expect(@field(Foo, "const" ++ "ant") == Foo.constant); | |
| 33 | try expect(@field(Bar, "O" ++ "ne") == Bar.One); | |
| 34 | try expect(@field(Bar, "T" ++ "wo") == Bar.Two); | |
| 35 | try expect(@field(Bar, "Th" ++ "ree") == Bar.Three); | |
| 36 | try expect(@field(Bar, "F" ++ "our") == Bar.Four); | |
| 37 | try expect(@field(reflection, "dum" ++ "my")(true, 1, 2) == dummy(true, 1, 2)); | |
| 38 | 38 | @field(f, "o" ++ "ne") = 4; |
| 39 | expect(f.one == 4); | |
| 39 | try expect(f.one == 4); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | const Foo = struct { |
test/stage1/behavior/shuffle.zig+10-10| ... | ... | @@ -9,33 +9,33 @@ test "@shuffle" { |
| 9 | 9 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 10 | 10 | |
| 11 | 11 | const S = struct { |
| 12 | fn doTheTest() void { | |
| 12 | fn doTheTest() !void { | |
| 13 | 13 | var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 14 | 14 | var x: Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; |
| 15 | 15 | const mask: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; |
| 16 | 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 })); | |
| 18 | 18 | |
| 19 | 19 | // Implicit cast from array (of mask) |
| 20 | 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 })); | |
| 22 | 22 | |
| 23 | 23 | // Undefined |
| 24 | 24 | const mask2: Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; |
| 25 | 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 })); | |
| 27 | 27 | |
| 28 | 28 | // Upcasting of b |
| 29 | 29 | var v2: Vector(2, i32) = [2]i32{ 2147483647, undefined }; |
| 30 | 30 | const mask3: Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; |
| 31 | 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 })); | |
| 33 | 33 | |
| 34 | 34 | // Upcasting of a |
| 35 | 35 | var v3: Vector(2, i32) = [2]i32{ 2147483647, -2 }; |
| 36 | 36 | const mask4: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; |
| 37 | 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 })); | |
| 39 | 39 | |
| 40 | 40 | // bool |
| 41 | 41 | // Disabled because of #3317 |
| ... | ... | @@ -44,7 +44,7 @@ test "@shuffle" { |
| 44 | 44 | var v4: Vector(2, bool) = [2]bool{ true, false }; |
| 45 | 45 | const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 46 | 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 | } |
| 49 | 49 | |
| 50 | 50 | // TODO re-enable when LLVM codegen is fixed |
| ... | ... | @@ -54,10 +54,10 @@ test "@shuffle" { |
| 54 | 54 | var v4: Vector(2, bool) = [2]bool{ true, false }; |
| 55 | 55 | const mask5: Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; |
| 56 | 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(); | |
| 62 | comptime S.doTheTest(); | |
| 61 | try S.doTheTest(); | |
| 62 | comptime try S.doTheTest(); | |
| 63 | 63 | } |
test/stage1/behavior/sizeof_and_typeof.zig+75-75| ... | ... | @@ -5,7 +5,7 @@ const expectEqual = std.testing.expectEqual; |
| 5 | 5 | |
| 6 | 6 | test "@sizeOf and @TypeOf" { |
| 7 | 7 | const y: @TypeOf(x) = 120; |
| 8 | expect(@sizeOf(@TypeOf(y)) == 2); | |
| 8 | try expect(@sizeOf(@TypeOf(y)) == 2); | |
| 9 | 9 | } |
| 10 | 10 | const x: u16 = 13; |
| 11 | 11 | const z: @TypeOf(x) = 19; |
| ... | ... | @@ -36,27 +36,27 @@ const P = packed struct { |
| 36 | 36 | |
| 37 | 37 | test "@byteOffsetOf" { |
| 38 | 38 | // Packed structs have fixed memory layout |
| 39 | expect(@byteOffsetOf(P, "a") == 0); | |
| 40 | expect(@byteOffsetOf(P, "b") == 1); | |
| 41 | expect(@byteOffsetOf(P, "c") == 5); | |
| 42 | expect(@byteOffsetOf(P, "d") == 6); | |
| 43 | expect(@byteOffsetOf(P, "e") == 6); | |
| 44 | expect(@byteOffsetOf(P, "f") == 7); | |
| 45 | expect(@byteOffsetOf(P, "g") == 9); | |
| 46 | expect(@byteOffsetOf(P, "h") == 11); | |
| 47 | expect(@byteOffsetOf(P, "i") == 12); | |
| 39 | try expect(@byteOffsetOf(P, "a") == 0); | |
| 40 | try expect(@byteOffsetOf(P, "b") == 1); | |
| 41 | try expect(@byteOffsetOf(P, "c") == 5); | |
| 42 | try expect(@byteOffsetOf(P, "d") == 6); | |
| 43 | try expect(@byteOffsetOf(P, "e") == 6); | |
| 44 | try expect(@byteOffsetOf(P, "f") == 7); | |
| 45 | try expect(@byteOffsetOf(P, "g") == 9); | |
| 46 | try expect(@byteOffsetOf(P, "h") == 11); | |
| 47 | try expect(@byteOffsetOf(P, "i") == 12); | |
| 48 | 48 | |
| 49 | 49 | // Normal struct fields can be moved/padded |
| 50 | 50 | var a: A = undefined; |
| 51 | expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a")); | |
| 52 | expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b")); | |
| 53 | expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c")); | |
| 54 | expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d")); | |
| 55 | expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e")); | |
| 56 | expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f")); | |
| 57 | expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g")); | |
| 58 | expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h")); | |
| 59 | expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i")); | |
| 51 | try expect(@ptrToInt(&a.a) - @ptrToInt(&a) == @byteOffsetOf(A, "a")); | |
| 52 | try expect(@ptrToInt(&a.b) - @ptrToInt(&a) == @byteOffsetOf(A, "b")); | |
| 53 | try expect(@ptrToInt(&a.c) - @ptrToInt(&a) == @byteOffsetOf(A, "c")); | |
| 54 | try expect(@ptrToInt(&a.d) - @ptrToInt(&a) == @byteOffsetOf(A, "d")); | |
| 55 | try expect(@ptrToInt(&a.e) - @ptrToInt(&a) == @byteOffsetOf(A, "e")); | |
| 56 | try expect(@ptrToInt(&a.f) - @ptrToInt(&a) == @byteOffsetOf(A, "f")); | |
| 57 | try expect(@ptrToInt(&a.g) - @ptrToInt(&a) == @byteOffsetOf(A, "g")); | |
| 58 | try expect(@ptrToInt(&a.h) - @ptrToInt(&a) == @byteOffsetOf(A, "h")); | |
| 59 | try expect(@ptrToInt(&a.i) - @ptrToInt(&a) == @byteOffsetOf(A, "i")); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | test "@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 | 65 | a: [p3a_len]u8, |
| 66 | 66 | b: usize, |
| 67 | 67 | }; |
| 68 | std.testing.expectEqual(0, @byteOffsetOf(P3, "a")); | |
| 69 | std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b")); | |
| 68 | try std.testing.expectEqual(0, @byteOffsetOf(P3, "a")); | |
| 69 | try std.testing.expectEqual(p3a_len, @byteOffsetOf(P3, "b")); | |
| 70 | 70 | |
| 71 | 71 | const p5a_len = 5; |
| 72 | 72 | const P5 = packed struct { |
| 73 | 73 | a: [p5a_len]u8, |
| 74 | 74 | b: usize, |
| 75 | 75 | }; |
| 76 | std.testing.expectEqual(0, @byteOffsetOf(P5, "a")); | |
| 77 | std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b")); | |
| 76 | try std.testing.expectEqual(0, @byteOffsetOf(P5, "a")); | |
| 77 | try std.testing.expectEqual(p5a_len, @byteOffsetOf(P5, "b")); | |
| 78 | 78 | |
| 79 | 79 | const p6a_len = 6; |
| 80 | 80 | const P6 = packed struct { |
| 81 | 81 | a: [p6a_len]u8, |
| 82 | 82 | b: usize, |
| 83 | 83 | }; |
| 84 | std.testing.expectEqual(0, @byteOffsetOf(P6, "a")); | |
| 85 | std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b")); | |
| 84 | try std.testing.expectEqual(0, @byteOffsetOf(P6, "a")); | |
| 85 | try std.testing.expectEqual(p6a_len, @byteOffsetOf(P6, "b")); | |
| 86 | 86 | |
| 87 | 87 | const p7a_len = 7; |
| 88 | 88 | const P7 = packed struct { |
| 89 | 89 | a: [p7a_len]u8, |
| 90 | 90 | b: usize, |
| 91 | 91 | }; |
| 92 | std.testing.expectEqual(0, @byteOffsetOf(P7, "a")); | |
| 93 | std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b")); | |
| 92 | try std.testing.expectEqual(0, @byteOffsetOf(P7, "a")); | |
| 93 | try std.testing.expectEqual(p7a_len, @byteOffsetOf(P7, "b")); | |
| 94 | 94 | |
| 95 | 95 | const p9a_len = 9; |
| 96 | 96 | const P9 = packed struct { |
| 97 | 97 | a: [p9a_len]u8, |
| 98 | 98 | b: usize, |
| 99 | 99 | }; |
| 100 | std.testing.expectEqual(0, @byteOffsetOf(P9, "a")); | |
| 101 | std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b")); | |
| 100 | try std.testing.expectEqual(0, @byteOffsetOf(P9, "a")); | |
| 101 | try std.testing.expectEqual(p9a_len, @byteOffsetOf(P9, "b")); | |
| 102 | 102 | |
| 103 | 103 | // 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25 etc. are further cases |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | test "@bitOffsetOf" { |
| 107 | 107 | // Packed structs have fixed memory layout |
| 108 | expect(@bitOffsetOf(P, "a") == 0); | |
| 109 | expect(@bitOffsetOf(P, "b") == 8); | |
| 110 | expect(@bitOffsetOf(P, "c") == 40); | |
| 111 | expect(@bitOffsetOf(P, "d") == 48); | |
| 112 | expect(@bitOffsetOf(P, "e") == 51); | |
| 113 | expect(@bitOffsetOf(P, "f") == 56); | |
| 114 | expect(@bitOffsetOf(P, "g") == 72); | |
| 108 | try expect(@bitOffsetOf(P, "a") == 0); | |
| 109 | try expect(@bitOffsetOf(P, "b") == 8); | |
| 110 | try expect(@bitOffsetOf(P, "c") == 40); | |
| 111 | try expect(@bitOffsetOf(P, "d") == 48); | |
| 112 | try expect(@bitOffsetOf(P, "e") == 51); | |
| 113 | try expect(@bitOffsetOf(P, "f") == 56); | |
| 114 | try expect(@bitOffsetOf(P, "g") == 72); | |
| 115 | 115 | |
| 116 | expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a")); | |
| 117 | expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b")); | |
| 118 | expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c")); | |
| 119 | expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d")); | |
| 120 | expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e")); | |
| 121 | expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f")); | |
| 122 | expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g")); | |
| 116 | try expect(@byteOffsetOf(A, "a") * 8 == @bitOffsetOf(A, "a")); | |
| 117 | try expect(@byteOffsetOf(A, "b") * 8 == @bitOffsetOf(A, "b")); | |
| 118 | try expect(@byteOffsetOf(A, "c") * 8 == @bitOffsetOf(A, "c")); | |
| 119 | try expect(@byteOffsetOf(A, "d") * 8 == @bitOffsetOf(A, "d")); | |
| 120 | try expect(@byteOffsetOf(A, "e") * 8 == @bitOffsetOf(A, "e")); | |
| 121 | try expect(@byteOffsetOf(A, "f") * 8 == @bitOffsetOf(A, "f")); | |
| 122 | try expect(@byteOffsetOf(A, "g") * 8 == @bitOffsetOf(A, "g")); | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | test "@sizeOf on compile-time types" { |
| 126 | expect(@sizeOf(comptime_int) == 0); | |
| 127 | expect(@sizeOf(comptime_float) == 0); | |
| 128 | expect(@sizeOf(@TypeOf(.hi)) == 0); | |
| 129 | expect(@sizeOf(@TypeOf(type)) == 0); | |
| 126 | try expect(@sizeOf(comptime_int) == 0); | |
| 127 | try expect(@sizeOf(comptime_float) == 0); | |
| 128 | try expect(@sizeOf(@TypeOf(.hi)) == 0); | |
| 129 | try expect(@sizeOf(@TypeOf(type)) == 0); | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | 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 | }; |
| 142 | 142 | |
| 143 | expect(@sizeOf(S.Foo) == 4); | |
| 144 | expect(@sizeOf(S.Bar) == 8); | |
| 143 | try expect(@sizeOf(S.Foo) == 4); | |
| 144 | try expect(@sizeOf(S.Bar) == 8); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | test "@TypeOf() has no runtime side effects" { |
| ... | ... | @@ -153,8 +153,8 @@ test "@TypeOf() has no runtime side effects" { |
| 153 | 153 | }; |
| 154 | 154 | var data: i32 = 0; |
| 155 | 155 | const T = @TypeOf(S.foo(i32, &data)); |
| 156 | comptime expect(T == i32); | |
| 157 | expect(data == 0); | |
| 156 | comptime try expect(T == i32); | |
| 157 | try expect(data == 0); | |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | test "@TypeOf() with multiple arguments" { |
| ... | ... | @@ -162,21 +162,21 @@ test "@TypeOf() with multiple arguments" { |
| 162 | 162 | var var_1: u32 = undefined; |
| 163 | 163 | var var_2: u8 = undefined; |
| 164 | 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 | 168 | var var_1: f16 = undefined; |
| 169 | 169 | var var_2: f32 = undefined; |
| 170 | 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 | 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 | 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 | } |
| 182 | 182 | |
| ... | ... | @@ -189,8 +189,8 @@ test "branching logic inside @TypeOf" { |
| 189 | 189 | } |
| 190 | 190 | }; |
| 191 | 191 | const T = @TypeOf(S.foo() catch undefined); |
| 192 | comptime expect(T == i32); | |
| 193 | expect(S.data == 0); | |
| 192 | comptime try expect(T == i32); | |
| 193 | try expect(S.data == 0); | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | fn fn1(alpha: bool) void { |
| ... | ... | @@ -203,12 +203,12 @@ test "lazy @sizeOf result is checked for definedness" { |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | test "@bitSizeOf" { |
| 206 | expect(@bitSizeOf(u2) == 2); | |
| 207 | expect(@bitSizeOf(u8) == @sizeOf(u8) * 8); | |
| 208 | expect(@bitSizeOf(struct { | |
| 206 | try expect(@bitSizeOf(u2) == 2); | |
| 207 | try expect(@bitSizeOf(u8) == @sizeOf(u8) * 8); | |
| 208 | try expect(@bitSizeOf(struct { | |
| 209 | 209 | a: u2, |
| 210 | 210 | }) == 8); |
| 211 | expect(@bitSizeOf(packed struct { | |
| 211 | try expect(@bitSizeOf(packed struct { | |
| 212 | 212 | a: u2, |
| 213 | 213 | }) == 2); |
| 214 | 214 | } |
| ... | ... | @@ -241,24 +241,24 @@ test "@sizeOf comparison against zero" { |
| 241 | 241 | f2: H(***@This()), |
| 242 | 242 | }; |
| 243 | 243 | const S = struct { |
| 244 | fn doTheTest(comptime T: type, comptime result: bool) void { | |
| 245 | expectEqual(result, @sizeOf(T) > 0); | |
| 244 | fn doTheTest(comptime T: type, comptime result: bool) !void { | |
| 245 | try expectEqual(result, @sizeOf(T) > 0); | |
| 246 | 246 | } |
| 247 | 247 | }; |
| 248 | 248 | // Zero-sized type |
| 249 | S.doTheTest(u0, false); | |
| 250 | S.doTheTest(*u0, false); | |
| 249 | try S.doTheTest(u0, false); | |
| 250 | try S.doTheTest(*u0, false); | |
| 251 | 251 | // Non byte-sized type |
| 252 | S.doTheTest(u1, true); | |
| 253 | S.doTheTest(*u1, true); | |
| 252 | try S.doTheTest(u1, true); | |
| 253 | try S.doTheTest(*u1, true); | |
| 254 | 254 | // Regular type |
| 255 | S.doTheTest(u8, true); | |
| 256 | S.doTheTest(*u8, true); | |
| 257 | S.doTheTest(f32, true); | |
| 258 | S.doTheTest(*f32, true); | |
| 255 | try S.doTheTest(u8, true); | |
| 256 | try S.doTheTest(*u8, true); | |
| 257 | try S.doTheTest(f32, true); | |
| 258 | try S.doTheTest(*f32, true); | |
| 259 | 259 | // Container with ptr pointing to themselves |
| 260 | S.doTheTest(S0, true); | |
| 261 | S.doTheTest(U0, true); | |
| 262 | S.doTheTest(S1, true); | |
| 263 | S.doTheTest(U1, true); | |
| 260 | try S.doTheTest(S0, true); | |
| 261 | try S.doTheTest(U0, true); | |
| 262 | try S.doTheTest(S1, true); | |
| 263 | try S.doTheTest(U1, true); | |
| 264 | 264 | } |
test/stage1/behavior/slice.zig+119-119| ... | ... | @@ -7,11 +7,11 @@ const mem = std.mem; |
| 7 | 7 | const x = @intToPtr([*]i32, 0x1000)[0..0x500]; |
| 8 | 8 | const y = x[0x100..]; |
| 9 | 9 | test "compile time slice of pointer to hard coded address" { |
| 10 | expect(@ptrToInt(x) == 0x1000); | |
| 11 | expect(x.len == 0x500); | |
| 10 | try expect(@ptrToInt(x) == 0x1000); | |
| 11 | try expect(x.len == 0x500); | |
| 12 | 12 | |
| 13 | expect(@ptrToInt(y) == 0x1100); | |
| 14 | expect(y.len == 0x400); | |
| 13 | try expect(@ptrToInt(y) == 0x1100); | |
| 14 | try expect(y.len == 0x400); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | test "runtime safety lets us slice from len..len" { |
| ... | ... | @@ -20,7 +20,7 @@ test "runtime safety lets us slice from len..len" { |
| 20 | 20 | 2, |
| 21 | 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 | } |
| 25 | 25 | |
| 26 | 26 | fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { |
| ... | ... | @@ -29,18 +29,18 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { |
| 29 | 29 | |
| 30 | 30 | test "implicitly cast array of size 0 to slice" { |
| 31 | 31 | var msg = [_]u8{}; |
| 32 | assertLenIsZero(&msg); | |
| 32 | try assertLenIsZero(&msg); | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | fn assertLenIsZero(msg: []const u8) void { | |
| 36 | expect(msg.len == 0); | |
| 35 | fn assertLenIsZero(msg: []const u8) !void { | |
| 36 | try expect(msg.len == 0); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "C pointer" { |
| 40 | 40 | var buf: [*c]const u8 = "kjdhfkjdhfdkjhfkfjhdfkjdhfkdjhfdkjhf"; |
| 41 | 41 | var len: u32 = 10; |
| 42 | 42 | var slice = buf[0..len]; |
| 43 | expectEqualSlices(u8, "kjdhfkjdhf", slice); | |
| 43 | try expectEqualSlices(u8, "kjdhfkjdhf", slice); | |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | test "C pointer slice access" { |
| ... | ... | @@ -48,11 +48,11 @@ test "C pointer slice access" { |
| 48 | 48 | const c_ptr = @ptrCast([*c]const u32, &buf); |
| 49 | 49 | |
| 50 | 50 | var runtime_zero: usize = 0; |
| 51 | comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); | |
| 52 | comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); | |
| 51 | comptime try expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); | |
| 52 | comptime try expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); | |
| 53 | 53 | |
| 54 | 54 | for (c_ptr[0..5]) |*cl| { |
| 55 | expectEqual(@as(u32, 42), cl.*); | |
| 55 | try expectEqual(@as(u32, 42), cl.*); | |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| ... | ... | @@ -65,8 +65,8 @@ fn sliceSum(comptime q: []const u8) i32 { |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | test "comptime slices are disambiguated" { |
| 68 | expect(sliceSum(&[_]u8{ 1, 2 }) == 3); | |
| 69 | expect(sliceSum(&[_]u8{ 3, 4 }) == 7); | |
| 68 | try expect(sliceSum(&[_]u8{ 1, 2 }) == 3); | |
| 69 | try expect(sliceSum(&[_]u8{ 3, 4 }) == 7); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | test "slice type with custom alignment" { |
| ... | ... | @@ -77,20 +77,20 @@ test "slice type with custom alignment" { |
| 77 | 77 | var array: [10]LazilyResolvedType align(32) = undefined; |
| 78 | 78 | slice = &array; |
| 79 | 79 | slice[1].anything = 42; |
| 80 | expect(array[1].anything == 42); | |
| 80 | try expect(array[1].anything == 42); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "access len index of sentinel-terminated slice" { |
| 84 | 84 | const S = struct { |
| 85 | fn doTheTest() void { | |
| 85 | fn doTheTest() !void { | |
| 86 | 86 | var slice: [:0]const u8 = "hello"; |
| 87 | 87 | |
| 88 | expect(slice.len == 5); | |
| 89 | expect(slice[5] == 0); | |
| 88 | try expect(slice.len == 5); | |
| 89 | try expect(slice[5] == 0); | |
| 90 | 90 | } |
| 91 | 91 | }; |
| 92 | S.doTheTest(); | |
| 93 | comptime S.doTheTest(); | |
| 92 | try S.doTheTest(); | |
| 93 | comptime try S.doTheTest(); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "obtaining a null terminated slice" { |
| ... | ... | @@ -108,230 +108,230 @@ test "obtaining a null terminated slice" { |
| 108 | 108 | var runtime_len: usize = 3; |
| 109 | 109 | const ptr2 = buf[0..runtime_len :0]; |
| 110 | 110 | // ptr2 is a null-terminated slice |
| 111 | comptime expect(@TypeOf(ptr2) == [:0]u8); | |
| 112 | comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); | |
| 111 | comptime try expect(@TypeOf(ptr2) == [:0]u8); | |
| 112 | comptime try expect(@TypeOf(ptr2[0..2]) == *[2]u8); | |
| 113 | 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 | } |
| 116 | 116 | |
| 117 | 117 | test "empty array to slice" { |
| 118 | 118 | const S = struct { |
| 119 | fn doTheTest() void { | |
| 119 | fn doTheTest() !void { | |
| 120 | 120 | const empty: []align(16) u8 = &[_]u8{}; |
| 121 | 121 | const align_1: []align(1) u8 = empty; |
| 122 | 122 | const align_4: []align(4) u8 = empty; |
| 123 | 123 | const align_16: []align(16) u8 = empty; |
| 124 | expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment); | |
| 125 | expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment); | |
| 126 | expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment); | |
| 124 | try expectEqual(1, @typeInfo(@TypeOf(align_1)).Pointer.alignment); | |
| 125 | try expectEqual(4, @typeInfo(@TypeOf(align_4)).Pointer.alignment); | |
| 126 | try expectEqual(16, @typeInfo(@TypeOf(align_16)).Pointer.alignment); | |
| 127 | 127 | } |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | S.doTheTest(); | |
| 131 | comptime S.doTheTest(); | |
| 130 | try S.doTheTest(); | |
| 131 | comptime try S.doTheTest(); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | test "@ptrCast slice to pointer" { |
| 135 | 135 | const S = struct { |
| 136 | fn doTheTest() void { | |
| 136 | fn doTheTest() !void { | |
| 137 | 137 | var array align(@alignOf(u16)) = [5]u8{ 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 138 | 138 | var slice: []u8 = &array; |
| 139 | 139 | var ptr = @ptrCast(*u16, slice); |
| 140 | expect(ptr.* == 65535); | |
| 140 | try expect(ptr.* == 65535); | |
| 141 | 141 | } |
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | S.doTheTest(); | |
| 145 | comptime S.doTheTest(); | |
| 144 | try S.doTheTest(); | |
| 145 | comptime try S.doTheTest(); | |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | test "slice syntax resulting in pointer-to-array" { |
| 149 | 149 | const S = struct { |
| 150 | fn doTheTest() void { | |
| 151 | testArray(); | |
| 152 | testArrayZ(); | |
| 153 | testArray0(); | |
| 154 | testArrayAlign(); | |
| 155 | testPointer(); | |
| 156 | testPointerZ(); | |
| 157 | testPointer0(); | |
| 158 | testPointerAlign(); | |
| 159 | testSlice(); | |
| 160 | testSliceZ(); | |
| 161 | testSlice0(); | |
| 162 | testSliceOpt(); | |
| 163 | testSliceAlign(); | |
| 150 | fn doTheTest() !void { | |
| 151 | try testArray(); | |
| 152 | try testArrayZ(); | |
| 153 | try testArray0(); | |
| 154 | try testArrayAlign(); | |
| 155 | try testPointer(); | |
| 156 | try testPointerZ(); | |
| 157 | try testPointer0(); | |
| 158 | try testPointerAlign(); | |
| 159 | try testSlice(); | |
| 160 | try testSliceZ(); | |
| 161 | try testSlice0(); | |
| 162 | try testSliceOpt(); | |
| 163 | try testSliceAlign(); | |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | fn testArray() void { | |
| 166 | fn testArray() !void { | |
| 167 | 167 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 168 | 168 | var slice = array[1..3]; |
| 169 | comptime expect(@TypeOf(slice) == *[2]u8); | |
| 170 | expect(slice[0] == 2); | |
| 171 | expect(slice[1] == 3); | |
| 169 | comptime try expect(@TypeOf(slice) == *[2]u8); | |
| 170 | try expect(slice[0] == 2); | |
| 171 | try expect(slice[1] == 3); | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | fn testArrayZ() void { | |
| 174 | fn testArrayZ() !void { | |
| 175 | 175 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 176 | comptime expect(@TypeOf(array[1..3]) == *[2]u8); | |
| 177 | comptime expect(@TypeOf(array[1..5]) == *[4:0]u8); | |
| 178 | comptime expect(@TypeOf(array[1..]) == *[4:0]u8); | |
| 179 | comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8); | |
| 176 | comptime try expect(@TypeOf(array[1..3]) == *[2]u8); | |
| 177 | comptime try expect(@TypeOf(array[1..5]) == *[4:0]u8); | |
| 178 | comptime try expect(@TypeOf(array[1..]) == *[4:0]u8); | |
| 179 | comptime try expect(@TypeOf(array[1..3 :4]) == *[2:4]u8); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | fn testArray0() void { | |
| 182 | fn testArray0() !void { | |
| 183 | 183 | { |
| 184 | 184 | var array = [0]u8{}; |
| 185 | 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 | 189 | var array = [0:0]u8{}; |
| 190 | 190 | var slice = array[0..0]; |
| 191 | comptime expect(@TypeOf(slice) == *[0:0]u8); | |
| 192 | expect(slice[0] == 0); | |
| 191 | comptime try expect(@TypeOf(slice) == *[0:0]u8); | |
| 192 | try expect(slice[0] == 0); | |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | fn testArrayAlign() void { | |
| 196 | fn testArrayAlign() !void { | |
| 197 | 197 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 198 | 198 | var slice = array[4..5]; |
| 199 | comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 200 | expect(slice[0] == 5); | |
| 201 | comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); | |
| 199 | comptime try expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 200 | try expect(slice[0] == 5); | |
| 201 | comptime try expect(@TypeOf(array[0..2]) == *align(4) [2]u8); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | fn testPointer() void { | |
| 204 | fn testPointer() !void { | |
| 205 | 205 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 206 | 206 | var pointer: [*]u8 = &array; |
| 207 | 207 | var slice = pointer[1..3]; |
| 208 | comptime expect(@TypeOf(slice) == *[2]u8); | |
| 209 | expect(slice[0] == 2); | |
| 210 | expect(slice[1] == 3); | |
| 208 | comptime try expect(@TypeOf(slice) == *[2]u8); | |
| 209 | try expect(slice[0] == 2); | |
| 210 | try expect(slice[1] == 3); | |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | fn testPointerZ() void { | |
| 213 | fn testPointerZ() !void { | |
| 214 | 214 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 215 | 215 | var pointer: [*:0]u8 = &array; |
| 216 | comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 217 | comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 216 | comptime try expect(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 217 | comptime try expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | fn testPointer0() void { | |
| 220 | fn testPointer0() !void { | |
| 221 | 221 | var pointer: [*]const u0 = &[1]u0{0}; |
| 222 | 222 | var slice = pointer[0..1]; |
| 223 | comptime expect(@TypeOf(slice) == *const [1]u0); | |
| 224 | expect(slice[0] == 0); | |
| 223 | comptime try expect(@TypeOf(slice) == *const [1]u0); | |
| 224 | try expect(slice[0] == 0); | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | fn testPointerAlign() void { | |
| 227 | fn testPointerAlign() !void { | |
| 228 | 228 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 229 | 229 | var pointer: [*]align(4) u8 = &array; |
| 230 | 230 | var slice = pointer[4..5]; |
| 231 | comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 232 | expect(slice[0] == 5); | |
| 233 | comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); | |
| 231 | comptime try expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 232 | try expect(slice[0] == 5); | |
| 233 | comptime try expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | fn testSlice() void { | |
| 236 | fn testSlice() !void { | |
| 237 | 237 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 238 | 238 | var src_slice: []u8 = &array; |
| 239 | 239 | var slice = src_slice[1..3]; |
| 240 | comptime expect(@TypeOf(slice) == *[2]u8); | |
| 241 | expect(slice[0] == 2); | |
| 242 | expect(slice[1] == 3); | |
| 240 | comptime try expect(@TypeOf(slice) == *[2]u8); | |
| 241 | try expect(slice[0] == 2); | |
| 242 | try expect(slice[1] == 3); | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | fn testSliceZ() void { | |
| 245 | fn testSliceZ() !void { | |
| 246 | 246 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 247 | 247 | var slice: [:0]u8 = &array; |
| 248 | comptime expect(@TypeOf(slice[1..3]) == *[2]u8); | |
| 249 | comptime expect(@TypeOf(slice[1..]) == [:0]u8); | |
| 250 | comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 248 | comptime try expect(@TypeOf(slice[1..3]) == *[2]u8); | |
| 249 | comptime try expect(@TypeOf(slice[1..]) == [:0]u8); | |
| 250 | comptime try expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | fn testSliceOpt() void { | |
| 253 | fn testSliceOpt() !void { | |
| 254 | 254 | var array: [2]u8 = [2]u8{ 1, 2 }; |
| 255 | 255 | var slice: ?[]u8 = &array; |
| 256 | comptime expect(@TypeOf(&array, slice) == ?[]u8); | |
| 257 | comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8); | |
| 256 | comptime try expect(@TypeOf(&array, slice) == ?[]u8); | |
| 257 | comptime try expect(@TypeOf(slice.?[0..2]) == *[2]u8); | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | fn testSlice0() void { | |
| 260 | fn testSlice0() !void { | |
| 261 | 261 | { |
| 262 | 262 | var array = [0]u8{}; |
| 263 | 263 | var src_slice: []u8 = &array; |
| 264 | 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 | 268 | var array = [0:0]u8{}; |
| 269 | 269 | var src_slice: [:0]u8 = &array; |
| 270 | 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 | } |
| 274 | 274 | |
| 275 | fn testSliceAlign() void { | |
| 275 | fn testSliceAlign() !void { | |
| 276 | 276 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 277 | 277 | var src_slice: []align(4) u8 = &array; |
| 278 | 278 | var slice = src_slice[4..5]; |
| 279 | comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 280 | expect(slice[0] == 5); | |
| 281 | comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); | |
| 279 | comptime try expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 280 | try expect(slice[0] == 5); | |
| 281 | comptime try expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); | |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | fn testConcatStrLiterals() void { | |
| 285 | expectEqualSlices("a"[0..] ++ "b"[0..], "ab"); | |
| 286 | expectEqualSlices("a"[0..:0] ++ "b"[0..:0], "ab"); | |
| 284 | fn testConcatStrLiterals() !void { | |
| 285 | try expectEqualSlices("a"[0..] ++ "b"[0..], "ab"); | |
| 286 | try expectEqualSlices("a"[0.. :0] ++ "b"[0.. :0], "ab"); | |
| 287 | 287 | } |
| 288 | 288 | }; |
| 289 | 289 | |
| 290 | S.doTheTest(); | |
| 291 | comptime S.doTheTest(); | |
| 290 | try S.doTheTest(); | |
| 291 | comptime try S.doTheTest(); | |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | test "slice of hardcoded address to pointer" { |
| 295 | 295 | const S = struct { |
| 296 | fn doTheTest() void { | |
| 296 | fn doTheTest() !void { | |
| 297 | 297 | const pointer = @intToPtr([*]u8, 0x04)[0..2]; |
| 298 | comptime expect(@TypeOf(pointer) == *[2]u8); | |
| 298 | comptime try expect(@TypeOf(pointer) == *[2]u8); | |
| 299 | 299 | const slice: []const u8 = pointer; |
| 300 | expect(@ptrToInt(slice.ptr) == 4); | |
| 301 | expect(slice.len == 2); | |
| 300 | try expect(@ptrToInt(slice.ptr) == 4); | |
| 301 | try expect(slice.len == 2); | |
| 302 | 302 | } |
| 303 | 303 | }; |
| 304 | 304 | |
| 305 | S.doTheTest(); | |
| 305 | try S.doTheTest(); | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | test "type coercion of pointer to anon struct literal to pointer to slice" { |
| 309 | 309 | const S = struct { |
| 310 | const U = union{ | |
| 310 | const U = union { | |
| 311 | 311 | a: u32, |
| 312 | 312 | b: bool, |
| 313 | 313 | c: []const u8, |
| 314 | 314 | }; |
| 315 | 315 | |
| 316 | fn doTheTest() void { | |
| 316 | fn doTheTest() !void { | |
| 317 | 317 | var x1: u8 = 42; |
| 318 | 318 | const t1 = &.{ x1, 56, 54 }; |
| 319 | 319 | var slice1: []const u8 = t1; |
| 320 | expect(slice1.len == 3); | |
| 321 | expect(slice1[0] == 42); | |
| 322 | expect(slice1[1] == 56); | |
| 323 | expect(slice1[2] == 54); | |
| 324 | ||
| 320 | try expect(slice1.len == 3); | |
| 321 | try expect(slice1[0] == 42); | |
| 322 | try expect(slice1[1] == 56); | |
| 323 | try expect(slice1[2] == 54); | |
| 324 | ||
| 325 | 325 | var x2: []const u8 = "hello"; |
| 326 | 326 | const t2 = &.{ x2, ", ", "world!" }; |
| 327 | 327 | // @compileLog(@TypeOf(t2)); |
| 328 | 328 | var slice2: []const []const u8 = t2; |
| 329 | expect(slice2.len == 3); | |
| 330 | expect(mem.eql(u8, slice2[0], "hello")); | |
| 331 | expect(mem.eql(u8, slice2[1], ", ")); | |
| 332 | expect(mem.eql(u8, slice2[2], "world!")); | |
| 329 | try expect(slice2.len == 3); | |
| 330 | try expect(mem.eql(u8, slice2[0], "hello")); | |
| 331 | try expect(mem.eql(u8, slice2[1], ", ")); | |
| 332 | try expect(mem.eql(u8, slice2[2], "world!")); | |
| 333 | 333 | } |
| 334 | 334 | }; |
| 335 | // S.doTheTest(); | |
| 336 | comptime S.doTheTest(); | |
| 335 | // try S.doTheTest(); | |
| 336 | comptime try S.doTheTest(); | |
| 337 | 337 | } |
test/stage1/behavior/src.zig+8-8| ... | ... | @@ -2,16 +2,16 @@ const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "@src" { |
| 5 | doTheTest(); | |
| 5 | try doTheTest(); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | fn doTheTest() void { | |
| 8 | fn doTheTest() !void { | |
| 9 | 9 | const src = @src(); |
| 10 | 10 | |
| 11 | expect(src.line == 9); | |
| 12 | expect(src.column == 17); | |
| 13 | expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); | |
| 14 | expect(std.mem.endsWith(u8, src.file, "src.zig")); | |
| 15 | expect(src.fn_name[src.fn_name.len] == 0); | |
| 16 | expect(src.file[src.file.len] == 0); | |
| 11 | try expect(src.line == 9); | |
| 12 | try expect(src.column == 17); | |
| 13 | try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); | |
| 14 | try expect(std.mem.endsWith(u8, src.file, "src.zig")); | |
| 15 | try expect(src.fn_name[src.fn_name.len] == 0); | |
| 16 | try expect(src.file[src.file.len] == 0); | |
| 17 | 17 | } |
test/stage1/behavior/struct.zig+191-190| ... | ... | @@ -18,12 +18,12 @@ test "top level fields" { |
| 18 | 18 | .top_level_field = 1234, |
| 19 | 19 | }; |
| 20 | 20 | instance.top_level_field += 1; |
| 21 | expectEqual(@as(i32, 1235), instance.top_level_field); | |
| 21 | try expectEqual(@as(i32, 1235), instance.top_level_field); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | test "call struct static method" { |
| 25 | 25 | const result = StructWithNoFields.add(3, 4); |
| 26 | expect(result == 7); | |
| 26 | try expect(result == 7); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | test "return empty struct instance" { |
| ... | ... | @@ -36,7 +36,7 @@ fn returnEmptyStructInstance() StructWithNoFields { |
| 36 | 36 | const should_be_11 = StructWithNoFields.add(5, 6); |
| 37 | 37 | |
| 38 | 38 | test "invoke static method in global scope" { |
| 39 | expect(should_be_11 == 11); | |
| 39 | try expect(should_be_11 == 11); | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | test "void struct fields" { |
| ... | ... | @@ -45,8 +45,8 @@ test "void struct fields" { |
| 45 | 45 | .b = 1, |
| 46 | 46 | .c = void{}, |
| 47 | 47 | }; |
| 48 | expect(foo.b == 1); | |
| 49 | expect(@sizeOf(VoidStructFieldsFoo) == 4); | |
| 48 | try expect(foo.b == 1); | |
| 49 | try expect(@sizeOf(VoidStructFieldsFoo) == 4); | |
| 50 | 50 | } |
| 51 | 51 | const VoidStructFieldsFoo = struct { |
| 52 | 52 | a: void, |
| ... | ... | @@ -59,17 +59,17 @@ test "structs" { |
| 59 | 59 | @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo)); |
| 60 | 60 | foo.a += 1; |
| 61 | 61 | foo.b = foo.a == 1; |
| 62 | testFoo(foo); | |
| 62 | try testFoo(foo); | |
| 63 | 63 | testMutation(&foo); |
| 64 | expect(foo.c == 100); | |
| 64 | try expect(foo.c == 100); | |
| 65 | 65 | } |
| 66 | 66 | const StructFoo = struct { |
| 67 | 67 | a: i32, |
| 68 | 68 | b: bool, |
| 69 | 69 | c: f32, |
| 70 | 70 | }; |
| 71 | fn testFoo(foo: StructFoo) void { | |
| 72 | expect(foo.b); | |
| 71 | fn testFoo(foo: StructFoo) !void { | |
| 72 | try expect(foo.b); | |
| 73 | 73 | } |
| 74 | 74 | fn testMutation(foo: *StructFoo) void { |
| 75 | 75 | foo.c = 100; |
| ... | ... | @@ -94,7 +94,7 @@ test "struct point to self" { |
| 94 | 94 | |
| 95 | 95 | root.next = &node; |
| 96 | 96 | |
| 97 | expect(node.next.next.next.val.x == 1); | |
| 97 | try expect(node.next.next.next.val.x == 1); | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | test "struct byval assign" { |
| ... | ... | @@ -103,14 +103,14 @@ test "struct byval assign" { |
| 103 | 103 | |
| 104 | 104 | foo1.a = 1234; |
| 105 | 105 | foo2.a = 0; |
| 106 | expect(foo2.a == 0); | |
| 106 | try expect(foo2.a == 0); | |
| 107 | 107 | foo2 = foo1; |
| 108 | expect(foo2.a == 1234); | |
| 108 | try expect(foo2.a == 1234); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | fn structInitializer() void { |
| 112 | 112 | const val = Val{ .x = 42 }; |
| 113 | expect(val.x == 42); | |
| 113 | try expect(val.x == 42); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | test "fn call of struct field" { |
| ... | ... | @@ -127,14 +127,14 @@ test "fn call of struct field" { |
| 127 | 127 | } |
| 128 | 128 | }; |
| 129 | 129 | |
| 130 | expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13); | |
| 130 | try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13); | |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | test "store member function in variable" { |
| 134 | 134 | const instance = MemberFnTestFoo{ .x = 1234 }; |
| 135 | 135 | const memberFn = MemberFnTestFoo.member; |
| 136 | 136 | const result = memberFn(instance); |
| 137 | expect(result == 1234); | |
| 137 | try expect(result == 1234); | |
| 138 | 138 | } |
| 139 | 139 | const MemberFnTestFoo = struct { |
| 140 | 140 | x: i32, |
| ... | ... | @@ -146,12 +146,12 @@ const MemberFnTestFoo = struct { |
| 146 | 146 | test "call member function directly" { |
| 147 | 147 | const instance = MemberFnTestFoo{ .x = 1234 }; |
| 148 | 148 | const result = MemberFnTestFoo.member(instance); |
| 149 | expect(result == 1234); | |
| 149 | try expect(result == 1234); | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | test "member functions" { |
| 153 | 153 | const r = MemberFnRand{ .seed = 1234 }; |
| 154 | expect(r.getSeed() == 1234); | |
| 154 | try expect(r.getSeed() == 1234); | |
| 155 | 155 | } |
| 156 | 156 | const MemberFnRand = struct { |
| 157 | 157 | seed: u32, |
| ... | ... | @@ -162,7 +162,7 @@ const MemberFnRand = struct { |
| 162 | 162 | |
| 163 | 163 | test "return struct byval from function" { |
| 164 | 164 | const bar = makeBar(1234, 5678); |
| 165 | expect(bar.y == 5678); | |
| 165 | try expect(bar.y == 5678); | |
| 166 | 166 | } |
| 167 | 167 | const Bar = struct { |
| 168 | 168 | x: i32, |
| ... | ... | @@ -177,7 +177,7 @@ fn makeBar(x: i32, y: i32) Bar { |
| 177 | 177 | |
| 178 | 178 | test "empty struct method call" { |
| 179 | 179 | const es = EmptyStruct{}; |
| 180 | expect(es.method() == 1234); | |
| 180 | try expect(es.method() == 1234); | |
| 181 | 181 | } |
| 182 | 182 | const EmptyStruct = struct { |
| 183 | 183 | fn method(es: *const EmptyStruct) i32 { |
| ... | ... | @@ -194,7 +194,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 { |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | test "pass slice of empty struct to fn" { |
| 197 | expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1); | |
| 197 | try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1); | |
| 198 | 198 | } |
| 199 | 199 | fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize { |
| 200 | 200 | return slice.len; |
| ... | ... | @@ -212,7 +212,7 @@ test "packed struct" { |
| 212 | 212 | }; |
| 213 | 213 | foo.y += 1; |
| 214 | 214 | const four = foo.x + foo.y; |
| 215 | expect(four == 4); | |
| 215 | try expect(four == 4); | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | const BitField1 = packed struct { |
| ... | ... | @@ -229,17 +229,17 @@ const bit_field_1 = BitField1{ |
| 229 | 229 | |
| 230 | 230 | test "bit field access" { |
| 231 | 231 | var data = bit_field_1; |
| 232 | expect(getA(&data) == 1); | |
| 233 | expect(getB(&data) == 2); | |
| 234 | expect(getC(&data) == 3); | |
| 235 | comptime expect(@sizeOf(BitField1) == 1); | |
| 232 | try expect(getA(&data) == 1); | |
| 233 | try expect(getB(&data) == 2); | |
| 234 | try expect(getC(&data) == 3); | |
| 235 | comptime try expect(@sizeOf(BitField1) == 1); | |
| 236 | 236 | |
| 237 | 237 | data.b += 1; |
| 238 | expect(data.b == 3); | |
| 238 | try expect(data.b == 3); | |
| 239 | 239 | |
| 240 | 240 | data.a += 1; |
| 241 | expect(data.a == 2); | |
| 242 | expect(data.b == 3); | |
| 241 | try expect(data.a == 2); | |
| 242 | try expect(data.b == 3); | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | fn getA(data: *const BitField1) u3 { |
| ... | ... | @@ -266,11 +266,11 @@ const Foo96Bits = packed struct { |
| 266 | 266 | |
| 267 | 267 | test "packed struct 24bits" { |
| 268 | 268 | comptime { |
| 269 | expect(@sizeOf(Foo24Bits) == 4); | |
| 269 | try expect(@sizeOf(Foo24Bits) == 4); | |
| 270 | 270 | if (@sizeOf(usize) == 4) { |
| 271 | expect(@sizeOf(Foo96Bits) == 12); | |
| 271 | try expect(@sizeOf(Foo96Bits) == 12); | |
| 272 | 272 | } else { |
| 273 | expect(@sizeOf(Foo96Bits) == 16); | |
| 273 | try expect(@sizeOf(Foo96Bits) == 16); | |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| ... | ... | @@ -281,28 +281,28 @@ test "packed struct 24bits" { |
| 281 | 281 | .d = 0, |
| 282 | 282 | }; |
| 283 | 283 | value.a += 1; |
| 284 | expect(value.a == 1); | |
| 285 | expect(value.b == 0); | |
| 286 | expect(value.c == 0); | |
| 287 | expect(value.d == 0); | |
| 284 | try expect(value.a == 1); | |
| 285 | try expect(value.b == 0); | |
| 286 | try expect(value.c == 0); | |
| 287 | try expect(value.d == 0); | |
| 288 | 288 | |
| 289 | 289 | value.b += 1; |
| 290 | expect(value.a == 1); | |
| 291 | expect(value.b == 1); | |
| 292 | expect(value.c == 0); | |
| 293 | expect(value.d == 0); | |
| 290 | try expect(value.a == 1); | |
| 291 | try expect(value.b == 1); | |
| 292 | try expect(value.c == 0); | |
| 293 | try expect(value.d == 0); | |
| 294 | 294 | |
| 295 | 295 | value.c += 1; |
| 296 | expect(value.a == 1); | |
| 297 | expect(value.b == 1); | |
| 298 | expect(value.c == 1); | |
| 299 | expect(value.d == 0); | |
| 296 | try expect(value.a == 1); | |
| 297 | try expect(value.b == 1); | |
| 298 | try expect(value.c == 1); | |
| 299 | try expect(value.d == 0); | |
| 300 | 300 | |
| 301 | 301 | value.d += 1; |
| 302 | expect(value.a == 1); | |
| 303 | expect(value.b == 1); | |
| 304 | expect(value.c == 1); | |
| 305 | expect(value.d == 1); | |
| 302 | try expect(value.a == 1); | |
| 303 | try expect(value.b == 1); | |
| 304 | try expect(value.c == 1); | |
| 305 | try expect(value.d == 1); | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | const Foo32Bits = packed struct { |
| ... | ... | @@ -319,43 +319,43 @@ const FooArray24Bits = packed struct { |
| 319 | 319 | // TODO revisit this test when doing https://github.com/ziglang/zig/issues/1512 |
| 320 | 320 | test "packed array 24bits" { |
| 321 | 321 | comptime { |
| 322 | expect(@sizeOf([9]Foo32Bits) == 9 * 4); | |
| 323 | expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2); | |
| 322 | try expect(@sizeOf([9]Foo32Bits) == 9 * 4); | |
| 323 | try expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2); | |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1); |
| 327 | 327 | bytes[bytes.len - 1] = 0xaa; |
| 328 | 328 | const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; |
| 329 | expect(ptr.a == 0); | |
| 330 | expect(ptr.b[0].field == 0); | |
| 331 | expect(ptr.b[1].field == 0); | |
| 332 | expect(ptr.c == 0); | |
| 329 | try expect(ptr.a == 0); | |
| 330 | try expect(ptr.b[0].field == 0); | |
| 331 | try expect(ptr.b[1].field == 0); | |
| 332 | try expect(ptr.c == 0); | |
| 333 | 333 | |
| 334 | 334 | ptr.a = maxInt(u16); |
| 335 | expect(ptr.a == maxInt(u16)); | |
| 336 | expect(ptr.b[0].field == 0); | |
| 337 | expect(ptr.b[1].field == 0); | |
| 338 | expect(ptr.c == 0); | |
| 335 | try expect(ptr.a == maxInt(u16)); | |
| 336 | try expect(ptr.b[0].field == 0); | |
| 337 | try expect(ptr.b[1].field == 0); | |
| 338 | try expect(ptr.c == 0); | |
| 339 | 339 | |
| 340 | 340 | ptr.b[0].field = maxInt(u24); |
| 341 | expect(ptr.a == maxInt(u16)); | |
| 342 | expect(ptr.b[0].field == maxInt(u24)); | |
| 343 | expect(ptr.b[1].field == 0); | |
| 344 | expect(ptr.c == 0); | |
| 341 | try expect(ptr.a == maxInt(u16)); | |
| 342 | try expect(ptr.b[0].field == maxInt(u24)); | |
| 343 | try expect(ptr.b[1].field == 0); | |
| 344 | try expect(ptr.c == 0); | |
| 345 | 345 | |
| 346 | 346 | ptr.b[1].field = maxInt(u24); |
| 347 | expect(ptr.a == maxInt(u16)); | |
| 348 | expect(ptr.b[0].field == maxInt(u24)); | |
| 349 | expect(ptr.b[1].field == maxInt(u24)); | |
| 350 | expect(ptr.c == 0); | |
| 347 | try expect(ptr.a == maxInt(u16)); | |
| 348 | try expect(ptr.b[0].field == maxInt(u24)); | |
| 349 | try expect(ptr.b[1].field == maxInt(u24)); | |
| 350 | try expect(ptr.c == 0); | |
| 351 | 351 | |
| 352 | 352 | ptr.c = maxInt(u16); |
| 353 | expect(ptr.a == maxInt(u16)); | |
| 354 | expect(ptr.b[0].field == maxInt(u24)); | |
| 355 | expect(ptr.b[1].field == maxInt(u24)); | |
| 356 | expect(ptr.c == maxInt(u16)); | |
| 353 | try expect(ptr.a == maxInt(u16)); | |
| 354 | try expect(ptr.b[0].field == maxInt(u24)); | |
| 355 | try expect(ptr.b[1].field == maxInt(u24)); | |
| 356 | try expect(ptr.c == maxInt(u16)); | |
| 357 | 357 | |
| 358 | expect(bytes[bytes.len - 1] == 0xaa); | |
| 358 | try expect(bytes[bytes.len - 1] == 0xaa); | |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | const FooStructAligned = packed struct { |
| ... | ... | @@ -369,17 +369,17 @@ const FooArrayOfAligned = packed struct { |
| 369 | 369 | |
| 370 | 370 | test "aligned array of packed struct" { |
| 371 | 371 | comptime { |
| 372 | expect(@sizeOf(FooStructAligned) == 2); | |
| 373 | expect(@sizeOf(FooArrayOfAligned) == 2 * 2); | |
| 372 | try expect(@sizeOf(FooStructAligned) == 2); | |
| 373 | try expect(@sizeOf(FooArrayOfAligned) == 2 * 2); | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned); |
| 377 | 377 | const ptr = &std.mem.bytesAsSlice(FooArrayOfAligned, bytes[0..])[0]; |
| 378 | 378 | |
| 379 | expect(ptr.a[0].a == 0xbb); | |
| 380 | expect(ptr.a[0].b == 0xbb); | |
| 381 | expect(ptr.a[1].a == 0xbb); | |
| 382 | expect(ptr.a[1].b == 0xbb); | |
| 379 | try expect(ptr.a[0].a == 0xbb); | |
| 380 | try expect(ptr.a[0].b == 0xbb); | |
| 381 | try expect(ptr.a[1].a == 0xbb); | |
| 382 | try expect(ptr.a[1].b == 0xbb); | |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | test "runtime struct initialization of bitfield" { |
| ... | ... | @@ -392,10 +392,10 @@ test "runtime struct initialization of bitfield" { |
| 392 | 392 | .y = @intCast(u4, x2), |
| 393 | 393 | }; |
| 394 | 394 | |
| 395 | expect(s1.x == x1); | |
| 396 | expect(s1.y == x1); | |
| 397 | expect(s2.x == @intCast(u4, x2)); | |
| 398 | expect(s2.y == @intCast(u4, x2)); | |
| 395 | try expect(s1.x == x1); | |
| 396 | try expect(s1.y == x1); | |
| 397 | try expect(s2.x == @intCast(u4, x2)); | |
| 398 | try expect(s2.y == @intCast(u4, x2)); | |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | var x1 = @as(u4, 1); |
| ... | ... | @@ -425,18 +425,18 @@ test "native bit field understands endianness" { |
| 425 | 425 | @memcpy(&bytes, @ptrCast([*]u8, &all), 8); |
| 426 | 426 | var bitfields = @ptrCast(*Bitfields, &bytes).*; |
| 427 | 427 | |
| 428 | expect(bitfields.f1 == 0x1111); | |
| 429 | expect(bitfields.f2 == 0x2222); | |
| 430 | expect(bitfields.f3 == 0x33); | |
| 431 | expect(bitfields.f4 == 0x44); | |
| 432 | expect(bitfields.f5 == 0x5); | |
| 433 | expect(bitfields.f6 == 0x6); | |
| 434 | expect(bitfields.f7 == 0x77); | |
| 428 | try expect(bitfields.f1 == 0x1111); | |
| 429 | try expect(bitfields.f2 == 0x2222); | |
| 430 | try expect(bitfields.f3 == 0x33); | |
| 431 | try expect(bitfields.f4 == 0x44); | |
| 432 | try expect(bitfields.f5 == 0x5); | |
| 433 | try expect(bitfields.f6 == 0x6); | |
| 434 | try expect(bitfields.f7 == 0x77); | |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | test "align 1 field before self referential align 8 field as slice return type" { |
| 438 | 438 | const result = alloc(Expr); |
| 439 | expect(result.len == 0); | |
| 439 | try expect(result.len == 0); | |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | const Expr = union(enum) { |
| ... | ... | @@ -459,10 +459,10 @@ test "call method with mutable reference to struct with no fields" { |
| 459 | 459 | }; |
| 460 | 460 | |
| 461 | 461 | var s = S{}; |
| 462 | expect(S.doC(&s)); | |
| 463 | expect(s.doC()); | |
| 464 | expect(S.do(&s)); | |
| 465 | expect(s.do()); | |
| 462 | try expect(S.doC(&s)); | |
| 463 | try expect(s.doC()); | |
| 464 | try expect(S.do(&s)); | |
| 465 | try expect(s.do()); | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | test "implicit cast packed struct field to const ptr" { |
| ... | ... | @@ -478,7 +478,7 @@ test "implicit cast packed struct field to const ptr" { |
| 478 | 478 | var lup: LevelUpMove = undefined; |
| 479 | 479 | lup.level = 12; |
| 480 | 480 | const res = LevelUpMove.toInt(lup.level); |
| 481 | expect(res == 12); | |
| 481 | try expect(res == 12); | |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | test "pointer to packed struct member in a stack variable" { |
| ... | ... | @@ -489,9 +489,9 @@ test "pointer to packed struct member in a stack variable" { |
| 489 | 489 | |
| 490 | 490 | var s = S{ .a = 2, .b = 0 }; |
| 491 | 491 | var b_ptr = &s.b; |
| 492 | expect(s.b == 0); | |
| 492 | try expect(s.b == 0); | |
| 493 | 493 | b_ptr.* = 2; |
| 494 | expect(s.b == 2); | |
| 494 | try expect(s.b == 2); | |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | test "non-byte-aligned array inside packed struct" { |
| ... | ... | @@ -500,20 +500,20 @@ test "non-byte-aligned array inside packed struct" { |
| 500 | 500 | b: [0x16]u8, |
| 501 | 501 | }; |
| 502 | 502 | const S = struct { |
| 503 | fn bar(slice: []const u8) void { | |
| 504 | expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu"); | |
| 503 | fn bar(slice: []const u8) !void { | |
| 504 | try expectEqualSlices(u8, slice, "abcdefghijklmnopqurstu"); | |
| 505 | 505 | } |
| 506 | fn doTheTest() void { | |
| 506 | fn doTheTest() !void { | |
| 507 | 507 | var foo = Foo{ |
| 508 | 508 | .a = true, |
| 509 | 509 | .b = "abcdefghijklmnopqurstu".*, |
| 510 | 510 | }; |
| 511 | 511 | const value = foo.b; |
| 512 | bar(&value); | |
| 512 | try bar(&value); | |
| 513 | 513 | } |
| 514 | 514 | }; |
| 515 | S.doTheTest(); | |
| 516 | comptime S.doTheTest(); | |
| 515 | try S.doTheTest(); | |
| 516 | comptime try S.doTheTest(); | |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | test "packed struct with u0 field access" { |
| ... | ... | @@ -521,7 +521,7 @@ test "packed struct with u0 field access" { |
| 521 | 521 | f0: u0, |
| 522 | 522 | }; |
| 523 | 523 | var s = S{ .f0 = 0 }; |
| 524 | comptime expect(s.f0 == 0); | |
| 524 | comptime try expect(s.f0 == 0); | |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | const S0 = struct { |
| ... | ... | @@ -540,7 +540,7 @@ var g_foo: S0 = S0.init(); |
| 540 | 540 | |
| 541 | 541 | test "access to global struct fields" { |
| 542 | 542 | g_foo.bar.value = 42; |
| 543 | expect(g_foo.bar.value == 42); | |
| 543 | try expect(g_foo.bar.value == 42); | |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | test "packed struct with fp fields" { |
| ... | ... | @@ -559,9 +559,9 @@ test "packed struct with fp fields" { |
| 559 | 559 | s.data[1] = 2.0; |
| 560 | 560 | s.data[2] = 3.0; |
| 561 | 561 | s.frob(); |
| 562 | expectEqual(@as(f32, 6.0), s.data[0]); | |
| 563 | expectEqual(@as(f32, 11.0), s.data[1]); | |
| 564 | expectEqual(@as(f32, 20.0), s.data[2]); | |
| 562 | try expectEqual(@as(f32, 6.0), s.data[0]); | |
| 563 | try expectEqual(@as(f32, 11.0), s.data[1]); | |
| 564 | try expectEqual(@as(f32, 20.0), s.data[2]); | |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | test "use within struct scope" { |
| ... | ... | @@ -572,7 +572,7 @@ test "use within struct scope" { |
| 572 | 572 | } |
| 573 | 573 | }; |
| 574 | 574 | }; |
| 575 | expectEqual(@as(i32, 42), S.inner()); | |
| 575 | try expectEqual(@as(i32, 42), S.inner()); | |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | test "default struct initialization fields" { |
| ... | ... | @@ -590,14 +590,14 @@ test "default struct initialization fields" { |
| 590 | 590 | const y = S{ |
| 591 | 591 | .b = five, |
| 592 | 592 | }; |
| 593 | expectEqual(1239, x.a + x.b); | |
| 593 | try expectEqual(1239, x.a + x.b); | |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | test "fn with C calling convention returns struct by value" { |
| 597 | 597 | const S = struct { |
| 598 | fn entry() void { | |
| 598 | fn entry() !void { | |
| 599 | 599 | var x = makeBar(10); |
| 600 | expectEqual(@as(i32, 10), x.handle); | |
| 600 | try expectEqual(@as(i32, 10), x.handle); | |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | const ExternBar = extern struct { |
| ... | ... | @@ -610,8 +610,8 @@ test "fn with C calling convention returns struct by value" { |
| 610 | 610 | }; |
| 611 | 611 | } |
| 612 | 612 | }; |
| 613 | S.entry(); | |
| 614 | comptime S.entry(); | |
| 613 | try S.entry(); | |
| 614 | comptime try S.entry(); | |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | test "for loop over pointers to struct, getting field from struct pointer" { |
| ... | ... | @@ -632,7 +632,7 @@ test "for loop over pointers to struct, getting field from struct pointer" { |
| 632 | 632 | } |
| 633 | 633 | }; |
| 634 | 634 | |
| 635 | fn doTheTest() void { | |
| 635 | fn doTheTest() !void { | |
| 636 | 636 | var objects: ArrayList = undefined; |
| 637 | 637 | |
| 638 | 638 | for (objects.toSlice()) |obj| { |
| ... | ... | @@ -641,10 +641,10 @@ test "for loop over pointers to struct, getting field from struct pointer" { |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | expect(ok); | |
| 644 | try expect(ok); | |
| 645 | 645 | } |
| 646 | 646 | }; |
| 647 | S.doTheTest(); | |
| 647 | try S.doTheTest(); | |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | test "zero-bit field in packed struct" { |
| ... | ... | @@ -657,20 +657,20 @@ test "zero-bit field in packed struct" { |
| 657 | 657 | |
| 658 | 658 | test "struct field init with catch" { |
| 659 | 659 | const S = struct { |
| 660 | fn doTheTest() void { | |
| 660 | fn doTheTest() !void { | |
| 661 | 661 | var x: anyerror!isize = 1; |
| 662 | 662 | var req = Foo{ |
| 663 | 663 | .field = x catch undefined, |
| 664 | 664 | }; |
| 665 | expect(req.field == 1); | |
| 665 | try expect(req.field == 1); | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | pub const Foo = extern struct { |
| 669 | 669 | field: isize, |
| 670 | 670 | }; |
| 671 | 671 | }; |
| 672 | S.doTheTest(); | |
| 673 | comptime S.doTheTest(); | |
| 672 | try S.doTheTest(); | |
| 673 | comptime try S.doTheTest(); | |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | test "packed struct with non-ABI-aligned field" { |
| ... | ... | @@ -681,8 +681,8 @@ test "packed struct with non-ABI-aligned field" { |
| 681 | 681 | var s: S = undefined; |
| 682 | 682 | s.x = 1; |
| 683 | 683 | s.y = 42; |
| 684 | expect(s.x == 1); | |
| 685 | expect(s.y == 42); | |
| 684 | try expect(s.x == 1); | |
| 685 | try expect(s.y == 42); | |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | test "non-packed struct with u128 entry in union" { |
| ... | ... | @@ -698,10 +698,10 @@ test "non-packed struct with u128 entry in union" { |
| 698 | 698 | |
| 699 | 699 | var sx: S = undefined; |
| 700 | 700 | var s = &sx; |
| 701 | std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2")); | |
| 701 | try std.testing.expect(@ptrToInt(&s.f2) - @ptrToInt(&s.f1) == @byteOffsetOf(S, "f2")); | |
| 702 | 702 | var v2 = U{ .Num = 123 }; |
| 703 | 703 | s.f2 = v2; |
| 704 | std.testing.expect(s.f2.Num == 123); | |
| 704 | try std.testing.expect(s.f2.Num == 123); | |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | test "packed struct field passed to generic function" { |
| ... | ... | @@ -721,7 +721,7 @@ test "packed struct field passed to generic function" { |
| 721 | 721 | var p: S.P = undefined; |
| 722 | 722 | p.b = 29; |
| 723 | 723 | var loaded = S.genericReadPackedField(&p.b); |
| 724 | expect(loaded == 29); | |
| 724 | try expect(loaded == 29); | |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | test "anonymous struct literal syntax" { |
| ... | ... | @@ -731,63 +731,63 @@ test "anonymous struct literal syntax" { |
| 731 | 731 | y: i32, |
| 732 | 732 | }; |
| 733 | 733 | |
| 734 | fn doTheTest() void { | |
| 734 | fn doTheTest() !void { | |
| 735 | 735 | var p: Point = .{ |
| 736 | 736 | .x = 1, |
| 737 | 737 | .y = 2, |
| 738 | 738 | }; |
| 739 | expect(p.x == 1); | |
| 740 | expect(p.y == 2); | |
| 739 | try expect(p.x == 1); | |
| 740 | try expect(p.y == 2); | |
| 741 | 741 | } |
| 742 | 742 | }; |
| 743 | S.doTheTest(); | |
| 744 | comptime S.doTheTest(); | |
| 743 | try S.doTheTest(); | |
| 744 | comptime try S.doTheTest(); | |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | test "fully anonymous struct" { |
| 748 | 748 | const S = struct { |
| 749 | fn doTheTest() void { | |
| 750 | dump(.{ | |
| 749 | fn doTheTest() !void { | |
| 750 | try dump(.{ | |
| 751 | 751 | .int = @as(u32, 1234), |
| 752 | 752 | .float = @as(f64, 12.34), |
| 753 | 753 | .b = true, |
| 754 | 754 | .s = "hi", |
| 755 | 755 | }); |
| 756 | 756 | } |
| 757 | fn dump(args: anytype) void { | |
| 758 | expect(args.int == 1234); | |
| 759 | expect(args.float == 12.34); | |
| 760 | expect(args.b); | |
| 761 | expect(args.s[0] == 'h'); | |
| 762 | expect(args.s[1] == 'i'); | |
| 757 | fn dump(args: anytype) !void { | |
| 758 | try expect(args.int == 1234); | |
| 759 | try expect(args.float == 12.34); | |
| 760 | try expect(args.b); | |
| 761 | try expect(args.s[0] == 'h'); | |
| 762 | try expect(args.s[1] == 'i'); | |
| 763 | 763 | } |
| 764 | 764 | }; |
| 765 | S.doTheTest(); | |
| 766 | comptime S.doTheTest(); | |
| 765 | try S.doTheTest(); | |
| 766 | comptime try S.doTheTest(); | |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | test "fully anonymous list literal" { |
| 770 | 770 | const S = struct { |
| 771 | fn doTheTest() void { | |
| 772 | dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" }); | |
| 771 | fn doTheTest() !void { | |
| 772 | try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" }); | |
| 773 | 773 | } |
| 774 | fn dump(args: anytype) void { | |
| 775 | expect(args.@"0" == 1234); | |
| 776 | expect(args.@"1" == 12.34); | |
| 777 | expect(args.@"2"); | |
| 778 | expect(args.@"3"[0] == 'h'); | |
| 779 | expect(args.@"3"[1] == 'i'); | |
| 774 | fn dump(args: anytype) !void { | |
| 775 | try expect(args.@"0" == 1234); | |
| 776 | try expect(args.@"1" == 12.34); | |
| 777 | try expect(args.@"2"); | |
| 778 | try expect(args.@"3"[0] == 'h'); | |
| 779 | try expect(args.@"3"[1] == 'i'); | |
| 780 | 780 | } |
| 781 | 781 | }; |
| 782 | S.doTheTest(); | |
| 783 | comptime S.doTheTest(); | |
| 782 | try S.doTheTest(); | |
| 783 | comptime try S.doTheTest(); | |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | test "anonymous struct literal assigned to variable" { |
| 787 | 787 | var vec = .{ @as(i32, 22), @as(i32, 55), @as(i32, 99) }; |
| 788 | expect(vec.@"0" == 22); | |
| 789 | expect(vec.@"1" == 55); | |
| 790 | expect(vec.@"2" == 99); | |
| 788 | try expect(vec.@"0" == 22); | |
| 789 | try expect(vec.@"1" == 55); | |
| 790 | try expect(vec.@"2" == 99); | |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | test "struct with var field" { |
| ... | ... | @@ -799,8 +799,8 @@ test "struct with var field" { |
| 799 | 799 | .x = 1, |
| 800 | 800 | .y = 2, |
| 801 | 801 | }; |
| 802 | expect(pt.x == 1); | |
| 803 | expect(pt.y == 2); | |
| 802 | try expect(pt.x == 1); | |
| 803 | try expect(pt.y == 2); | |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | test "comptime struct field" { |
| ... | ... | @@ -810,21 +810,21 @@ test "comptime struct field" { |
| 810 | 810 | }; |
| 811 | 811 | |
| 812 | 812 | var foo: T = undefined; |
| 813 | comptime expect(foo.b == 1234); | |
| 813 | comptime try expect(foo.b == 1234); | |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | test "anon struct literal field value initialized with fn call" { |
| 817 | 817 | const S = struct { |
| 818 | fn doTheTest() void { | |
| 818 | fn doTheTest() !void { | |
| 819 | 819 | var x = .{foo()}; |
| 820 | expectEqualSlices(u8, x[0], "hi"); | |
| 820 | try expectEqualSlices(u8, x[0], "hi"); | |
| 821 | 821 | } |
| 822 | 822 | fn foo() []const u8 { |
| 823 | 823 | return "hi"; |
| 824 | 824 | } |
| 825 | 825 | }; |
| 826 | S.doTheTest(); | |
| 827 | comptime S.doTheTest(); | |
| 826 | try S.doTheTest(); | |
| 827 | comptime try S.doTheTest(); | |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | test "self-referencing struct via array member" { |
| ... | ... | @@ -833,7 +833,7 @@ test "self-referencing struct via array member" { |
| 833 | 833 | }; |
| 834 | 834 | var x: T = undefined; |
| 835 | 835 | x = T{ .children = .{&x} }; |
| 836 | expect(x.children[0] == &x); | |
| 836 | try expect(x.children[0] == &x); | |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | test "struct with union field" { |
| ... | ... | @@ -848,8 +848,8 @@ test "struct with union field" { |
| 848 | 848 | var True = Value{ |
| 849 | 849 | .kind = .{ .Bool = true }, |
| 850 | 850 | }; |
| 851 | expectEqual(@as(u32, 2), True.ref); | |
| 852 | expectEqual(true, True.kind.Bool); | |
| 851 | try expectEqual(@as(u32, 2), True.ref); | |
| 852 | try expectEqual(true, True.kind.Bool); | |
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | test "type coercion of anon struct literal to struct" { |
| ... | ... | @@ -865,24 +865,24 @@ test "type coercion of anon struct literal to struct" { |
| 865 | 865 | field: i32 = 1234, |
| 866 | 866 | }; |
| 867 | 867 | |
| 868 | fn doTheTest() void { | |
| 868 | fn doTheTest() !void { | |
| 869 | 869 | var y: u32 = 42; |
| 870 | 870 | const t0 = .{ .A = 123, .B = "foo", .C = {} }; |
| 871 | 871 | const t1 = .{ .A = y, .B = "foo", .C = {} }; |
| 872 | 872 | const y0: S2 = t0; |
| 873 | 873 | var y1: S2 = t1; |
| 874 | expect(y0.A == 123); | |
| 875 | expect(std.mem.eql(u8, y0.B, "foo")); | |
| 876 | expect(y0.C == {}); | |
| 877 | expect(y0.D.field == 1234); | |
| 878 | expect(y1.A == y); | |
| 879 | expect(std.mem.eql(u8, y1.B, "foo")); | |
| 880 | expect(y1.C == {}); | |
| 881 | expect(y1.D.field == 1234); | |
| 874 | try expect(y0.A == 123); | |
| 875 | try expect(std.mem.eql(u8, y0.B, "foo")); | |
| 876 | try expect(y0.C == {}); | |
| 877 | try expect(y0.D.field == 1234); | |
| 878 | try expect(y1.A == y); | |
| 879 | try expect(std.mem.eql(u8, y1.B, "foo")); | |
| 880 | try expect(y1.C == {}); | |
| 881 | try expect(y1.D.field == 1234); | |
| 882 | 882 | } |
| 883 | 883 | }; |
| 884 | S.doTheTest(); | |
| 885 | comptime S.doTheTest(); | |
| 884 | try S.doTheTest(); | |
| 885 | comptime try S.doTheTest(); | |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | test "type coercion of pointer to anon struct literal to pointer to struct" { |
| ... | ... | @@ -898,24 +898,24 @@ test "type coercion of pointer to anon struct literal to pointer to struct" { |
| 898 | 898 | field: i32 = 1234, |
| 899 | 899 | }; |
| 900 | 900 | |
| 901 | fn doTheTest() void { | |
| 901 | fn doTheTest() !void { | |
| 902 | 902 | var y: u32 = 42; |
| 903 | 903 | const t0 = &.{ .A = 123, .B = "foo", .C = {} }; |
| 904 | 904 | const t1 = &.{ .A = y, .B = "foo", .C = {} }; |
| 905 | 905 | const y0: *const S2 = t0; |
| 906 | 906 | var y1: *const S2 = t1; |
| 907 | expect(y0.A == 123); | |
| 908 | expect(std.mem.eql(u8, y0.B, "foo")); | |
| 909 | expect(y0.C == {}); | |
| 910 | expect(y0.D.field == 1234); | |
| 911 | expect(y1.A == y); | |
| 912 | expect(std.mem.eql(u8, y1.B, "foo")); | |
| 913 | expect(y1.C == {}); | |
| 914 | expect(y1.D.field == 1234); | |
| 907 | try expect(y0.A == 123); | |
| 908 | try expect(std.mem.eql(u8, y0.B, "foo")); | |
| 909 | try expect(y0.C == {}); | |
| 910 | try expect(y0.D.field == 1234); | |
| 911 | try expect(y1.A == y); | |
| 912 | try expect(std.mem.eql(u8, y1.B, "foo")); | |
| 913 | try expect(y1.C == {}); | |
| 914 | try expect(y1.D.field == 1234); | |
| 915 | 915 | } |
| 916 | 916 | }; |
| 917 | S.doTheTest(); | |
| 918 | comptime S.doTheTest(); | |
| 917 | try S.doTheTest(); | |
| 918 | comptime try S.doTheTest(); | |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | test "packed struct with undefined initializers" { |
| ... | ... | @@ -929,16 +929,17 @@ test "packed struct with undefined initializers" { |
| 929 | 929 | _c: u3 = undefined, |
| 930 | 930 | }; |
| 931 | 931 | |
| 932 | fn doTheTest() void { | |
| 932 | fn doTheTest() !void { | |
| 933 | 933 | var p: P = undefined; |
| 934 | 934 | p = P{ .a = 2, .b = 4, .c = 6 }; |
| 935 | 935 | // Make sure the compiler doesn't touch the unprefixed fields. |
| 936 | expectEqual(@as(u3, 2), p.a); | |
| 937 | expectEqual(@as(u3, 4), p.b); | |
| 938 | expectEqual(@as(u3, 6), p.c); | |
| 936 | // Use expect since i386-linux doesn't like expectEqual | |
| 937 | try expect(p.a == 2); | |
| 938 | try expect(p.b == 4); | |
| 939 | try expect(p.c == 6); | |
| 939 | 940 | } |
| 940 | 941 | }; |
| 941 | 942 | |
| 942 | S.doTheTest(); | |
| 943 | comptime S.doTheTest(); | |
| 943 | try S.doTheTest(); | |
| 944 | comptime try S.doTheTest(); | |
| 944 | 945 | } |
test/stage1/behavior/struct_contains_null_ptr_itself.zig+1-1| ... | ... | @@ -3,7 +3,7 @@ const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "struct contains null pointer which contains original struct" { |
| 5 | 5 | var x: ?*NodeLineComment = null; |
| 6 | expect(x == null); | |
| 6 | try expect(x == null); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | pub const Node = struct { |
test/stage1/behavior/struct_contains_slice_of_itself.zig+12-12| ... | ... | @@ -39,12 +39,12 @@ test "struct contains slice of itself" { |
| 39 | 39 | .payload = 1234, |
| 40 | 40 | .children = nodes[0..], |
| 41 | 41 | }; |
| 42 | expect(root.payload == 1234); | |
| 43 | expect(root.children[0].payload == 1); | |
| 44 | expect(root.children[1].payload == 2); | |
| 45 | expect(root.children[2].payload == 3); | |
| 46 | expect(root.children[2].children[0].payload == 31); | |
| 47 | expect(root.children[2].children[1].payload == 32); | |
| 42 | try expect(root.payload == 1234); | |
| 43 | try expect(root.children[0].payload == 1); | |
| 44 | try expect(root.children[1].payload == 2); | |
| 45 | try expect(root.children[2].payload == 3); | |
| 46 | try expect(root.children[2].children[0].payload == 31); | |
| 47 | try expect(root.children[2].children[1].payload == 32); | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | test "struct contains aligned slice of itself" { |
| ... | ... | @@ -76,10 +76,10 @@ test "struct contains aligned slice of itself" { |
| 76 | 76 | .payload = 1234, |
| 77 | 77 | .children = nodes[0..], |
| 78 | 78 | }; |
| 79 | expect(root.payload == 1234); | |
| 80 | expect(root.children[0].payload == 1); | |
| 81 | expect(root.children[1].payload == 2); | |
| 82 | expect(root.children[2].payload == 3); | |
| 83 | expect(root.children[2].children[0].payload == 31); | |
| 84 | expect(root.children[2].children[1].payload == 32); | |
| 79 | try expect(root.payload == 1234); | |
| 80 | try expect(root.children[0].payload == 1); | |
| 81 | try expect(root.children[1].payload == 2); | |
| 82 | try expect(root.children[2].payload == 3); | |
| 83 | try expect(root.children[2].children[0].payload == 31); | |
| 84 | try expect(root.children[2].children[1].payload == 32); | |
| 85 | 85 | } |
test/stage1/behavior/switch.zig+104-104| ... | ... | @@ -4,23 +4,23 @@ const expectError = std.testing.expectError; |
| 4 | 4 | const expectEqual = std.testing.expectEqual; |
| 5 | 5 | |
| 6 | 6 | test "switch with numbers" { |
| 7 | testSwitchWithNumbers(13); | |
| 7 | try testSwitchWithNumbers(13); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | fn testSwitchWithNumbers(x: u32) void { | |
| 10 | fn testSwitchWithNumbers(x: u32) !void { | |
| 11 | 11 | const result = switch (x) { |
| 12 | 12 | 1, 2, 3, 4...8 => false, |
| 13 | 13 | 13 => true, |
| 14 | 14 | else => false, |
| 15 | 15 | }; |
| 16 | expect(result); | |
| 16 | try expect(result); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | test "switch with all ranges" { |
| 20 | expect(testSwitchWithAllRanges(50, 3) == 1); | |
| 21 | expect(testSwitchWithAllRanges(101, 0) == 2); | |
| 22 | expect(testSwitchWithAllRanges(300, 5) == 3); | |
| 23 | expect(testSwitchWithAllRanges(301, 6) == 6); | |
| 20 | try expect(testSwitchWithAllRanges(50, 3) == 1); | |
| 21 | try expect(testSwitchWithAllRanges(101, 0) == 2); | |
| 22 | try expect(testSwitchWithAllRanges(300, 5) == 3); | |
| 23 | try expect(testSwitchWithAllRanges(301, 6) == 6); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | fn testSwitchWithAllRanges(x: u32, y: u32) u32 { |
| ... | ... | @@ -43,7 +43,7 @@ test "implicit comptime switch" { |
| 43 | 43 | }; |
| 44 | 44 | |
| 45 | 45 | comptime { |
| 46 | expect(result + 1 == 14); | |
| 46 | try expect(result + 1 == 14); | |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| ... | ... | @@ -65,16 +65,16 @@ fn nonConstSwitchOnEnum(fruit: Fruit) void { |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | test "switch statement" { |
| 68 | nonConstSwitch(SwitchStatmentFoo.C); | |
| 68 | try nonConstSwitch(SwitchStatmentFoo.C); | |
| 69 | 69 | } |
| 70 | fn nonConstSwitch(foo: SwitchStatmentFoo) void { | |
| 70 | fn nonConstSwitch(foo: SwitchStatmentFoo) !void { | |
| 71 | 71 | const val = switch (foo) { |
| 72 | 72 | SwitchStatmentFoo.A => @as(i32, 1), |
| 73 | 73 | SwitchStatmentFoo.B => 2, |
| 74 | 74 | SwitchStatmentFoo.C => 3, |
| 75 | 75 | SwitchStatmentFoo.D => 4, |
| 76 | 76 | }; |
| 77 | expect(val == 3); | |
| 77 | try expect(val == 3); | |
| 78 | 78 | } |
| 79 | 79 | const SwitchStatmentFoo = enum { |
| 80 | 80 | A, |
| ... | ... | @@ -84,22 +84,22 @@ const SwitchStatmentFoo = enum { |
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | 86 | test "switch prong with variable" { |
| 87 | switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 }); | |
| 88 | switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 }); | |
| 89 | switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} }); | |
| 87 | try switchProngWithVarFn(SwitchProngWithVarEnum{ .One = 13 }); | |
| 88 | try switchProngWithVarFn(SwitchProngWithVarEnum{ .Two = 13.0 }); | |
| 89 | try switchProngWithVarFn(SwitchProngWithVarEnum{ .Meh = {} }); | |
| 90 | 90 | } |
| 91 | 91 | const SwitchProngWithVarEnum = union(enum) { |
| 92 | 92 | One: i32, |
| 93 | 93 | Two: f32, |
| 94 | 94 | Meh: void, |
| 95 | 95 | }; |
| 96 | fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void { | |
| 96 | fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void { | |
| 97 | 97 | switch (a) { |
| 98 | 98 | SwitchProngWithVarEnum.One => |x| { |
| 99 | expect(x == 13); | |
| 99 | try expect(x == 13); | |
| 100 | 100 | }, |
| 101 | 101 | SwitchProngWithVarEnum.Two => |x| { |
| 102 | expect(x == 13.0); | |
| 102 | try expect(x == 13.0); | |
| 103 | 103 | }, |
| 104 | 104 | SwitchProngWithVarEnum.Meh => |x| { |
| 105 | 105 | const v: void = x; |
| ... | ... | @@ -108,18 +108,18 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) void { |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | test "switch on enum using pointer capture" { |
| 111 | testSwitchEnumPtrCapture(); | |
| 112 | comptime testSwitchEnumPtrCapture(); | |
| 111 | try testSwitchEnumPtrCapture(); | |
| 112 | comptime try testSwitchEnumPtrCapture(); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | fn testSwitchEnumPtrCapture() void { | |
| 115 | fn testSwitchEnumPtrCapture() !void { | |
| 116 | 116 | var value = SwitchProngWithVarEnum{ .One = 1234 }; |
| 117 | 117 | switch (value) { |
| 118 | 118 | SwitchProngWithVarEnum.One => |*x| x.* += 1, |
| 119 | 119 | else => unreachable, |
| 120 | 120 | } |
| 121 | 121 | switch (value) { |
| 122 | SwitchProngWithVarEnum.One => |x| expect(x == 1235), | |
| 122 | SwitchProngWithVarEnum.One => |x| try expect(x == 1235), | |
| 123 | 123 | else => unreachable, |
| 124 | 124 | } |
| 125 | 125 | } |
| ... | ... | @@ -130,7 +130,7 @@ test "switch with multiple expressions" { |
| 130 | 130 | 4, 5, 6 => 2, |
| 131 | 131 | else => @as(i32, 3), |
| 132 | 132 | }; |
| 133 | expect(x == 2); | |
| 133 | try expect(x == 2); | |
| 134 | 134 | } |
| 135 | 135 | fn returnsFive() i32 { |
| 136 | 136 | return 5; |
| ... | ... | @@ -152,12 +152,12 @@ fn returnsFalse() bool { |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | test "switch on const enum with var" { |
| 155 | expect(!returnsFalse()); | |
| 155 | try expect(!returnsFalse()); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | test "switch on type" { |
| 159 | expect(trueIfBoolFalseOtherwise(bool)); | |
| 160 | expect(!trueIfBoolFalseOtherwise(i32)); | |
| 159 | try expect(trueIfBoolFalseOtherwise(bool)); | |
| 160 | try expect(!trueIfBoolFalseOtherwise(i32)); | |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | fn trueIfBoolFalseOtherwise(comptime T: type) bool { |
| ... | ... | @@ -168,21 +168,21 @@ fn trueIfBoolFalseOtherwise(comptime T: type) bool { |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | test "switch handles all cases of number" { |
| 171 | testSwitchHandleAllCases(); | |
| 172 | comptime testSwitchHandleAllCases(); | |
| 171 | try testSwitchHandleAllCases(); | |
| 172 | comptime try testSwitchHandleAllCases(); | |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | fn testSwitchHandleAllCases() void { | |
| 176 | expect(testSwitchHandleAllCasesExhaustive(0) == 3); | |
| 177 | expect(testSwitchHandleAllCasesExhaustive(1) == 2); | |
| 178 | expect(testSwitchHandleAllCasesExhaustive(2) == 1); | |
| 179 | expect(testSwitchHandleAllCasesExhaustive(3) == 0); | |
| 175 | fn testSwitchHandleAllCases() !void { | |
| 176 | try expect(testSwitchHandleAllCasesExhaustive(0) == 3); | |
| 177 | try expect(testSwitchHandleAllCasesExhaustive(1) == 2); | |
| 178 | try expect(testSwitchHandleAllCasesExhaustive(2) == 1); | |
| 179 | try expect(testSwitchHandleAllCasesExhaustive(3) == 0); | |
| 180 | 180 | |
| 181 | expect(testSwitchHandleAllCasesRange(100) == 0); | |
| 182 | expect(testSwitchHandleAllCasesRange(200) == 1); | |
| 183 | expect(testSwitchHandleAllCasesRange(201) == 2); | |
| 184 | expect(testSwitchHandleAllCasesRange(202) == 4); | |
| 185 | expect(testSwitchHandleAllCasesRange(230) == 3); | |
| 181 | try expect(testSwitchHandleAllCasesRange(100) == 0); | |
| 182 | try expect(testSwitchHandleAllCasesRange(200) == 1); | |
| 183 | try expect(testSwitchHandleAllCasesRange(201) == 2); | |
| 184 | try expect(testSwitchHandleAllCasesRange(202) == 4); | |
| 185 | try expect(testSwitchHandleAllCasesRange(230) == 3); | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | fn testSwitchHandleAllCasesExhaustive(x: u2) u2 { |
| ... | ... | @@ -205,13 +205,13 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 { |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | test "switch all prongs unreachable" { |
| 208 | testAllProngsUnreachable(); | |
| 209 | comptime testAllProngsUnreachable(); | |
| 208 | try testAllProngsUnreachable(); | |
| 209 | comptime try testAllProngsUnreachable(); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | fn testAllProngsUnreachable() void { | |
| 213 | expect(switchWithUnreachable(1) == 2); | |
| 214 | expect(switchWithUnreachable(2) == 10); | |
| 212 | fn testAllProngsUnreachable() !void { | |
| 213 | try expect(switchWithUnreachable(1) == 2); | |
| 214 | try expect(switchWithUnreachable(2) == 10); | |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | fn switchWithUnreachable(x: i32) i32 { |
| ... | ... | @@ -233,23 +233,23 @@ test "capture value of switch with all unreachable prongs" { |
| 233 | 233 | const x = return_a_number() catch |err| switch (err) { |
| 234 | 234 | else => unreachable, |
| 235 | 235 | }; |
| 236 | expect(x == 1); | |
| 236 | try expect(x == 1); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | test "switching on booleans" { |
| 240 | testSwitchOnBools(); | |
| 241 | comptime testSwitchOnBools(); | |
| 240 | try testSwitchOnBools(); | |
| 241 | comptime try testSwitchOnBools(); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | fn testSwitchOnBools() void { | |
| 245 | expect(testSwitchOnBoolsTrueAndFalse(true) == false); | |
| 246 | expect(testSwitchOnBoolsTrueAndFalse(false) == true); | |
| 244 | fn testSwitchOnBools() !void { | |
| 245 | try expect(testSwitchOnBoolsTrueAndFalse(true) == false); | |
| 246 | try expect(testSwitchOnBoolsTrueAndFalse(false) == true); | |
| 247 | 247 | |
| 248 | expect(testSwitchOnBoolsTrueWithElse(true) == false); | |
| 249 | expect(testSwitchOnBoolsTrueWithElse(false) == true); | |
| 248 | try expect(testSwitchOnBoolsTrueWithElse(true) == false); | |
| 249 | try expect(testSwitchOnBoolsTrueWithElse(false) == true); | |
| 250 | 250 | |
| 251 | expect(testSwitchOnBoolsFalseWithElse(true) == false); | |
| 252 | expect(testSwitchOnBoolsFalseWithElse(false) == true); | |
| 251 | try expect(testSwitchOnBoolsFalseWithElse(true) == false); | |
| 252 | try expect(testSwitchOnBoolsFalseWithElse(false) == true); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | fn testSwitchOnBoolsTrueAndFalse(x: bool) bool { |
| ... | ... | @@ -276,14 +276,14 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { |
| 276 | 276 | test "u0" { |
| 277 | 277 | var val: u0 = 0; |
| 278 | 278 | switch (val) { |
| 279 | 0 => expect(val == 0), | |
| 279 | 0 => try expect(val == 0), | |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | test "undefined.u0" { |
| 284 | 284 | var val: u0 = undefined; |
| 285 | 285 | switch (val) { |
| 286 | 0 => expect(val == 0), | |
| 286 | 0 => try expect(val == 0), | |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| ... | ... | @@ -295,15 +295,15 @@ test "anon enum literal used in switch on union enum" { |
| 295 | 295 | var foo = Foo{ .a = 1234 }; |
| 296 | 296 | switch (foo) { |
| 297 | 297 | .a => |x| { |
| 298 | expect(x == 1234); | |
| 298 | try expect(x == 1234); | |
| 299 | 299 | }, |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | test "else prong of switch on error set excludes other cases" { |
| 304 | 304 | const S = struct { |
| 305 | fn doTheTest() void { | |
| 306 | expectError(error.C, bar()); | |
| 305 | fn doTheTest() !void { | |
| 306 | try expectError(error.C, bar()); | |
| 307 | 307 | } |
| 308 | 308 | const E = error{ |
| 309 | 309 | A, |
| ... | ... | @@ -326,14 +326,14 @@ test "else prong of switch on error set excludes other cases" { |
| 326 | 326 | }; |
| 327 | 327 | } |
| 328 | 328 | }; |
| 329 | S.doTheTest(); | |
| 330 | comptime S.doTheTest(); | |
| 329 | try S.doTheTest(); | |
| 330 | comptime try S.doTheTest(); | |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | test "switch prongs with error set cases make a new error set type for capture value" { |
| 334 | 334 | const S = struct { |
| 335 | fn doTheTest() void { | |
| 336 | expectError(error.B, bar()); | |
| 335 | fn doTheTest() !void { | |
| 336 | try expectError(error.B, bar()); | |
| 337 | 337 | } |
| 338 | 338 | const E = E1 || E2; |
| 339 | 339 | |
| ... | ... | @@ -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(); | |
| 362 | comptime S.doTheTest(); | |
| 361 | try S.doTheTest(); | |
| 362 | comptime try S.doTheTest(); | |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | test "return result loc and then switch with range implicit casted to error union" { |
| 366 | 366 | const S = struct { |
| 367 | fn doTheTest() void { | |
| 368 | expect((func(0xb) catch unreachable) == 0xb); | |
| 367 | fn doTheTest() !void { | |
| 368 | try expect((func(0xb) catch unreachable) == 0xb); | |
| 369 | 369 | } |
| 370 | 370 | fn func(d: u8) anyerror!u8 { |
| 371 | 371 | return switch (d) { |
| ... | ... | @@ -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(); | |
| 378 | comptime S.doTheTest(); | |
| 377 | try S.doTheTest(); | |
| 378 | comptime try S.doTheTest(); | |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | test "switch with null and T peer types and inferred result location type" { |
| 382 | 382 | const S = struct { |
| 383 | fn doTheTest(c: u8) void { | |
| 383 | fn doTheTest(c: u8) !void { | |
| 384 | 384 | if (switch (c) { |
| 385 | 385 | 0 => true, |
| 386 | 386 | else => null, |
| ... | ... | @@ -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); | |
| 393 | comptime S.doTheTest(1); | |
| 392 | try S.doTheTest(1); | |
| 393 | comptime try S.doTheTest(1); | |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | test "switch prongs with cases with identical payload types" { |
| ... | ... | @@ -400,31 +400,31 @@ test "switch prongs with cases with identical payload types" { |
| 400 | 400 | C: usize, |
| 401 | 401 | }; |
| 402 | 402 | const S = struct { |
| 403 | fn doTheTest() void { | |
| 404 | doTheSwitch1(Union{ .A = 8 }); | |
| 405 | doTheSwitch2(Union{ .B = -8 }); | |
| 403 | fn doTheTest() !void { | |
| 404 | try doTheSwitch1(Union{ .A = 8 }); | |
| 405 | try doTheSwitch2(Union{ .B = -8 }); | |
| 406 | 406 | } |
| 407 | fn doTheSwitch1(u: Union) void { | |
| 407 | fn doTheSwitch1(u: Union) !void { | |
| 408 | 408 | switch (u) { |
| 409 | 409 | .A, .C => |e| { |
| 410 | expect(@TypeOf(e) == usize); | |
| 411 | expect(e == 8); | |
| 410 | try expect(@TypeOf(e) == usize); | |
| 411 | try expect(e == 8); | |
| 412 | 412 | }, |
| 413 | 413 | .B => |e| @panic("fail"), |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | fn doTheSwitch2(u: Union) void { | |
| 416 | fn doTheSwitch2(u: Union) !void { | |
| 417 | 417 | switch (u) { |
| 418 | 418 | .A, .C => |e| @panic("fail"), |
| 419 | 419 | .B => |e| { |
| 420 | expect(@TypeOf(e) == isize); | |
| 421 | expect(e == -8); | |
| 420 | try expect(@TypeOf(e) == isize); | |
| 421 | try expect(e == -8); | |
| 422 | 422 | }, |
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | }; |
| 426 | S.doTheTest(); | |
| 427 | comptime S.doTheTest(); | |
| 426 | try S.doTheTest(); | |
| 427 | comptime try S.doTheTest(); | |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | test "switch with disjoint range" { |
| ... | ... | @@ -438,19 +438,19 @@ test "switch with disjoint range" { |
| 438 | 438 | |
| 439 | 439 | test "switch variable for range and multiple prongs" { |
| 440 | 440 | const S = struct { |
| 441 | fn doTheTest() void { | |
| 441 | fn doTheTest() !void { | |
| 442 | 442 | var u: u8 = 16; |
| 443 | doTheSwitch(u); | |
| 444 | comptime doTheSwitch(u); | |
| 443 | try doTheSwitch(u); | |
| 444 | comptime try doTheSwitch(u); | |
| 445 | 445 | var v: u8 = 42; |
| 446 | doTheSwitch(v); | |
| 447 | comptime doTheSwitch(v); | |
| 446 | try doTheSwitch(v); | |
| 447 | comptime try doTheSwitch(v); | |
| 448 | 448 | } |
| 449 | fn doTheSwitch(q: u8) void { | |
| 449 | fn doTheSwitch(q: u8) !void { | |
| 450 | 450 | switch (q) { |
| 451 | 0...40 => |x| expect(x == 16), | |
| 452 | 41, 42, 43 => |x| expect(x == 42), | |
| 453 | else => expect(false), | |
| 451 | 0...40 => |x| try expect(x == 16), | |
| 452 | 41, 42, 43 => |x| try expect(x == 42), | |
| 453 | else => try expect(false), | |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | }; |
| ... | ... | @@ -493,31 +493,31 @@ test "switch on pointer type" { |
| 493 | 493 | } |
| 494 | 494 | }; |
| 495 | 495 | |
| 496 | expect(1 == S.doTheTest(S.P1)); | |
| 497 | expect(2 == S.doTheTest(S.P2)); | |
| 498 | expect(3 == S.doTheTest(S.P3)); | |
| 499 | comptime expect(1 == S.doTheTest(S.P1)); | |
| 500 | comptime expect(2 == S.doTheTest(S.P2)); | |
| 501 | comptime expect(3 == S.doTheTest(S.P3)); | |
| 496 | try expect(1 == S.doTheTest(S.P1)); | |
| 497 | try expect(2 == S.doTheTest(S.P2)); | |
| 498 | try expect(3 == S.doTheTest(S.P3)); | |
| 499 | comptime try expect(1 == S.doTheTest(S.P1)); | |
| 500 | comptime try expect(2 == S.doTheTest(S.P2)); | |
| 501 | comptime try expect(3 == S.doTheTest(S.P3)); | |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | test "switch on error set with single else" { |
| 505 | 505 | const S = struct { |
| 506 | fn doTheTest() void { | |
| 506 | fn doTheTest() !void { | |
| 507 | 507 | var some: error{Foo} = error.Foo; |
| 508 | expect(switch (some) { | |
| 508 | try expect(switch (some) { | |
| 509 | 509 | else => |a| true, |
| 510 | 510 | }); |
| 511 | 511 | } |
| 512 | 512 | }; |
| 513 | 513 | |
| 514 | S.doTheTest(); | |
| 515 | comptime S.doTheTest(); | |
| 514 | try S.doTheTest(); | |
| 515 | comptime try S.doTheTest(); | |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | test "while copies its payload" { |
| 519 | 519 | const S = struct { |
| 520 | fn doTheTest() void { | |
| 520 | fn doTheTest() !void { | |
| 521 | 521 | var tmp: union(enum) { |
| 522 | 522 | A: u8, |
| 523 | 523 | B: u32, |
| ... | ... | @@ -526,12 +526,12 @@ test "while copies its payload" { |
| 526 | 526 | .A => |value| { |
| 527 | 527 | // Modify the original union |
| 528 | 528 | tmp = .{ .B = 0x10101010 }; |
| 529 | expectEqual(@as(u8, 42), value); | |
| 529 | try expectEqual(@as(u8, 42), value); | |
| 530 | 530 | }, |
| 531 | 531 | else => unreachable, |
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | }; |
| 535 | S.doTheTest(); | |
| 536 | comptime S.doTheTest(); | |
| 535 | try S.doTheTest(); | |
| 536 | comptime try S.doTheTest(); | |
| 537 | 537 | } |
test/stage1/behavior/switch_prong_err_enum.zig+2-2| ... | ... | @@ -22,9 +22,9 @@ fn doThing(form_id: u64) anyerror!FormValue { |
| 22 | 22 | test "switch prong returns error enum" { |
| 23 | 23 | switch (doThing(17) catch unreachable) { |
| 24 | 24 | FormValue.Address => |payload| { |
| 25 | expect(payload == 1); | |
| 25 | try expect(payload == 1); | |
| 26 | 26 | }, |
| 27 | 27 | else => unreachable, |
| 28 | 28 | } |
| 29 | expect(read_count == 1); | |
| 29 | try expect(read_count == 1); | |
| 30 | 30 | } |
test/stage1/behavior/switch_prong_implicit_cast.zig+1-1| ... | ... | @@ -18,5 +18,5 @@ test "switch prong implicit cast" { |
| 18 | 18 | FormValue.One => false, |
| 19 | 19 | FormValue.Two => |x| x, |
| 20 | 20 | }; |
| 21 | expect(result); | |
| 21 | try expect(result); | |
| 22 | 22 | } |
test/stage1/behavior/this.zig+3-3| ... | ... | @@ -20,7 +20,7 @@ fn add(x: i32, y: i32) i32 { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "this refer to module call private fn" { |
| 23 | expect(module.add(1, 2) == 3); | |
| 23 | try expect(module.add(1, 2) == 3); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | test "this refer to container" { |
| ... | ... | @@ -29,6 +29,6 @@ test "this refer to container" { |
| 29 | 29 | .y = 34, |
| 30 | 30 | }; |
| 31 | 31 | pt.addOne(); |
| 32 | expect(pt.x == 13); | |
| 33 | expect(pt.y == 35); | |
| 32 | try expect(pt.x == 13); | |
| 33 | try expect(pt.y == 35); | |
| 34 | 34 | } |
test/stage1/behavior/translate_c_macros.zig+4-4| ... | ... | @@ -4,7 +4,7 @@ const expectEqual = @import("std").testing.expectEqual; |
| 4 | 4 | const h = @cImport(@cInclude("stage1/behavior/translate_c_macros.h")); |
| 5 | 5 | |
| 6 | 6 | test "initializer list expression" { |
| 7 | expectEqual(h.Color{ | |
| 7 | try expectEqual(h.Color{ | |
| 8 | 8 | .r = 200, |
| 9 | 9 | .g = 200, |
| 10 | 10 | .b = 200, |
| ... | ... | @@ -13,10 +13,10 @@ test "initializer list expression" { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | test "sizeof in macros" { |
| 16 | expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32)); | |
| 17 | expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32)); | |
| 16 | try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF(u32)); | |
| 17 | try expectEqual(@as(c_int, @sizeOf(u32)), h.MY_SIZEOF2(u32)); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | test "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/stage1/behavior/truncate.zig+6-6| ... | ... | @@ -4,33 +4,33 @@ const expect = std.testing.expect; |
| 4 | 4 | test "truncate u0 to larger integer allowed and has comptime known result" { |
| 5 | 5 | var x: u0 = 0; |
| 6 | 6 | const y = @truncate(u8, x); |
| 7 | comptime expect(y == 0); | |
| 7 | comptime try expect(y == 0); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | test "truncate.u0.literal" { |
| 11 | 11 | var z = @truncate(u0, 0); |
| 12 | expect(z == 0); | |
| 12 | try expect(z == 0); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | test "truncate.u0.const" { |
| 16 | 16 | const c0: usize = 0; |
| 17 | 17 | var z = @truncate(u0, c0); |
| 18 | expect(z == 0); | |
| 18 | try expect(z == 0); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "truncate.u0.var" { |
| 22 | 22 | var d: u8 = 2; |
| 23 | 23 | var z = @truncate(u0, d); |
| 24 | expect(z == 0); | |
| 24 | try expect(z == 0); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | test "truncate sign mismatch but comptime known so it works anyway" { |
| 28 | 28 | const x: u32 = 10; |
| 29 | 29 | var result = @truncate(i8, x); |
| 30 | expect(result == 10); | |
| 30 | try expect(result == 10); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | test "truncate on comptime integer" { |
| 34 | 34 | var x = @truncate(u16, 9999); |
| 35 | expect(x == 9999); | |
| 35 | try expect(x == 9999); | |
| 36 | 36 | } |
test/stage1/behavior/try.zig+7-7| ... | ... | @@ -1,17 +1,17 @@ |
| 1 | 1 | const expect = @import("std").testing.expect; |
| 2 | 2 | |
| 3 | 3 | test "try on error union" { |
| 4 | tryOnErrorUnionImpl(); | |
| 5 | comptime tryOnErrorUnionImpl(); | |
| 4 | try tryOnErrorUnionImpl(); | |
| 5 | comptime try tryOnErrorUnionImpl(); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | fn tryOnErrorUnionImpl() void { | |
| 8 | fn tryOnErrorUnionImpl() !void { | |
| 9 | 9 | const x = if (returnsTen()) |val| val + 1 else |err| switch (err) { |
| 10 | 10 | error.ItBroke, error.NoMem => 1, |
| 11 | 11 | error.CrappedOut => @as(i32, 2), |
| 12 | 12 | else => unreachable, |
| 13 | 13 | }; |
| 14 | expect(x == 11); | |
| 14 | try expect(x == 11); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn returnsTen() anyerror!i32 { |
| ... | ... | @@ -20,10 +20,10 @@ fn returnsTen() anyerror!i32 { |
| 20 | 20 | |
| 21 | 21 | test "try without vars" { |
| 22 | 22 | const result1 = if (failIfTrue(true)) 1 else |_| @as(i32, 2); |
| 23 | expect(result1 == 2); | |
| 23 | try expect(result1 == 2); | |
| 24 | 24 | |
| 25 | 25 | const result2 = if (failIfTrue(false)) 1 else |_| @as(i32, 2); |
| 26 | expect(result2 == 1); | |
| 26 | try expect(result2 == 1); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | fn failIfTrue(ok: bool) anyerror!void { |
| ... | ... | @@ -38,6 +38,6 @@ test "try then not executed with assignment" { |
| 38 | 38 | if (failIfTrue(true)) { |
| 39 | 39 | unreachable; |
| 40 | 40 | } else |err| { |
| 41 | expect(err == error.ItBroke); | |
| 41 | try expect(err == error.ItBroke); | |
| 42 | 42 | } |
| 43 | 43 | } |
test/stage1/behavior/tuple.zig+44-44| ... | ... | @@ -5,93 +5,93 @@ const expectEqual = testing.expectEqual; |
| 5 | 5 | |
| 6 | 6 | test "tuple concatenation" { |
| 7 | 7 | const S = struct { |
| 8 | fn doTheTest() void { | |
| 8 | fn doTheTest() !void { | |
| 9 | 9 | var a: i32 = 1; |
| 10 | 10 | var b: i32 = 2; |
| 11 | 11 | var x = .{a}; |
| 12 | 12 | var y = .{b}; |
| 13 | 13 | var c = x ++ y; |
| 14 | expectEqual(@as(i32, 1), c[0]); | |
| 15 | expectEqual(@as(i32, 2), c[1]); | |
| 14 | try expectEqual(@as(i32, 1), c[0]); | |
| 15 | try expectEqual(@as(i32, 2), c[1]); | |
| 16 | 16 | } |
| 17 | 17 | }; |
| 18 | S.doTheTest(); | |
| 19 | comptime S.doTheTest(); | |
| 18 | try S.doTheTest(); | |
| 19 | comptime try S.doTheTest(); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "tuple multiplication" { |
| 23 | 23 | const S = struct { |
| 24 | fn doTheTest() void { | |
| 24 | fn doTheTest() !void { | |
| 25 | 25 | { |
| 26 | 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 | 30 | const t = .{'a'} ** 4; |
| 31 | expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len); | |
| 32 | inline for (t) |x| expectEqual('a', x); | |
| 31 | try expectEqual(4, @typeInfo(@TypeOf(t)).Struct.fields.len); | |
| 32 | inline for (t) |x| try expectEqual('a', x); | |
| 33 | 33 | } |
| 34 | 34 | { |
| 35 | 35 | const t = .{ 1, 2, 3 } ** 4; |
| 36 | expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len); | |
| 37 | inline for (t) |x, i| expectEqual(1 + i % 3, x); | |
| 36 | try expectEqual(12, @typeInfo(@TypeOf(t)).Struct.fields.len); | |
| 37 | inline for (t) |x, i| try expectEqual(1 + i % 3, x); | |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | }; |
| 41 | S.doTheTest(); | |
| 42 | comptime S.doTheTest(); | |
| 41 | try S.doTheTest(); | |
| 42 | comptime try S.doTheTest(); | |
| 43 | 43 | |
| 44 | 44 | const T = struct { |
| 45 | fn consume_tuple(tuple: anytype, len: usize) void { | |
| 46 | expect(tuple.len == len); | |
| 45 | fn consume_tuple(tuple: anytype, len: usize) !void { | |
| 46 | try expect(tuple.len == len); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | fn doTheTest() void { | |
| 49 | fn doTheTest() !void { | |
| 50 | 50 | const t1 = .{}; |
| 51 | 51 | |
| 52 | 52 | var rt_var: u8 = 42; |
| 53 | 53 | const t2 = .{rt_var} ++ .{}; |
| 54 | 54 | |
| 55 | expect(t2.len == 1); | |
| 56 | expect(t2.@"0" == rt_var); | |
| 57 | expect(t2.@"0" == 42); | |
| 58 | expect(&t2.@"0" != &rt_var); | |
| 55 | try expect(t2.len == 1); | |
| 56 | try expect(t2.@"0" == rt_var); | |
| 57 | try expect(t2.@"0" == 42); | |
| 58 | try expect(&t2.@"0" != &rt_var); | |
| 59 | 59 | |
| 60 | consume_tuple(t1 ++ t1, 0); | |
| 61 | consume_tuple(.{} ++ .{}, 0); | |
| 62 | consume_tuple(.{0} ++ .{}, 1); | |
| 63 | consume_tuple(.{0} ++ .{1}, 2); | |
| 64 | consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6); | |
| 65 | consume_tuple(t2 ++ t1, 1); | |
| 66 | consume_tuple(t1 ++ t2, 1); | |
| 67 | consume_tuple(t2 ++ t2, 2); | |
| 68 | consume_tuple(.{rt_var} ++ .{}, 1); | |
| 69 | consume_tuple(.{rt_var} ++ t1, 1); | |
| 70 | consume_tuple(.{} ++ .{rt_var}, 1); | |
| 71 | consume_tuple(t2 ++ .{void}, 2); | |
| 72 | consume_tuple(t2 ++ .{0}, 2); | |
| 73 | consume_tuple(.{0} ++ t2, 2); | |
| 74 | consume_tuple(.{void} ++ t2, 2); | |
| 75 | consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3); | |
| 60 | try consume_tuple(t1 ++ t1, 0); | |
| 61 | try consume_tuple(.{} ++ .{}, 0); | |
| 62 | try consume_tuple(.{0} ++ .{}, 1); | |
| 63 | try consume_tuple(.{0} ++ .{1}, 2); | |
| 64 | try consume_tuple(.{ 0, 1, 2 } ++ .{ u8, 1, noreturn }, 6); | |
| 65 | try consume_tuple(t2 ++ t1, 1); | |
| 66 | try consume_tuple(t1 ++ t2, 1); | |
| 67 | try consume_tuple(t2 ++ t2, 2); | |
| 68 | try consume_tuple(.{rt_var} ++ .{}, 1); | |
| 69 | try consume_tuple(.{rt_var} ++ t1, 1); | |
| 70 | try consume_tuple(.{} ++ .{rt_var}, 1); | |
| 71 | try consume_tuple(t2 ++ .{void}, 2); | |
| 72 | try consume_tuple(t2 ++ .{0}, 2); | |
| 73 | try consume_tuple(.{0} ++ t2, 2); | |
| 74 | try consume_tuple(.{void} ++ t2, 2); | |
| 75 | try consume_tuple(.{u8} ++ .{rt_var} ++ .{true}, 3); | |
| 76 | 76 | } |
| 77 | 77 | }; |
| 78 | 78 | |
| 79 | T.doTheTest(); | |
| 80 | comptime T.doTheTest(); | |
| 79 | try T.doTheTest(); | |
| 80 | comptime try T.doTheTest(); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | test "pass tuple to comptime var parameter" { |
| 84 | 84 | const S = struct { |
| 85 | fn Foo(comptime args: anytype) void { | |
| 86 | expect(args[0] == 1); | |
| 85 | fn Foo(comptime args: anytype) !void { | |
| 86 | try expect(args[0] == 1); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | fn doTheTest() void { | |
| 90 | Foo(.{1}); | |
| 89 | fn doTheTest() !void { | |
| 90 | try Foo(.{1}); | |
| 91 | 91 | } |
| 92 | 92 | }; |
| 93 | S.doTheTest(); | |
| 94 | comptime S.doTheTest(); | |
| 93 | try S.doTheTest(); | |
| 94 | comptime try S.doTheTest(); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | test "tuple initializer for var" { |
test/stage1/behavior/type.zig+84-84| ... | ... | @@ -4,52 +4,52 @@ const TypeInfo = builtin.TypeInfo; |
| 4 | 4 | const std = @import("std"); |
| 5 | 5 | const testing = std.testing; |
| 6 | 6 | |
| 7 | fn testTypes(comptime types: []const type) void { | |
| 7 | fn testTypes(comptime types: []const type) !void { | |
| 8 | 8 | inline for (types) |testType| { |
| 9 | testing.expect(testType == @Type(@typeInfo(testType))); | |
| 9 | try testing.expect(testType == @Type(@typeInfo(testType))); | |
| 10 | 10 | } |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | test "Type.MetaType" { |
| 14 | testing.expect(type == @Type(TypeInfo{ .Type = undefined })); | |
| 15 | testTypes(&[_]type{type}); | |
| 14 | try testing.expect(type == @Type(TypeInfo{ .Type = undefined })); | |
| 15 | try testTypes(&[_]type{type}); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | test "Type.Void" { |
| 19 | testing.expect(void == @Type(TypeInfo{ .Void = undefined })); | |
| 20 | testTypes(&[_]type{void}); | |
| 19 | try testing.expect(void == @Type(TypeInfo{ .Void = undefined })); | |
| 20 | try testTypes(&[_]type{void}); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "Type.Bool" { |
| 24 | testing.expect(bool == @Type(TypeInfo{ .Bool = undefined })); | |
| 25 | testTypes(&[_]type{bool}); | |
| 24 | try testing.expect(bool == @Type(TypeInfo{ .Bool = undefined })); | |
| 25 | try testTypes(&[_]type{bool}); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "Type.NoReturn" { |
| 29 | testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined })); | |
| 30 | testTypes(&[_]type{noreturn}); | |
| 29 | try testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined })); | |
| 30 | try testTypes(&[_]type{noreturn}); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | test "Type.Int" { |
| 34 | testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } })); | |
| 35 | testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } })); | |
| 36 | testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } })); | |
| 37 | testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } })); | |
| 38 | testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } })); | |
| 39 | testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } })); | |
| 40 | testTypes(&[_]type{ u8, u32, i64 }); | |
| 34 | try testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } })); | |
| 35 | try testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } })); | |
| 36 | try testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } })); | |
| 37 | try testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } })); | |
| 38 | try testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } })); | |
| 39 | try testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } })); | |
| 40 | try testTypes(&[_]type{ u8, u32, i64 }); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | test "Type.Float" { |
| 44 | testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } })); | |
| 45 | testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } })); | |
| 46 | testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } })); | |
| 47 | testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } })); | |
| 48 | testTypes(&[_]type{ f16, f32, f64, f128 }); | |
| 44 | try testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } })); | |
| 45 | try testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } })); | |
| 46 | try testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } })); | |
| 47 | try testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } })); | |
| 48 | try testTypes(&[_]type{ f16, f32, f64, f128 }); | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | test "Type.Pointer" { |
| 52 | testTypes(&[_]type{ | |
| 52 | try testTypes(&[_]type{ | |
| 53 | 53 | // One Value Pointer Types |
| 54 | 54 | *u8, *const u8, |
| 55 | 55 | *volatile u8, *const volatile u8, |
| ... | ... | @@ -94,41 +94,41 @@ test "Type.Pointer" { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | test "Type.Array" { |
| 97 | testing.expect([123]u8 == @Type(TypeInfo{ | |
| 97 | try testing.expect([123]u8 == @Type(TypeInfo{ | |
| 98 | 98 | .Array = TypeInfo.Array{ |
| 99 | 99 | .len = 123, |
| 100 | 100 | .child = u8, |
| 101 | 101 | .sentinel = null, |
| 102 | 102 | }, |
| 103 | 103 | })); |
| 104 | testing.expect([2]u32 == @Type(TypeInfo{ | |
| 104 | try testing.expect([2]u32 == @Type(TypeInfo{ | |
| 105 | 105 | .Array = TypeInfo.Array{ |
| 106 | 106 | .len = 2, |
| 107 | 107 | .child = u32, |
| 108 | 108 | .sentinel = null, |
| 109 | 109 | }, |
| 110 | 110 | })); |
| 111 | testing.expect([2:0]u32 == @Type(TypeInfo{ | |
| 111 | try testing.expect([2:0]u32 == @Type(TypeInfo{ | |
| 112 | 112 | .Array = TypeInfo.Array{ |
| 113 | 113 | .len = 2, |
| 114 | 114 | .child = u32, |
| 115 | 115 | .sentinel = 0, |
| 116 | 116 | }, |
| 117 | 117 | })); |
| 118 | testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); | |
| 118 | try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); | |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | test "Type.ComptimeFloat" { |
| 122 | testTypes(&[_]type{comptime_float}); | |
| 122 | try testTypes(&[_]type{comptime_float}); | |
| 123 | 123 | } |
| 124 | 124 | test "Type.ComptimeInt" { |
| 125 | testTypes(&[_]type{comptime_int}); | |
| 125 | try testTypes(&[_]type{comptime_int}); | |
| 126 | 126 | } |
| 127 | 127 | test "Type.Undefined" { |
| 128 | testTypes(&[_]type{@TypeOf(undefined)}); | |
| 128 | try testTypes(&[_]type{@TypeOf(undefined)}); | |
| 129 | 129 | } |
| 130 | 130 | test "Type.Null" { |
| 131 | testTypes(&[_]type{@TypeOf(null)}); | |
| 131 | try testTypes(&[_]type{@TypeOf(null)}); | |
| 132 | 132 | } |
| 133 | 133 | test "@Type create slice with null sentinel" { |
| 134 | 134 | const Slice = @Type(builtin.TypeInfo{ |
| ... | ... | @@ -142,10 +142,10 @@ test "@Type create slice with null sentinel" { |
| 142 | 142 | .sentinel = null, |
| 143 | 143 | }, |
| 144 | 144 | }); |
| 145 | testing.expect(Slice == []align(8) const *i32); | |
| 145 | try testing.expect(Slice == []align(8) const *i32); | |
| 146 | 146 | } |
| 147 | 147 | test "@Type picks up the sentinel value from TypeInfo" { |
| 148 | testTypes(&[_]type{ | |
| 148 | try testTypes(&[_]type{ | |
| 149 | 149 | [11:0]u8, [4:10]u8, |
| 150 | 150 | [*:0]u8, [*:0]const u8, |
| 151 | 151 | [*:0]volatile u8, [*:0]const volatile u8, |
| ... | ... | @@ -173,7 +173,7 @@ test "@Type picks up the sentinel value from TypeInfo" { |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | test "Type.Optional" { |
| 176 | testTypes(&[_]type{ | |
| 176 | try testTypes(&[_]type{ | |
| 177 | 177 | ?u8, |
| 178 | 178 | ?*u8, |
| 179 | 179 | ?[]u8, |
| ... | ... | @@ -183,7 +183,7 @@ test "Type.Optional" { |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "Type.ErrorUnion" { |
| 186 | testTypes(&[_]type{ | |
| 186 | try testTypes(&[_]type{ | |
| 187 | 187 | error{}!void, |
| 188 | 188 | error{Error}!void, |
| 189 | 189 | }); |
| ... | ... | @@ -195,8 +195,8 @@ test "Type.Opaque" { |
| 195 | 195 | .decls = &[_]TypeInfo.Declaration{}, |
| 196 | 196 | }, |
| 197 | 197 | }); |
| 198 | testing.expect(Opaque != opaque {}); | |
| 199 | testing.expectEqualSlices( | |
| 198 | try testing.expect(Opaque != opaque {}); | |
| 199 | try testing.expectEqualSlices( | |
| 200 | 200 | TypeInfo.Declaration, |
| 201 | 201 | &[_]TypeInfo.Declaration{}, |
| 202 | 202 | @typeInfo(Opaque).Opaque.decls, |
| ... | ... | @@ -204,7 +204,7 @@ test "Type.Opaque" { |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | test "Type.Vector" { |
| 207 | testTypes(&[_]type{ | |
| 207 | try testTypes(&[_]type{ | |
| 208 | 208 | @Vector(0, u8), |
| 209 | 209 | @Vector(4, u8), |
| 210 | 210 | @Vector(8, *u8), |
| ... | ... | @@ -215,7 +215,7 @@ test "Type.Vector" { |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | test "Type.AnyFrame" { |
| 218 | testTypes(&[_]type{ | |
| 218 | try testTypes(&[_]type{ | |
| 219 | 219 | anyframe, |
| 220 | 220 | anyframe->u8, |
| 221 | 221 | anyframe->anyframe->u8, |
| ... | ... | @@ -223,7 +223,7 @@ test "Type.AnyFrame" { |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | test "Type.EnumLiteral" { |
| 226 | testTypes(&[_]type{ | |
| 226 | try testTypes(&[_]type{ | |
| 227 | 227 | @TypeOf(.Dummy), |
| 228 | 228 | }); |
| 229 | 229 | } |
| ... | ... | @@ -233,7 +233,7 @@ fn add(a: i32, b: i32) i32 { |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | test "Type.Frame" { |
| 236 | testTypes(&[_]type{ | |
| 236 | try testTypes(&[_]type{ | |
| 237 | 237 | @Frame(add), |
| 238 | 238 | }); |
| 239 | 239 | } |
| ... | ... | @@ -248,45 +248,45 @@ test "Type.ErrorSet" { |
| 248 | 248 | test "Type.Struct" { |
| 249 | 249 | const A = @Type(@typeInfo(struct { x: u8, y: u32 })); |
| 250 | 250 | const infoA = @typeInfo(A).Struct; |
| 251 | testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout); | |
| 252 | testing.expectEqualSlices(u8, "x", infoA.fields[0].name); | |
| 253 | testing.expectEqual(u8, infoA.fields[0].field_type); | |
| 254 | testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value); | |
| 255 | testing.expectEqualSlices(u8, "y", infoA.fields[1].name); | |
| 256 | testing.expectEqual(u32, infoA.fields[1].field_type); | |
| 257 | testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value); | |
| 258 | testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls); | |
| 259 | testing.expectEqual(@as(bool, false), infoA.is_tuple); | |
| 251 | try testing.expectEqual(TypeInfo.ContainerLayout.Auto, infoA.layout); | |
| 252 | try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); | |
| 253 | try testing.expectEqual(u8, infoA.fields[0].field_type); | |
| 254 | try testing.expectEqual(@as(?u8, null), infoA.fields[0].default_value); | |
| 255 | try testing.expectEqualSlices(u8, "y", infoA.fields[1].name); | |
| 256 | try testing.expectEqual(u32, infoA.fields[1].field_type); | |
| 257 | try testing.expectEqual(@as(?u32, null), infoA.fields[1].default_value); | |
| 258 | try testing.expectEqualSlices(TypeInfo.Declaration, &[_]TypeInfo.Declaration{}, infoA.decls); | |
| 259 | try testing.expectEqual(@as(bool, false), infoA.is_tuple); | |
| 260 | 260 | |
| 261 | 261 | var a = A{ .x = 0, .y = 1 }; |
| 262 | testing.expectEqual(@as(u8, 0), a.x); | |
| 263 | testing.expectEqual(@as(u32, 1), a.y); | |
| 262 | try testing.expectEqual(@as(u8, 0), a.x); | |
| 263 | try testing.expectEqual(@as(u32, 1), a.y); | |
| 264 | 264 | a.y += 1; |
| 265 | testing.expectEqual(@as(u32, 2), a.y); | |
| 265 | try testing.expectEqual(@as(u32, 2), a.y); | |
| 266 | 266 | |
| 267 | 267 | const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 })); |
| 268 | 268 | const infoB = @typeInfo(B).Struct; |
| 269 | testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout); | |
| 270 | testing.expectEqualSlices(u8, "x", infoB.fields[0].name); | |
| 271 | testing.expectEqual(u8, infoB.fields[0].field_type); | |
| 272 | testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value); | |
| 273 | testing.expectEqualSlices(u8, "y", infoB.fields[1].name); | |
| 274 | testing.expectEqual(u32, infoB.fields[1].field_type); | |
| 275 | testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value); | |
| 276 | testing.expectEqual(@as(usize, 0), infoB.decls.len); | |
| 277 | testing.expectEqual(@as(bool, false), infoB.is_tuple); | |
| 269 | try testing.expectEqual(TypeInfo.ContainerLayout.Extern, infoB.layout); | |
| 270 | try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); | |
| 271 | try testing.expectEqual(u8, infoB.fields[0].field_type); | |
| 272 | try testing.expectEqual(@as(?u8, null), infoB.fields[0].default_value); | |
| 273 | try testing.expectEqualSlices(u8, "y", infoB.fields[1].name); | |
| 274 | try testing.expectEqual(u32, infoB.fields[1].field_type); | |
| 275 | try testing.expectEqual(@as(?u32, 5), infoB.fields[1].default_value); | |
| 276 | try testing.expectEqual(@as(usize, 0), infoB.decls.len); | |
| 277 | try testing.expectEqual(@as(bool, false), infoB.is_tuple); | |
| 278 | 278 | |
| 279 | 279 | const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 })); |
| 280 | 280 | const infoC = @typeInfo(C).Struct; |
| 281 | testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout); | |
| 282 | testing.expectEqualSlices(u8, "x", infoC.fields[0].name); | |
| 283 | testing.expectEqual(u8, infoC.fields[0].field_type); | |
| 284 | testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value); | |
| 285 | testing.expectEqualSlices(u8, "y", infoC.fields[1].name); | |
| 286 | testing.expectEqual(u32, infoC.fields[1].field_type); | |
| 287 | testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value); | |
| 288 | testing.expectEqual(@as(usize, 0), infoC.decls.len); | |
| 289 | testing.expectEqual(@as(bool, false), infoC.is_tuple); | |
| 281 | try testing.expectEqual(TypeInfo.ContainerLayout.Packed, infoC.layout); | |
| 282 | try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); | |
| 283 | try testing.expectEqual(u8, infoC.fields[0].field_type); | |
| 284 | try testing.expectEqual(@as(?u8, 3), infoC.fields[0].default_value); | |
| 285 | try testing.expectEqualSlices(u8, "y", infoC.fields[1].name); | |
| 286 | try testing.expectEqual(u32, infoC.fields[1].field_type); | |
| 287 | try testing.expectEqual(@as(?u32, 5), infoC.fields[1].default_value); | |
| 288 | try testing.expectEqual(@as(usize, 0), infoC.decls.len); | |
| 289 | try testing.expectEqual(@as(bool, false), infoC.is_tuple); | |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | test "Type.Enum" { |
| ... | ... | @@ -302,9 +302,9 @@ test "Type.Enum" { |
| 302 | 302 | .is_exhaustive = true, |
| 303 | 303 | }, |
| 304 | 304 | }); |
| 305 | testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive); | |
| 306 | testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a)); | |
| 307 | testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b)); | |
| 305 | try testing.expectEqual(true, @typeInfo(Foo).Enum.is_exhaustive); | |
| 306 | try testing.expectEqual(@as(u8, 1), @enumToInt(Foo.a)); | |
| 307 | try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b)); | |
| 308 | 308 | const Bar = @Type(.{ |
| 309 | 309 | .Enum = .{ |
| 310 | 310 | .layout = .Extern, |
| ... | ... | @@ -317,10 +317,10 @@ test "Type.Enum" { |
| 317 | 317 | .is_exhaustive = false, |
| 318 | 318 | }, |
| 319 | 319 | }); |
| 320 | testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive); | |
| 321 | testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a)); | |
| 322 | testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b)); | |
| 323 | testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6))); | |
| 320 | try testing.expectEqual(false, @typeInfo(Bar).Enum.is_exhaustive); | |
| 321 | try testing.expectEqual(@as(u32, 1), @enumToInt(Bar.a)); | |
| 322 | try testing.expectEqual(@as(u32, 5), @enumToInt(Bar.b)); | |
| 323 | try testing.expectEqual(@as(u32, 6), @enumToInt(@intToEnum(Bar, 6))); | |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | test "Type.Union" { |
| ... | ... | @@ -338,7 +338,7 @@ test "Type.Union" { |
| 338 | 338 | var untagged = Untagged{ .int = 1 }; |
| 339 | 339 | untagged.float = 2.0; |
| 340 | 340 | untagged.int = 3; |
| 341 | testing.expectEqual(@as(i32, 3), untagged.int); | |
| 341 | try testing.expectEqual(@as(i32, 3), untagged.int); | |
| 342 | 342 | |
| 343 | 343 | const PackedUntagged = @Type(.{ |
| 344 | 344 | .Union = .{ |
| ... | ... | @@ -352,8 +352,8 @@ test "Type.Union" { |
| 352 | 352 | }, |
| 353 | 353 | }); |
| 354 | 354 | var packed_untagged = PackedUntagged{ .signed = -1 }; |
| 355 | testing.expectEqual(@as(i32, -1), packed_untagged.signed); | |
| 356 | testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); | |
| 355 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); | |
| 356 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); | |
| 357 | 357 | |
| 358 | 358 | const Tag = @Type(.{ |
| 359 | 359 | .Enum = .{ |
| ... | ... | @@ -379,9 +379,9 @@ test "Type.Union" { |
| 379 | 379 | }, |
| 380 | 380 | }); |
| 381 | 381 | var tagged = Tagged{ .signed = -1 }; |
| 382 | testing.expectEqual(Tag.signed, tagged); | |
| 382 | try testing.expectEqual(Tag.signed, tagged); | |
| 383 | 383 | tagged = .{ .unsigned = 1 }; |
| 384 | testing.expectEqual(Tag.unsigned, tagged); | |
| 384 | try testing.expectEqual(Tag.unsigned, tagged); | |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | test "Type.Union from Type.Enum" { |
| ... | ... | @@ -447,7 +447,7 @@ test "Type.BoundFn" { |
| 447 | 447 | pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {} |
| 448 | 448 | }; |
| 449 | 449 | const test_instance: TestStruct = undefined; |
| 450 | testing.expect(std.meta.eql( | |
| 450 | try testing.expect(std.meta.eql( | |
| 451 | 451 | @typeName(@TypeOf(test_instance.foo)), |
| 452 | 452 | @typeName(@Type(@typeInfo(@TypeOf(test_instance.foo)))), |
| 453 | 453 | )); |
test/stage1/behavior/type_info.zig+187-187| ... | ... | @@ -9,151 +9,151 @@ const expect = std.testing.expect; |
| 9 | 9 | const expectEqualStrings = std.testing.expectEqualStrings; |
| 10 | 10 | |
| 11 | 11 | test "type info: tag type, void info" { |
| 12 | testBasic(); | |
| 13 | comptime testBasic(); | |
| 12 | try testBasic(); | |
| 13 | comptime try testBasic(); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | fn testBasic() void { | |
| 17 | expect(@typeInfo(TypeInfo).Union.tag_type == TypeId); | |
| 16 | fn testBasic() !void { | |
| 17 | try expect(@typeInfo(TypeInfo).Union.tag_type == TypeId); | |
| 18 | 18 | const void_info = @typeInfo(void); |
| 19 | expect(void_info == TypeId.Void); | |
| 20 | expect(void_info.Void == {}); | |
| 19 | try expect(void_info == TypeId.Void); | |
| 20 | try expect(void_info.Void == {}); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | test "type info: integer, floating point type info" { |
| 24 | testIntFloat(); | |
| 25 | comptime testIntFloat(); | |
| 24 | try testIntFloat(); | |
| 25 | comptime try testIntFloat(); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | fn testIntFloat() void { | |
| 28 | fn testIntFloat() !void { | |
| 29 | 29 | const u8_info = @typeInfo(u8); |
| 30 | expect(u8_info == .Int); | |
| 31 | expect(u8_info.Int.signedness == .unsigned); | |
| 32 | expect(u8_info.Int.bits == 8); | |
| 30 | try expect(u8_info == .Int); | |
| 31 | try expect(u8_info.Int.signedness == .unsigned); | |
| 32 | try expect(u8_info.Int.bits == 8); | |
| 33 | 33 | |
| 34 | 34 | const f64_info = @typeInfo(f64); |
| 35 | expect(f64_info == .Float); | |
| 36 | expect(f64_info.Float.bits == 64); | |
| 35 | try expect(f64_info == .Float); | |
| 36 | try expect(f64_info.Float.bits == 64); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | test "type info: pointer type info" { |
| 40 | testPointer(); | |
| 41 | comptime testPointer(); | |
| 40 | try testPointer(); | |
| 41 | comptime try testPointer(); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | fn testPointer() void { | |
| 44 | fn testPointer() !void { | |
| 45 | 45 | const u32_ptr_info = @typeInfo(*u32); |
| 46 | expect(u32_ptr_info == .Pointer); | |
| 47 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); | |
| 48 | expect(u32_ptr_info.Pointer.is_const == false); | |
| 49 | expect(u32_ptr_info.Pointer.is_volatile == false); | |
| 50 | expect(u32_ptr_info.Pointer.alignment == @alignOf(u32)); | |
| 51 | expect(u32_ptr_info.Pointer.child == u32); | |
| 52 | expect(u32_ptr_info.Pointer.sentinel == null); | |
| 46 | try expect(u32_ptr_info == .Pointer); | |
| 47 | try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); | |
| 48 | try expect(u32_ptr_info.Pointer.is_const == false); | |
| 49 | try expect(u32_ptr_info.Pointer.is_volatile == false); | |
| 50 | try expect(u32_ptr_info.Pointer.alignment == @alignOf(u32)); | |
| 51 | try expect(u32_ptr_info.Pointer.child == u32); | |
| 52 | try expect(u32_ptr_info.Pointer.sentinel == null); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "type info: unknown length pointer type info" { |
| 56 | testUnknownLenPtr(); | |
| 57 | comptime testUnknownLenPtr(); | |
| 56 | try testUnknownLenPtr(); | |
| 57 | comptime try testUnknownLenPtr(); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | fn testUnknownLenPtr() void { | |
| 60 | fn testUnknownLenPtr() !void { | |
| 61 | 61 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 62 | expect(u32_ptr_info == .Pointer); | |
| 63 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 64 | expect(u32_ptr_info.Pointer.is_const == true); | |
| 65 | expect(u32_ptr_info.Pointer.is_volatile == true); | |
| 66 | expect(u32_ptr_info.Pointer.sentinel == null); | |
| 67 | expect(u32_ptr_info.Pointer.alignment == @alignOf(f64)); | |
| 68 | expect(u32_ptr_info.Pointer.child == f64); | |
| 62 | try expect(u32_ptr_info == .Pointer); | |
| 63 | try expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 64 | try expect(u32_ptr_info.Pointer.is_const == true); | |
| 65 | try expect(u32_ptr_info.Pointer.is_volatile == true); | |
| 66 | try expect(u32_ptr_info.Pointer.sentinel == null); | |
| 67 | try expect(u32_ptr_info.Pointer.alignment == @alignOf(f64)); | |
| 68 | try expect(u32_ptr_info.Pointer.child == f64); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | test "type info: null terminated pointer type info" { |
| 72 | testNullTerminatedPtr(); | |
| 73 | comptime testNullTerminatedPtr(); | |
| 72 | try testNullTerminatedPtr(); | |
| 73 | comptime try testNullTerminatedPtr(); | |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | fn testNullTerminatedPtr() void { | |
| 76 | fn testNullTerminatedPtr() !void { | |
| 77 | 77 | const ptr_info = @typeInfo([*:0]u8); |
| 78 | expect(ptr_info == .Pointer); | |
| 79 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 80 | expect(ptr_info.Pointer.is_const == false); | |
| 81 | expect(ptr_info.Pointer.is_volatile == false); | |
| 82 | expect(ptr_info.Pointer.sentinel.? == 0); | |
| 78 | try expect(ptr_info == .Pointer); | |
| 79 | try expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); | |
| 80 | try expect(ptr_info.Pointer.is_const == false); | |
| 81 | try expect(ptr_info.Pointer.is_volatile == false); | |
| 82 | try expect(ptr_info.Pointer.sentinel.? == 0); | |
| 83 | 83 | |
| 84 | expect(@typeInfo([:0]u8).Pointer.sentinel != null); | |
| 84 | try expect(@typeInfo([:0]u8).Pointer.sentinel != null); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | test "type info: C pointer type info" { |
| 88 | testCPtr(); | |
| 89 | comptime testCPtr(); | |
| 88 | try testCPtr(); | |
| 89 | comptime try testCPtr(); | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | fn testCPtr() void { | |
| 92 | fn testCPtr() !void { | |
| 93 | 93 | const ptr_info = @typeInfo([*c]align(4) const i8); |
| 94 | expect(ptr_info == .Pointer); | |
| 95 | expect(ptr_info.Pointer.size == .C); | |
| 96 | expect(ptr_info.Pointer.is_const); | |
| 97 | expect(!ptr_info.Pointer.is_volatile); | |
| 98 | expect(ptr_info.Pointer.alignment == 4); | |
| 99 | expect(ptr_info.Pointer.child == i8); | |
| 94 | try expect(ptr_info == .Pointer); | |
| 95 | try expect(ptr_info.Pointer.size == .C); | |
| 96 | try expect(ptr_info.Pointer.is_const); | |
| 97 | try expect(!ptr_info.Pointer.is_volatile); | |
| 98 | try expect(ptr_info.Pointer.alignment == 4); | |
| 99 | try expect(ptr_info.Pointer.child == i8); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "type info: slice type info" { |
| 103 | testSlice(); | |
| 104 | comptime testSlice(); | |
| 103 | try testSlice(); | |
| 104 | comptime try testSlice(); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | fn testSlice() void { | |
| 107 | fn testSlice() !void { | |
| 108 | 108 | const u32_slice_info = @typeInfo([]u32); |
| 109 | expect(u32_slice_info == .Pointer); | |
| 110 | expect(u32_slice_info.Pointer.size == .Slice); | |
| 111 | expect(u32_slice_info.Pointer.is_const == false); | |
| 112 | expect(u32_slice_info.Pointer.is_volatile == false); | |
| 113 | expect(u32_slice_info.Pointer.alignment == 4); | |
| 114 | expect(u32_slice_info.Pointer.child == u32); | |
| 109 | try expect(u32_slice_info == .Pointer); | |
| 110 | try expect(u32_slice_info.Pointer.size == .Slice); | |
| 111 | try expect(u32_slice_info.Pointer.is_const == false); | |
| 112 | try expect(u32_slice_info.Pointer.is_volatile == false); | |
| 113 | try expect(u32_slice_info.Pointer.alignment == 4); | |
| 114 | try expect(u32_slice_info.Pointer.child == u32); | |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | test "type info: array type info" { |
| 118 | testArray(); | |
| 119 | comptime testArray(); | |
| 118 | try testArray(); | |
| 119 | comptime try testArray(); | |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | fn testArray() void { | |
| 122 | fn testArray() !void { | |
| 123 | 123 | { |
| 124 | 124 | const info = @typeInfo([42]u8); |
| 125 | expect(info == .Array); | |
| 126 | expect(info.Array.len == 42); | |
| 127 | expect(info.Array.child == u8); | |
| 128 | expect(info.Array.sentinel == null); | |
| 125 | try expect(info == .Array); | |
| 126 | try expect(info.Array.len == 42); | |
| 127 | try expect(info.Array.child == u8); | |
| 128 | try expect(info.Array.sentinel == null); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | { |
| 132 | 132 | const info = @typeInfo([10:0]u8); |
| 133 | expect(info.Array.len == 10); | |
| 134 | expect(info.Array.child == u8); | |
| 135 | expect(info.Array.sentinel.? == @as(u8, 0)); | |
| 136 | expect(@sizeOf([10:0]u8) == info.Array.len + 1); | |
| 133 | try expect(info.Array.len == 10); | |
| 134 | try expect(info.Array.child == u8); | |
| 135 | try expect(info.Array.sentinel.? == @as(u8, 0)); | |
| 136 | try expect(@sizeOf([10:0]u8) == info.Array.len + 1); | |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | test "type info: optional type info" { |
| 141 | testOptional(); | |
| 142 | comptime testOptional(); | |
| 141 | try testOptional(); | |
| 142 | comptime try testOptional(); | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | fn testOptional() void { | |
| 145 | fn testOptional() !void { | |
| 146 | 146 | const null_info = @typeInfo(?void); |
| 147 | expect(null_info == .Optional); | |
| 148 | expect(null_info.Optional.child == void); | |
| 147 | try expect(null_info == .Optional); | |
| 148 | try expect(null_info.Optional.child == void); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | test "type info: error set, error union info" { |
| 152 | testErrorSet(); | |
| 153 | comptime testErrorSet(); | |
| 152 | try testErrorSet(); | |
| 153 | comptime try testErrorSet(); | |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | fn testErrorSet() void { | |
| 156 | fn testErrorSet() !void { | |
| 157 | 157 | const TestErrorSet = error{ |
| 158 | 158 | First, |
| 159 | 159 | Second, |
| ... | ... | @@ -161,26 +161,26 @@ fn testErrorSet() void { |
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | 163 | const error_set_info = @typeInfo(TestErrorSet); |
| 164 | expect(error_set_info == .ErrorSet); | |
| 165 | expect(error_set_info.ErrorSet.?.len == 3); | |
| 166 | expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); | |
| 164 | try expect(error_set_info == .ErrorSet); | |
| 165 | try expect(error_set_info.ErrorSet.?.len == 3); | |
| 166 | try expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); | |
| 167 | 167 | |
| 168 | 168 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 169 | expect(error_union_info == .ErrorUnion); | |
| 170 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); | |
| 171 | expect(error_union_info.ErrorUnion.payload == usize); | |
| 169 | try expect(error_union_info == .ErrorUnion); | |
| 170 | try expect(error_union_info.ErrorUnion.error_set == TestErrorSet); | |
| 171 | try expect(error_union_info.ErrorUnion.payload == usize); | |
| 172 | 172 | |
| 173 | 173 | const global_info = @typeInfo(anyerror); |
| 174 | expect(global_info == .ErrorSet); | |
| 175 | expect(global_info.ErrorSet == null); | |
| 174 | try expect(global_info == .ErrorSet); | |
| 175 | try expect(global_info.ErrorSet == null); | |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | test "type info: enum info" { |
| 179 | testEnum(); | |
| 180 | comptime testEnum(); | |
| 179 | try testEnum(); | |
| 180 | comptime try testEnum(); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | fn testEnum() void { | |
| 183 | fn testEnum() !void { | |
| 184 | 184 | const Os = enum { |
| 185 | 185 | Windows, |
| 186 | 186 | Macos, |
| ... | ... | @@ -189,28 +189,28 @@ fn testEnum() void { |
| 189 | 189 | }; |
| 190 | 190 | |
| 191 | 191 | const os_info = @typeInfo(Os); |
| 192 | expect(os_info == .Enum); | |
| 193 | expect(os_info.Enum.layout == .Auto); | |
| 194 | expect(os_info.Enum.fields.len == 4); | |
| 195 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); | |
| 196 | expect(os_info.Enum.fields[3].value == 3); | |
| 197 | expect(os_info.Enum.tag_type == u2); | |
| 198 | expect(os_info.Enum.decls.len == 0); | |
| 192 | try expect(os_info == .Enum); | |
| 193 | try expect(os_info.Enum.layout == .Auto); | |
| 194 | try expect(os_info.Enum.fields.len == 4); | |
| 195 | try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); | |
| 196 | try expect(os_info.Enum.fields[3].value == 3); | |
| 197 | try expect(os_info.Enum.tag_type == u2); | |
| 198 | try expect(os_info.Enum.decls.len == 0); | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | test "type info: union info" { |
| 202 | testUnion(); | |
| 203 | comptime testUnion(); | |
| 202 | try testUnion(); | |
| 203 | comptime try testUnion(); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | fn testUnion() void { | |
| 206 | fn testUnion() !void { | |
| 207 | 207 | const typeinfo_info = @typeInfo(TypeInfo); |
| 208 | expect(typeinfo_info == .Union); | |
| 209 | expect(typeinfo_info.Union.layout == .Auto); | |
| 210 | expect(typeinfo_info.Union.tag_type.? == TypeId); | |
| 211 | expect(typeinfo_info.Union.fields.len == 25); | |
| 212 | expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); | |
| 213 | expect(typeinfo_info.Union.decls.len == 22); | |
| 208 | try expect(typeinfo_info == .Union); | |
| 209 | try expect(typeinfo_info.Union.layout == .Auto); | |
| 210 | try expect(typeinfo_info.Union.tag_type.? == TypeId); | |
| 211 | try expect(typeinfo_info.Union.fields.len == 25); | |
| 212 | try expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); | |
| 213 | try expect(typeinfo_info.Union.decls.len == 22); | |
| 214 | 214 | |
| 215 | 215 | const TestNoTagUnion = union { |
| 216 | 216 | Foo: void, |
| ... | ... | @@ -218,52 +218,52 @@ fn testUnion() void { |
| 218 | 218 | }; |
| 219 | 219 | |
| 220 | 220 | const notag_union_info = @typeInfo(TestNoTagUnion); |
| 221 | expect(notag_union_info == .Union); | |
| 222 | expect(notag_union_info.Union.tag_type == null); | |
| 223 | expect(notag_union_info.Union.layout == .Auto); | |
| 224 | expect(notag_union_info.Union.fields.len == 2); | |
| 225 | expect(notag_union_info.Union.fields[0].alignment == @alignOf(void)); | |
| 226 | expect(notag_union_info.Union.fields[1].field_type == u32); | |
| 227 | expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32)); | |
| 221 | try expect(notag_union_info == .Union); | |
| 222 | try expect(notag_union_info.Union.tag_type == null); | |
| 223 | try expect(notag_union_info.Union.layout == .Auto); | |
| 224 | try expect(notag_union_info.Union.fields.len == 2); | |
| 225 | try expect(notag_union_info.Union.fields[0].alignment == @alignOf(void)); | |
| 226 | try expect(notag_union_info.Union.fields[1].field_type == u32); | |
| 227 | try expect(notag_union_info.Union.fields[1].alignment == @alignOf(u32)); | |
| 228 | 228 | |
| 229 | 229 | const TestExternUnion = extern union { |
| 230 | 230 | foo: *c_void, |
| 231 | 231 | }; |
| 232 | 232 | |
| 233 | 233 | const extern_union_info = @typeInfo(TestExternUnion); |
| 234 | expect(extern_union_info.Union.layout == .Extern); | |
| 235 | expect(extern_union_info.Union.tag_type == null); | |
| 236 | expect(extern_union_info.Union.fields[0].field_type == *c_void); | |
| 234 | try expect(extern_union_info.Union.layout == .Extern); | |
| 235 | try expect(extern_union_info.Union.tag_type == null); | |
| 236 | try expect(extern_union_info.Union.fields[0].field_type == *c_void); | |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | test "type info: struct info" { |
| 240 | testStruct(); | |
| 241 | comptime testStruct(); | |
| 240 | try testStruct(); | |
| 241 | comptime try testStruct(); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | fn testStruct() void { | |
| 244 | fn testStruct() !void { | |
| 245 | 245 | const unpacked_struct_info = @typeInfo(TestUnpackedStruct); |
| 246 | expect(unpacked_struct_info.Struct.is_tuple == false); | |
| 247 | expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32)); | |
| 248 | expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4); | |
| 249 | expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?); | |
| 246 | try expect(unpacked_struct_info.Struct.is_tuple == false); | |
| 247 | try expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32)); | |
| 248 | try expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4); | |
| 249 | try expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?); | |
| 250 | 250 | |
| 251 | 251 | const struct_info = @typeInfo(TestStruct); |
| 252 | expect(struct_info == .Struct); | |
| 253 | expect(struct_info.Struct.is_tuple == false); | |
| 254 | expect(struct_info.Struct.layout == .Packed); | |
| 255 | expect(struct_info.Struct.fields.len == 4); | |
| 256 | expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize)); | |
| 257 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); | |
| 258 | expect(struct_info.Struct.fields[2].default_value == null); | |
| 259 | expect(struct_info.Struct.fields[3].default_value.? == 4); | |
| 260 | expect(struct_info.Struct.fields[3].alignment == 1); | |
| 261 | expect(struct_info.Struct.decls.len == 2); | |
| 262 | expect(struct_info.Struct.decls[0].is_pub); | |
| 263 | expect(!struct_info.Struct.decls[0].data.Fn.is_extern); | |
| 264 | expect(struct_info.Struct.decls[0].data.Fn.lib_name == null); | |
| 265 | expect(struct_info.Struct.decls[0].data.Fn.return_type == void); | |
| 266 | expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void); | |
| 252 | try expect(struct_info == .Struct); | |
| 253 | try expect(struct_info.Struct.is_tuple == false); | |
| 254 | try expect(struct_info.Struct.layout == .Packed); | |
| 255 | try expect(struct_info.Struct.fields.len == 4); | |
| 256 | try expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize)); | |
| 257 | try expect(struct_info.Struct.fields[2].field_type == *TestStruct); | |
| 258 | try expect(struct_info.Struct.fields[2].default_value == null); | |
| 259 | try expect(struct_info.Struct.fields[3].default_value.? == 4); | |
| 260 | try expect(struct_info.Struct.fields[3].alignment == 1); | |
| 261 | try expect(struct_info.Struct.decls.len == 2); | |
| 262 | try expect(struct_info.Struct.decls[0].is_pub); | |
| 263 | try expect(!struct_info.Struct.decls[0].data.Fn.is_extern); | |
| 264 | try expect(struct_info.Struct.decls[0].data.Fn.lib_name == null); | |
| 265 | try expect(struct_info.Struct.decls[0].data.Fn.return_type == void); | |
| 266 | try expect(struct_info.Struct.decls[0].data.Fn.fn_type == fn (*const TestStruct) void); | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | const TestUnpackedStruct = struct { |
| ... | ... | @@ -282,43 +282,43 @@ const TestStruct = packed struct { |
| 282 | 282 | }; |
| 283 | 283 | |
| 284 | 284 | test "type info: opaque info" { |
| 285 | testOpaque(); | |
| 286 | comptime testOpaque(); | |
| 285 | try testOpaque(); | |
| 286 | comptime try testOpaque(); | |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | fn testOpaque() void { | |
| 289 | fn testOpaque() !void { | |
| 290 | 290 | const Foo = opaque { |
| 291 | 291 | const A = 1; |
| 292 | 292 | fn b() void {} |
| 293 | 293 | }; |
| 294 | 294 | |
| 295 | 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 | } |
| 298 | 298 | |
| 299 | 299 | test "type info: function type info" { |
| 300 | 300 | // wasm doesn't support align attributes on functions |
| 301 | 301 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
| 302 | testFunction(); | |
| 303 | comptime testFunction(); | |
| 302 | try testFunction(); | |
| 303 | comptime try testFunction(); | |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | fn testFunction() void { | |
| 306 | fn testFunction() !void { | |
| 307 | 307 | const fn_info = @typeInfo(@TypeOf(foo)); |
| 308 | expect(fn_info == .Fn); | |
| 309 | expect(fn_info.Fn.alignment > 0); | |
| 310 | expect(fn_info.Fn.calling_convention == .C); | |
| 311 | expect(!fn_info.Fn.is_generic); | |
| 312 | expect(fn_info.Fn.args.len == 2); | |
| 313 | expect(fn_info.Fn.is_var_args); | |
| 314 | expect(fn_info.Fn.return_type.? == usize); | |
| 308 | try expect(fn_info == .Fn); | |
| 309 | try expect(fn_info.Fn.alignment > 0); | |
| 310 | try expect(fn_info.Fn.calling_convention == .C); | |
| 311 | try expect(!fn_info.Fn.is_generic); | |
| 312 | try expect(fn_info.Fn.args.len == 2); | |
| 313 | try expect(fn_info.Fn.is_var_args); | |
| 314 | try expect(fn_info.Fn.return_type.? == usize); | |
| 315 | 315 | const fn_aligned_info = @typeInfo(@TypeOf(fooAligned)); |
| 316 | expect(fn_aligned_info.Fn.alignment == 4); | |
| 316 | try expect(fn_aligned_info.Fn.alignment == 4); | |
| 317 | 317 | |
| 318 | 318 | const test_instance: TestStruct = undefined; |
| 319 | 319 | const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo)); |
| 320 | expect(bound_fn_info == .BoundFn); | |
| 321 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); | |
| 320 | try expect(bound_fn_info == .BoundFn); | |
| 321 | try expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); | |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | extern fn foo(a: usize, b: bool, ...) callconv(.C) usize; |
| ... | ... | @@ -332,33 +332,33 @@ test "typeInfo with comptime parameter in struct fn def" { |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | test "type info: vectors" { |
| 335 | testVector(); | |
| 336 | comptime testVector(); | |
| 335 | try testVector(); | |
| 336 | comptime try testVector(); | |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | fn testVector() void { | |
| 339 | fn testVector() !void { | |
| 340 | 340 | const vec_info = @typeInfo(std.meta.Vector(4, i32)); |
| 341 | expect(vec_info == .Vector); | |
| 342 | expect(vec_info.Vector.len == 4); | |
| 343 | expect(vec_info.Vector.child == i32); | |
| 341 | try expect(vec_info == .Vector); | |
| 342 | try expect(vec_info.Vector.len == 4); | |
| 343 | try expect(vec_info.Vector.child == i32); | |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | test "type info: anyframe and anyframe->T" { |
| 347 | testAnyFrame(); | |
| 348 | comptime testAnyFrame(); | |
| 347 | try testAnyFrame(); | |
| 348 | comptime try testAnyFrame(); | |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | fn testAnyFrame() void { | |
| 351 | fn testAnyFrame() !void { | |
| 352 | 352 | { |
| 353 | 353 | const anyframe_info = @typeInfo(anyframe->i32); |
| 354 | expect(anyframe_info == .AnyFrame); | |
| 355 | expect(anyframe_info.AnyFrame.child.? == i32); | |
| 354 | try expect(anyframe_info == .AnyFrame); | |
| 355 | try expect(anyframe_info.AnyFrame.child.? == i32); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | { |
| 359 | 359 | const anyframe_info = @typeInfo(anyframe); |
| 360 | expect(anyframe_info == .AnyFrame); | |
| 361 | expect(anyframe_info.AnyFrame.child == null); | |
| 360 | try expect(anyframe_info == .AnyFrame); | |
| 361 | try expect(anyframe_info.AnyFrame.child == null); | |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| ... | ... | @@ -385,9 +385,9 @@ test "type info: extern fns with and without lib names" { |
| 385 | 385 | comptime { |
| 386 | 386 | for (info.Struct.decls) |decl| { |
| 387 | 387 | if (std.mem.eql(u8, decl.name, "bar1")) { |
| 388 | expect(decl.data.Fn.lib_name == null); | |
| 388 | try expect(decl.data.Fn.lib_name == null); | |
| 389 | 389 | } else { |
| 390 | expectEqualStrings("cool", decl.data.Fn.lib_name.?); | |
| 390 | try expectEqualStrings("cool", decl.data.Fn.lib_name.?); | |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
| ... | ... | @@ -397,12 +397,12 @@ test "data field is a compile-time value" { |
| 397 | 397 | const S = struct { |
| 398 | 398 | const Bar = @as(isize, -1); |
| 399 | 399 | }; |
| 400 | comptime expect(@typeInfo(S).Struct.decls[0].data.Var == isize); | |
| 400 | comptime try expect(@typeInfo(S).Struct.decls[0].data.Var == isize); | |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | test "sentinel of opaque pointer type" { |
| 404 | 404 | const c_void_info = @typeInfo(*c_void); |
| 405 | expect(c_void_info.Pointer.sentinel == null); | |
| 405 | try expect(c_void_info.Pointer.sentinel == null); | |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | test "@typeInfo does not force declarations into existence" { |
| ... | ... | @@ -413,12 +413,12 @@ test "@typeInfo does not force declarations into existence" { |
| 413 | 413 | @compileError("test failed"); |
| 414 | 414 | } |
| 415 | 415 | }; |
| 416 | comptime expect(@typeInfo(S).Struct.fields.len == 1); | |
| 416 | comptime try expect(@typeInfo(S).Struct.fields.len == 1); | |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | test "defaut value for a var-typed field" { |
| 420 | 420 | const S = struct { x: anytype }; |
| 421 | expect(@typeInfo(S).Struct.fields[0].default_value == null); | |
| 421 | try expect(@typeInfo(S).Struct.fields[0].default_value == null); | |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -428,7 +428,7 @@ fn add(a: i32, b: i32) i32 { |
| 428 | 428 | test "type info for async frames" { |
| 429 | 429 | switch (@typeInfo(@Frame(add))) { |
| 430 | 430 | .Frame => |frame| { |
| 431 | expect(frame.function == add); | |
| 431 | try expect(frame.function == add); | |
| 432 | 432 | }, |
| 433 | 433 | else => unreachable, |
| 434 | 434 | } |
| ... | ... | @@ -438,7 +438,7 @@ test "type info: value is correctly copied" { |
| 438 | 438 | comptime { |
| 439 | 439 | var ptrInfo = @typeInfo([]u32); |
| 440 | 440 | ptrInfo.Pointer.size = .One; |
| 441 | expect(@typeInfo([]u32).Pointer.size == .Slice); | |
| 441 | try expect(@typeInfo([]u32).Pointer.size == .Slice); | |
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | |
| ... | ... | @@ -451,22 +451,22 @@ test "Declarations are returned in declaration order" { |
| 451 | 451 | const e = 5; |
| 452 | 452 | }; |
| 453 | 453 | const d = @typeInfo(S).Struct.decls; |
| 454 | expect(std.mem.eql(u8, d[0].name, "a")); | |
| 455 | expect(std.mem.eql(u8, d[1].name, "b")); | |
| 456 | expect(std.mem.eql(u8, d[2].name, "c")); | |
| 457 | expect(std.mem.eql(u8, d[3].name, "d")); | |
| 458 | expect(std.mem.eql(u8, d[4].name, "e")); | |
| 454 | try expect(std.mem.eql(u8, d[0].name, "a")); | |
| 455 | try expect(std.mem.eql(u8, d[1].name, "b")); | |
| 456 | try expect(std.mem.eql(u8, d[2].name, "c")); | |
| 457 | try expect(std.mem.eql(u8, d[3].name, "d")); | |
| 458 | try expect(std.mem.eql(u8, d[4].name, "e")); | |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | test "Struct.is_tuple" { |
| 462 | expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple); | |
| 463 | expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple); | |
| 462 | try expect(@typeInfo(@TypeOf(.{0})).Struct.is_tuple); | |
| 463 | try expect(!@typeInfo(@TypeOf(.{ .a = 0 })).Struct.is_tuple); | |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | test "StructField.is_comptime" { |
| 467 | 467 | const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).Struct; |
| 468 | expect(!info.fields[0].is_comptime); | |
| 469 | expect(info.fields[1].is_comptime); | |
| 468 | try expect(!info.fields[0].is_comptime); | |
| 469 | try expect(info.fields[1].is_comptime); | |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | test "typeInfo resolves usingnamespace declarations" { |
| ... | ... | @@ -479,6 +479,6 @@ test "typeInfo resolves usingnamespace declarations" { |
| 479 | 479 | usingnamespace A; |
| 480 | 480 | }; |
| 481 | 481 | |
| 482 | expect(@typeInfo(B).Struct.decls.len == 2); | |
| 482 | try expect(@typeInfo(B).Struct.decls.len == 2); | |
| 483 | 483 | //a |
| 484 | 484 | } |
test/stage1/behavior/typename.zig+1-1| ... | ... | @@ -3,5 +3,5 @@ const expect = std.testing.expect; |
| 3 | 3 | const expectEqualSlices = std.testing.expectEqualSlices; |
| 4 | 4 | |
| 5 | 5 | test "slice" { |
| 6 | expectEqualSlices(u8, "[]u8", @typeName([]u8)); | |
| 6 | try expectEqualSlices(u8, "[]u8", @typeName([]u8)); | |
| 7 | 7 | } |
test/stage1/behavior/undefined.zig+13-13| ... | ... | @@ -12,16 +12,16 @@ fn initStaticArray() [10]i32 { |
| 12 | 12 | } |
| 13 | 13 | const static_array = initStaticArray(); |
| 14 | 14 | test "init static array to undefined" { |
| 15 | expect(static_array[0] == 1); | |
| 16 | expect(static_array[4] == 2); | |
| 17 | expect(static_array[7] == 3); | |
| 18 | expect(static_array[9] == 4); | |
| 15 | try expect(static_array[0] == 1); | |
| 16 | try expect(static_array[4] == 2); | |
| 17 | try expect(static_array[7] == 3); | |
| 18 | try expect(static_array[9] == 4); | |
| 19 | 19 | |
| 20 | 20 | comptime { |
| 21 | expect(static_array[0] == 1); | |
| 22 | expect(static_array[4] == 2); | |
| 23 | expect(static_array[7] == 3); | |
| 24 | expect(static_array[9] == 4); | |
| 21 | try expect(static_array[0] == 1); | |
| 22 | try expect(static_array[4] == 2); | |
| 23 | try expect(static_array[7] == 3); | |
| 24 | try expect(static_array[9] == 4); | |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
| ... | ... | @@ -41,12 +41,12 @@ test "assign undefined to struct" { |
| 41 | 41 | comptime { |
| 42 | 42 | var foo: Foo = undefined; |
| 43 | 43 | setFooX(&foo); |
| 44 | expect(foo.x == 2); | |
| 44 | try expect(foo.x == 2); | |
| 45 | 45 | } |
| 46 | 46 | { |
| 47 | 47 | var foo: Foo = undefined; |
| 48 | 48 | setFooX(&foo); |
| 49 | expect(foo.x == 2); | |
| 49 | try expect(foo.x == 2); | |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| ... | ... | @@ -54,16 +54,16 @@ test "assign undefined to struct with method" { |
| 54 | 54 | comptime { |
| 55 | 55 | var foo: Foo = undefined; |
| 56 | 56 | foo.setFooXMethod(); |
| 57 | expect(foo.x == 3); | |
| 57 | try expect(foo.x == 3); | |
| 58 | 58 | } |
| 59 | 59 | { |
| 60 | 60 | var foo: Foo = undefined; |
| 61 | 61 | foo.setFooXMethod(); |
| 62 | expect(foo.x == 3); | |
| 62 | try expect(foo.x == 3); | |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | test "type name of undefined" { |
| 67 | 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/stage1/behavior/union.zig+142-142| ... | ... | @@ -30,11 +30,11 @@ const array = [_]Value{ |
| 30 | 30 | |
| 31 | 31 | test "unions embedded in aggregate types" { |
| 32 | 32 | switch (array[1]) { |
| 33 | Value.Array => |arr| expect(arr[4] == 3), | |
| 33 | Value.Array => |arr| try expect(arr[4] == 3), | |
| 34 | 34 | else => unreachable, |
| 35 | 35 | } |
| 36 | 36 | switch ((err catch unreachable).val1) { |
| 37 | Value.Int => |x| expect(x == 1234), | |
| 37 | Value.Int => |x| try expect(x == 1234), | |
| 38 | 38 | else => unreachable, |
| 39 | 39 | } |
| 40 | 40 | } |
| ... | ... | @@ -46,18 +46,18 @@ const Foo = union { |
| 46 | 46 | |
| 47 | 47 | test "basic unions" { |
| 48 | 48 | var foo = Foo{ .int = 1 }; |
| 49 | expect(foo.int == 1); | |
| 49 | try expect(foo.int == 1); | |
| 50 | 50 | foo = Foo{ .float = 12.34 }; |
| 51 | expect(foo.float == 12.34); | |
| 51 | try expect(foo.float == 12.34); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | test "comptime union field access" { |
| 55 | 55 | comptime { |
| 56 | 56 | var foo = Foo{ .int = 0 }; |
| 57 | expect(foo.int == 0); | |
| 57 | try expect(foo.int == 0); | |
| 58 | 58 | |
| 59 | 59 | foo = Foo{ .float = 42.42 }; |
| 60 | expect(foo.float == 42.42); | |
| 60 | try expect(foo.float == 42.42); | |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -65,10 +65,10 @@ test "init union with runtime value" { |
| 65 | 65 | var foo: Foo = undefined; |
| 66 | 66 | |
| 67 | 67 | setFloat(&foo, 12.34); |
| 68 | expect(foo.float == 12.34); | |
| 68 | try expect(foo.float == 12.34); | |
| 69 | 69 | |
| 70 | 70 | setInt(&foo, 42); |
| 71 | expect(foo.int == 42); | |
| 71 | try expect(foo.int == 42); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | fn setFloat(foo: *Foo, x: f64) void { |
| ... | ... | @@ -86,9 +86,9 @@ const FooExtern = extern union { |
| 86 | 86 | |
| 87 | 87 | test "basic extern unions" { |
| 88 | 88 | var foo = FooExtern{ .int = 1 }; |
| 89 | expect(foo.int == 1); | |
| 89 | try expect(foo.int == 1); | |
| 90 | 90 | foo.float = 12.34; |
| 91 | expect(foo.float == 12.34); | |
| 91 | try expect(foo.float == 12.34); | |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | const Letter = enum { |
| ... | ... | @@ -103,16 +103,16 @@ const Payload = union(Letter) { |
| 103 | 103 | }; |
| 104 | 104 | |
| 105 | 105 | test "union with specified enum tag" { |
| 106 | doTest(); | |
| 107 | comptime doTest(); | |
| 106 | try doTest(); | |
| 107 | comptime try doTest(); | |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | fn doTest() void { | |
| 111 | expect(bar(Payload{ .A = 1234 }) == -10); | |
| 110 | fn doTest() !void { | |
| 111 | try expect((try bar(Payload{ .A = 1234 })) == -10); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | fn bar(value: Payload) i32 { | |
| 115 | expect(@as(Letter, value) == Letter.A); | |
| 114 | fn bar(value: Payload) !i32 { | |
| 115 | try expect(@as(Letter, value) == Letter.A); | |
| 116 | 116 | return switch (value) { |
| 117 | 117 | Payload.A => |x| return x - 1244, |
| 118 | 118 | Payload.B => |x| if (x == 12.34) @as(i32, 20) else 21, |
| ... | ... | @@ -128,8 +128,8 @@ const MultipleChoice = union(enum(u32)) { |
| 128 | 128 | }; |
| 129 | 129 | test "simple union(enum(u32))" { |
| 130 | 130 | var x = MultipleChoice.C; |
| 131 | expect(x == MultipleChoice.C); | |
| 132 | expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60); | |
| 131 | try expect(x == MultipleChoice.C); | |
| 132 | try expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | const MultipleChoice2 = union(enum(u32)) { |
| ... | ... | @@ -145,14 +145,14 @@ const MultipleChoice2 = union(enum(u32)) { |
| 145 | 145 | }; |
| 146 | 146 | |
| 147 | 147 | test "union(enum(u32)) with specified and unspecified tag values" { |
| 148 | comptime expect(Tag(Tag(MultipleChoice2)) == u32); | |
| 149 | testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); | |
| 150 | comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); | |
| 148 | comptime try expect(Tag(Tag(MultipleChoice2)) == u32); | |
| 149 | try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); | |
| 150 | comptime try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void { | |
| 154 | expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60); | |
| 155 | expect(1123 == switch (x) { | |
| 153 | fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) !void { | |
| 154 | try expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60); | |
| 155 | try expect(1123 == switch (x) { | |
| 156 | 156 | MultipleChoice2.A => 1, |
| 157 | 157 | MultipleChoice2.B => 2, |
| 158 | 158 | MultipleChoice2.C => |v| @as(i32, 1000) + v, |
| ... | ... | @@ -170,7 +170,7 @@ const ExternPtrOrInt = extern union { |
| 170 | 170 | int: u64, |
| 171 | 171 | }; |
| 172 | 172 | test "extern union size" { |
| 173 | comptime expect(@sizeOf(ExternPtrOrInt) == 8); | |
| 173 | comptime try expect(@sizeOf(ExternPtrOrInt) == 8); | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | const PackedPtrOrInt = packed union { |
| ... | ... | @@ -178,14 +178,14 @@ const PackedPtrOrInt = packed union { |
| 178 | 178 | int: u64, |
| 179 | 179 | }; |
| 180 | 180 | test "extern union size" { |
| 181 | comptime expect(@sizeOf(PackedPtrOrInt) == 8); | |
| 181 | comptime try expect(@sizeOf(PackedPtrOrInt) == 8); | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | const ZeroBits = union { |
| 185 | 185 | OnlyField: void, |
| 186 | 186 | }; |
| 187 | 187 | test "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 | } |
| 190 | 190 | |
| 191 | 191 | const TheTag = enum { |
| ... | ... | @@ -199,23 +199,23 @@ const TheUnion = union(TheTag) { |
| 199 | 199 | C: i32, |
| 200 | 200 | }; |
| 201 | 201 | test "union field access gives the enum values" { |
| 202 | expect(TheUnion.A == TheTag.A); | |
| 203 | expect(TheUnion.B == TheTag.B); | |
| 204 | expect(TheUnion.C == TheTag.C); | |
| 202 | try expect(TheUnion.A == TheTag.A); | |
| 203 | try expect(TheUnion.B == TheTag.B); | |
| 204 | try expect(TheUnion.C == TheTag.C); | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | test "cast union to tag type of union" { |
| 208 | testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 209 | comptime testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 208 | try testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 209 | comptime try testCastUnionToTag(TheUnion{ .B = 1234 }); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | fn testCastUnionToTag(x: TheUnion) void { | |
| 213 | expect(@as(TheTag, x) == TheTag.B); | |
| 212 | fn testCastUnionToTag(x: TheUnion) !void { | |
| 213 | try expect(@as(TheTag, x) == TheTag.B); | |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | test "cast tag type of union to union" { |
| 217 | 217 | var x: Value2 = Letter2.B; |
| 218 | expect(@as(Letter2, x) == Letter2.B); | |
| 218 | try expect(@as(Letter2, x) == Letter2.B); | |
| 219 | 219 | } |
| 220 | 220 | const Letter2 = enum { |
| 221 | 221 | A, |
| ... | ... | @@ -230,11 +230,11 @@ const Value2 = union(Letter2) { |
| 230 | 230 | |
| 231 | 231 | test "implicit cast union to its tag type" { |
| 232 | 232 | var x: Value2 = Letter2.B; |
| 233 | expect(x == Letter2.B); | |
| 234 | giveMeLetterB(x); | |
| 233 | try expect(x == Letter2.B); | |
| 234 | try giveMeLetterB(x); | |
| 235 | 235 | } |
| 236 | fn giveMeLetterB(x: Letter2) void { | |
| 237 | expect(x == Value2.B); | |
| 236 | fn giveMeLetterB(x: Letter2) !void { | |
| 237 | try expect(x == Value2.B); | |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | pub const PackThis = union(enum) { |
| ... | ... | @@ -243,11 +243,11 @@ pub const PackThis = union(enum) { |
| 243 | 243 | }; |
| 244 | 244 | |
| 245 | 245 | test "constant packed union" { |
| 246 | testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }}); | |
| 246 | try testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }}); | |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | fn testConstPackedUnion(expected_tokens: []const PackThis) void { | |
| 250 | expect(expected_tokens[0].StringLiteral == 1); | |
| 249 | fn testConstPackedUnion(expected_tokens: []const PackThis) !void { | |
| 250 | try expect(expected_tokens[0].StringLiteral == 1); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | test "switch on union with only 1 field" { |
| ... | ... | @@ -259,7 +259,7 @@ test "switch on union with only 1 field" { |
| 259 | 259 | z = PartialInstWithPayload{ .Compiled = 1234 }; |
| 260 | 260 | switch (z) { |
| 261 | 261 | PartialInstWithPayload.Compiled => |x| { |
| 262 | expect(x == 1234); | |
| 262 | try expect(x == 1234); | |
| 263 | 263 | return; |
| 264 | 264 | }, |
| 265 | 265 | } |
| ... | ... | @@ -285,11 +285,11 @@ test "access a member of tagged union with conflicting enum tag name" { |
| 285 | 285 | const B = void; |
| 286 | 286 | }; |
| 287 | 287 | |
| 288 | comptime expect(Bar.A == u8); | |
| 288 | comptime try expect(Bar.A == u8); | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | test "tagged union initialization with runtime void" { |
| 292 | expect(testTaggedUnionInit({})); | |
| 292 | try expect(testTaggedUnionInit({})); | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | const TaggedUnionWithAVoid = union(enum) { |
| ... | ... | @@ -327,9 +327,9 @@ test "union with only 1 field casted to its enum type" { |
| 327 | 327 | |
| 328 | 328 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 329 | 329 | const ExprTag = Tag(Expr); |
| 330 | comptime expect(Tag(ExprTag) == u0); | |
| 330 | comptime try expect(Tag(ExprTag) == u0); | |
| 331 | 331 | var t = @as(ExprTag, e); |
| 332 | expect(t == Expr.Literal); | |
| 332 | try expect(t == Expr.Literal); | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | test "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 | 347 | }; |
| 348 | 348 | |
| 349 | 349 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 350 | comptime expect(Tag(ExprTag) == comptime_int); | |
| 350 | comptime try expect(Tag(ExprTag) == comptime_int); | |
| 351 | 351 | var t = @as(ExprTag, e); |
| 352 | expect(t == Expr.Literal); | |
| 353 | expect(@enumToInt(t) == 33); | |
| 354 | comptime expect(@enumToInt(t) == 33); | |
| 352 | try expect(t == Expr.Literal); | |
| 353 | try expect(@enumToInt(t) == 33); | |
| 354 | comptime try expect(@enumToInt(t) == 33); | |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | test "@enumToInt works on unions" { |
| ... | ... | @@ -364,9 +364,9 @@ test "@enumToInt works on unions" { |
| 364 | 364 | const a = Bar{ .A = true }; |
| 365 | 365 | var b = Bar{ .B = undefined }; |
| 366 | 366 | var c = Bar.C; |
| 367 | expect(@enumToInt(a) == 0); | |
| 368 | expect(@enumToInt(b) == 1); | |
| 369 | expect(@enumToInt(c) == 2); | |
| 367 | try expect(@enumToInt(a) == 0); | |
| 368 | try expect(@enumToInt(b) == 1); | |
| 369 | try expect(@enumToInt(c) == 2); | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | const Attribute = union(enum) { |
| ... | ... | @@ -393,23 +393,23 @@ test "comptime union field value equality" { |
| 393 | 393 | const b1 = Setter(Attribute{ .B = 9 }); |
| 394 | 394 | const b2 = Setter(Attribute{ .B = 5 }); |
| 395 | 395 | |
| 396 | expect(a0 == a0); | |
| 397 | expect(a1 == a1); | |
| 398 | expect(a0 == a2); | |
| 396 | try expect(a0 == a0); | |
| 397 | try expect(a1 == a1); | |
| 398 | try expect(a0 == a2); | |
| 399 | 399 | |
| 400 | expect(b0 == b0); | |
| 401 | expect(b1 == b1); | |
| 402 | expect(b0 == b2); | |
| 400 | try expect(b0 == b0); | |
| 401 | try expect(b1 == b1); | |
| 402 | try expect(b0 == b2); | |
| 403 | 403 | |
| 404 | expect(a0 != b0); | |
| 405 | expect(a0 != a1); | |
| 406 | expect(b0 != b1); | |
| 404 | try expect(a0 != b0); | |
| 405 | try expect(a0 != a1); | |
| 406 | try expect(b0 != b1); | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | test "return union init with void payload" { |
| 410 | 410 | const S = struct { |
| 411 | fn entry() void { | |
| 412 | expect(func().state == State.one); | |
| 411 | fn entry() !void { | |
| 412 | try expect(func().state == State.one); | |
| 413 | 413 | } |
| 414 | 414 | const Outer = union(enum) { |
| 415 | 415 | state: State, |
| ... | ... | @@ -422,8 +422,8 @@ test "return union init with void payload" { |
| 422 | 422 | return Outer{ .state = State{ .one = {} } }; |
| 423 | 423 | } |
| 424 | 424 | }; |
| 425 | S.entry(); | |
| 426 | comptime S.entry(); | |
| 425 | try S.entry(); | |
| 426 | comptime try S.entry(); | |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | test "@unionInit can modify a union type" { |
| ... | ... | @@ -435,14 +435,14 @@ test "@unionInit can modify a union type" { |
| 435 | 435 | var value: UnionInitEnum = undefined; |
| 436 | 436 | |
| 437 | 437 | value = @unionInit(UnionInitEnum, "Boolean", true); |
| 438 | expect(value.Boolean == true); | |
| 438 | try expect(value.Boolean == true); | |
| 439 | 439 | value.Boolean = false; |
| 440 | expect(value.Boolean == false); | |
| 440 | try expect(value.Boolean == false); | |
| 441 | 441 | |
| 442 | 442 | value = @unionInit(UnionInitEnum, "Byte", 2); |
| 443 | expect(value.Byte == 2); | |
| 443 | try expect(value.Byte == 2); | |
| 444 | 444 | value.Byte = 3; |
| 445 | expect(value.Byte == 3); | |
| 445 | try expect(value.Byte == 3); | |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | test "@unionInit can modify a pointer value" { |
| ... | ... | @@ -455,10 +455,10 @@ test "@unionInit can modify a pointer value" { |
| 455 | 455 | var value_ptr = &value; |
| 456 | 456 | |
| 457 | 457 | value_ptr.* = @unionInit(UnionInitEnum, "Boolean", true); |
| 458 | expect(value.Boolean == true); | |
| 458 | try expect(value.Boolean == true); | |
| 459 | 459 | |
| 460 | 460 | value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2); |
| 461 | expect(value.Byte == 2); | |
| 461 | try expect(value.Byte == 2); | |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | test "union no tag with struct member" { |
| ... | ... | @@ -471,38 +471,38 @@ test "union no tag with struct member" { |
| 471 | 471 | u.foo(); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | fn testComparison() void { | |
| 474 | fn testComparison() !void { | |
| 475 | 475 | var x = Payload{ .A = 42 }; |
| 476 | expect(x == .A); | |
| 477 | expect(x != .B); | |
| 478 | expect(x != .C); | |
| 479 | expect((x == .B) == false); | |
| 480 | expect((x == .C) == false); | |
| 481 | expect((x != .A) == false); | |
| 476 | try expect(x == .A); | |
| 477 | try expect(x != .B); | |
| 478 | try expect(x != .C); | |
| 479 | try expect((x == .B) == false); | |
| 480 | try expect((x == .C) == false); | |
| 481 | try expect((x != .A) == false); | |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | test "comparison between union and enum literal" { |
| 485 | testComparison(); | |
| 486 | comptime testComparison(); | |
| 485 | try testComparison(); | |
| 486 | comptime try testComparison(); | |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | test "packed union generates correctly aligned LLVM type" { |
| 490 | 490 | const U = packed union { |
| 491 | f1: fn () void, | |
| 491 | f1: fn () error{TestUnexpectedResult}!void, | |
| 492 | 492 | f2: u32, |
| 493 | 493 | }; |
| 494 | 494 | var foo = [_]U{ |
| 495 | 495 | U{ .f1 = doTest }, |
| 496 | 496 | U{ .f2 = 0 }, |
| 497 | 497 | }; |
| 498 | foo[0].f1(); | |
| 498 | try foo[0].f1(); | |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | test "union with one member defaults to u0 tag type" { |
| 502 | 502 | const U0 = union(enum) { |
| 503 | 503 | X: u32, |
| 504 | 504 | }; |
| 505 | comptime expect(Tag(Tag(U0)) == u0); | |
| 505 | comptime try expect(Tag(Tag(U0)) == u0); | |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | test "union with comptime_int tag" { |
| ... | ... | @@ -511,7 +511,7 @@ test "union with comptime_int tag" { |
| 511 | 511 | Y: u16, |
| 512 | 512 | Z: u8, |
| 513 | 513 | }; |
| 514 | comptime expect(Tag(Tag(Union)) == comptime_int); | |
| 514 | comptime try expect(Tag(Tag(Union)) == comptime_int); | |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | 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 | }; |
| 522 | 522 | |
| 523 | 523 | const x = U{ .x = 0x55AAAA55 }; |
| 524 | comptime expect(x.y == 0x55); | |
| 524 | comptime try expect(x.y == 0x55); | |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | const Foo1 = union(enum) { |
| ... | ... | @@ -535,7 +535,7 @@ test "global union with single field is correctly initialized" { |
| 535 | 535 | glbl = Foo1{ |
| 536 | 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 | } |
| 540 | 540 | |
| 541 | 541 | pub const FooUnion = union(enum) { |
| ... | ... | @@ -548,8 +548,8 @@ var glbl_array: [2]FooUnion = undefined; |
| 548 | 548 | test "initialize global array of union" { |
| 549 | 549 | glbl_array[1] = FooUnion{ .U1 = 2 }; |
| 550 | 550 | glbl_array[0] = FooUnion{ .U0 = 1 }; |
| 551 | expect(glbl_array[0].U0 == 1); | |
| 552 | expect(glbl_array[1].U1 == 2); | |
| 551 | try expect(glbl_array[0].U0 == 1); | |
| 552 | try expect(glbl_array[1].U1 == 2); | |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | test "anonymous union literal syntax" { |
| ... | ... | @@ -559,19 +559,19 @@ test "anonymous union literal syntax" { |
| 559 | 559 | float: f64, |
| 560 | 560 | }; |
| 561 | 561 | |
| 562 | fn doTheTest() void { | |
| 562 | fn doTheTest() !void { | |
| 563 | 563 | var i: Number = .{ .int = 42 }; |
| 564 | 564 | var f = makeNumber(); |
| 565 | expect(i.int == 42); | |
| 566 | expect(f.float == 12.34); | |
| 565 | try expect(i.int == 42); | |
| 566 | try expect(f.float == 12.34); | |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | fn makeNumber() Number { |
| 570 | 570 | return .{ .float = 12.34 }; |
| 571 | 571 | } |
| 572 | 572 | }; |
| 573 | S.doTheTest(); | |
| 574 | comptime S.doTheTest(); | |
| 573 | try S.doTheTest(); | |
| 574 | comptime try S.doTheTest(); | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | test "update the tag value for zero-sized unions" { |
| ... | ... | @@ -580,9 +580,9 @@ test "update the tag value for zero-sized unions" { |
| 580 | 580 | U1: void, |
| 581 | 581 | }; |
| 582 | 582 | var x = S{ .U0 = {} }; |
| 583 | expect(x == .U0); | |
| 583 | try expect(x == .U0); | |
| 584 | 584 | x = S{ .U1 = {} }; |
| 585 | expect(x == .U1); | |
| 585 | try expect(x == .U1); | |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | 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" { |
| 594 | 594 | |
| 595 | 595 | const ArchTag = Tag(Arch); |
| 596 | 596 | |
| 597 | fn doTheTest() void { | |
| 597 | fn doTheTest() !void { | |
| 598 | 598 | var x: ArchTag = getArch1(); |
| 599 | expect(x == .One); | |
| 599 | try expect(x == .One); | |
| 600 | 600 | |
| 601 | 601 | var y: ArchTag = getArch2(); |
| 602 | expect(y == .Two); | |
| 602 | try expect(y == .Two); | |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | pub fn getArch1() Arch { |
| ... | ... | @@ -610,8 +610,8 @@ test "function call result coerces from tagged union to the tag" { |
| 610 | 610 | return .{ .Two = 99 }; |
| 611 | 611 | } |
| 612 | 612 | }; |
| 613 | S.doTheTest(); | |
| 614 | comptime S.doTheTest(); | |
| 613 | try S.doTheTest(); | |
| 614 | comptime try S.doTheTest(); | |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | test "0-sized extern union definition" { |
| ... | ... | @@ -620,7 +620,7 @@ test "0-sized extern union definition" { |
| 620 | 620 | const f = 1; |
| 621 | 621 | }; |
| 622 | 622 | |
| 623 | expect(U.f == 1); | |
| 623 | try expect(U.f == 1); | |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | test "union initializer generates padding only if needed" { |
| ... | ... | @@ -629,7 +629,7 @@ test "union initializer generates padding only if needed" { |
| 629 | 629 | }; |
| 630 | 630 | |
| 631 | 631 | var v = U{ .A = 532 }; |
| 632 | expect(v.A == 532); | |
| 632 | try expect(v.A == 532); | |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | test "runtime tag name with single field" { |
| ... | ... | @@ -638,7 +638,7 @@ test "runtime tag name with single field" { |
| 638 | 638 | }; |
| 639 | 639 | |
| 640 | 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 | } |
| 643 | 643 | |
| 644 | 644 | test "cast from anonymous struct to union" { |
| ... | ... | @@ -648,7 +648,7 @@ test "cast from anonymous struct to union" { |
| 648 | 648 | B: []const u8, |
| 649 | 649 | C: void, |
| 650 | 650 | }; |
| 651 | fn doTheTest() void { | |
| 651 | fn doTheTest() !void { | |
| 652 | 652 | var y: u32 = 42; |
| 653 | 653 | const t0 = .{ .A = 123 }; |
| 654 | 654 | const t1 = .{ .B = "foo" }; |
| ... | ... | @@ -658,14 +658,14 @@ test "cast from anonymous struct to union" { |
| 658 | 658 | var x1: U = t1; |
| 659 | 659 | const x2: U = t2; |
| 660 | 660 | var x3: U = t3; |
| 661 | expect(x0.A == 123); | |
| 662 | expect(std.mem.eql(u8, x1.B, "foo")); | |
| 663 | expect(x2 == .C); | |
| 664 | expect(x3.A == y); | |
| 661 | try expect(x0.A == 123); | |
| 662 | try expect(std.mem.eql(u8, x1.B, "foo")); | |
| 663 | try expect(x2 == .C); | |
| 664 | try expect(x3.A == y); | |
| 665 | 665 | } |
| 666 | 666 | }; |
| 667 | S.doTheTest(); | |
| 668 | comptime S.doTheTest(); | |
| 667 | try S.doTheTest(); | |
| 668 | comptime try S.doTheTest(); | |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | 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 | 675 | B: []const u8, |
| 676 | 676 | C: void, |
| 677 | 677 | }; |
| 678 | fn doTheTest() void { | |
| 678 | fn doTheTest() !void { | |
| 679 | 679 | var y: u32 = 42; |
| 680 | 680 | const t0 = &.{ .A = 123 }; |
| 681 | 681 | const t1 = &.{ .B = "foo" }; |
| ... | ... | @@ -685,14 +685,14 @@ test "cast from pointer to anonymous struct to pointer to union" { |
| 685 | 685 | var x1: *const U = t1; |
| 686 | 686 | const x2: *const U = t2; |
| 687 | 687 | var x3: *const U = t3; |
| 688 | expect(x0.A == 123); | |
| 689 | expect(std.mem.eql(u8, x1.B, "foo")); | |
| 690 | expect(x2.* == .C); | |
| 691 | expect(x3.A == y); | |
| 688 | try expect(x0.A == 123); | |
| 689 | try expect(std.mem.eql(u8, x1.B, "foo")); | |
| 690 | try expect(x2.* == .C); | |
| 691 | try expect(x3.A == y); | |
| 692 | 692 | } |
| 693 | 693 | }; |
| 694 | S.doTheTest(); | |
| 695 | comptime S.doTheTest(); | |
| 694 | try S.doTheTest(); | |
| 695 | comptime try S.doTheTest(); | |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | test "method call on an empty union" { |
| ... | ... | @@ -707,13 +707,13 @@ test "method call on an empty union" { |
| 707 | 707 | } |
| 708 | 708 | }; |
| 709 | 709 | |
| 710 | fn doTheTest() void { | |
| 710 | fn doTheTest() !void { | |
| 711 | 711 | var u = MyUnion{ .X1 = [0]u8{} }; |
| 712 | expect(u.useIt()); | |
| 712 | try expect(u.useIt()); | |
| 713 | 713 | } |
| 714 | 714 | }; |
| 715 | S.doTheTest(); | |
| 716 | comptime S.doTheTest(); | |
| 715 | try S.doTheTest(); | |
| 716 | comptime try S.doTheTest(); | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | test "switching on non exhaustive union" { |
| ... | ... | @@ -727,16 +727,16 @@ test "switching on non exhaustive union" { |
| 727 | 727 | a: i32, |
| 728 | 728 | b: u32, |
| 729 | 729 | }; |
| 730 | fn doTheTest() void { | |
| 730 | fn doTheTest() !void { | |
| 731 | 731 | var a = U{ .a = 2 }; |
| 732 | 732 | switch (a) { |
| 733 | .a => |val| expect(val == 2), | |
| 733 | .a => |val| try expect(val == 2), | |
| 734 | 734 | .b => unreachable, |
| 735 | 735 | } |
| 736 | 736 | } |
| 737 | 737 | }; |
| 738 | S.doTheTest(); | |
| 739 | comptime S.doTheTest(); | |
| 738 | try S.doTheTest(); | |
| 739 | comptime try S.doTheTest(); | |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | test "containers with single-field enums" { |
| ... | ... | @@ -746,21 +746,21 @@ test "containers with single-field enums" { |
| 746 | 746 | const C = struct { a: A }; |
| 747 | 747 | const D = struct { a: B }; |
| 748 | 748 | |
| 749 | fn doTheTest() void { | |
| 749 | fn doTheTest() !void { | |
| 750 | 750 | var array1 = [1]A{A{ .f1 = {} }}; |
| 751 | 751 | var array2 = [1]B{B{ .f1 = {} }}; |
| 752 | expect(array1[0] == .f1); | |
| 753 | expect(array2[0] == .f1); | |
| 752 | try expect(array1[0] == .f1); | |
| 753 | try expect(array2[0] == .f1); | |
| 754 | 754 | |
| 755 | 755 | var struct1 = C{ .a = A{ .f1 = {} } }; |
| 756 | 756 | var struct2 = D{ .a = B{ .f1 = {} } }; |
| 757 | expect(struct1.a == .f1); | |
| 758 | expect(struct2.a == .f1); | |
| 757 | try expect(struct1.a == .f1); | |
| 758 | try expect(struct2.a == .f1); | |
| 759 | 759 | } |
| 760 | 760 | }; |
| 761 | 761 | |
| 762 | S.doTheTest(); | |
| 763 | comptime S.doTheTest(); | |
| 762 | try S.doTheTest(); | |
| 763 | comptime try S.doTheTest(); | |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | test "@unionInit on union w/ tag but no fields" { |
| ... | ... | @@ -776,18 +776,18 @@ test "@unionInit on union w/ tag but no fields" { |
| 776 | 776 | }; |
| 777 | 777 | |
| 778 | 778 | comptime { |
| 779 | expect(@sizeOf(Data) != 0); | |
| 779 | try expect(@sizeOf(Data) != 0); | |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | fn doTheTest() void { | |
| 782 | fn doTheTest() !void { | |
| 783 | 783 | var data: Data = .{ .no_op = .{} }; |
| 784 | 784 | var o = Data.decode(&[_]u8{}); |
| 785 | expectEqual(Type.no_op, o); | |
| 785 | try expectEqual(Type.no_op, o); | |
| 786 | 786 | } |
| 787 | 787 | }; |
| 788 | 788 | |
| 789 | S.doTheTest(); | |
| 790 | comptime S.doTheTest(); | |
| 789 | try S.doTheTest(); | |
| 790 | comptime try S.doTheTest(); | |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | test "union enum type gets a separate scope" { |
| ... | ... | @@ -797,10 +797,10 @@ test "union enum type gets a separate scope" { |
| 797 | 797 | const foo = 1; |
| 798 | 798 | }; |
| 799 | 799 | |
| 800 | fn doTheTest() void { | |
| 801 | expect(!@hasDecl(Tag(U), "foo")); | |
| 800 | fn doTheTest() !void { | |
| 801 | try expect(!@hasDecl(Tag(U), "foo")); | |
| 802 | 802 | } |
| 803 | 803 | }; |
| 804 | 804 | |
| 805 | S.doTheTest(); | |
| 805 | try S.doTheTest(); | |
| 806 | 806 | } |
test/stage1/behavior/usingnamespace.zig+3-3| ... | ... | @@ -9,8 +9,8 @@ fn Foo(comptime T: type) type { |
| 9 | 9 | test "usingnamespace inside a generic struct" { |
| 10 | 10 | const std2 = Foo(std); |
| 11 | 11 | const testing2 = Foo(std.testing); |
| 12 | std2.testing.expect(true); | |
| 13 | testing2.expect(true); | |
| 12 | try std2.testing.expect(true); | |
| 13 | try testing2.expect(true); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | usingnamespace struct { |
| ... | ... | @@ -18,5 +18,5 @@ usingnamespace struct { |
| 18 | 18 | }; |
| 19 | 19 | |
| 20 | 20 | test "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/stage1/behavior/var_args.zig+17-17| ... | ... | @@ -12,9 +12,9 @@ fn add(args: anytype) i32 { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | test "add arbitrary args" { |
| 15 | expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); | |
| 16 | expect(add(.{@as(i32, 1234)}) == 1234); | |
| 17 | expect(add(.{}) == 0); | |
| 15 | try expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); | |
| 16 | try expect(add(.{@as(i32, 1234)}) == 1234); | |
| 17 | try expect(add(.{}) == 0); | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | fn readFirstVarArg(args: anytype) void { |
| ... | ... | @@ -26,9 +26,9 @@ test "send void arg to var args" { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | test "pass args directly" { |
| 29 | expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); | |
| 30 | expect(addSomeStuff(.{@as(i32, 1234)}) == 1234); | |
| 31 | expect(addSomeStuff(.{}) == 0); | |
| 29 | try expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); | |
| 30 | try expect(addSomeStuff(.{@as(i32, 1234)}) == 1234); | |
| 31 | try expect(addSomeStuff(.{}) == 0); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | fn addSomeStuff(args: anytype) i32 { |
| ... | ... | @@ -36,23 +36,23 @@ fn addSomeStuff(args: anytype) i32 { |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "runtime parameter before var args" { |
| 39 | expect(extraFn(10, .{}) == 0); | |
| 40 | expect(extraFn(10, .{false}) == 1); | |
| 41 | expect(extraFn(10, .{ false, true }) == 2); | |
| 39 | try expect((try extraFn(10, .{})) == 0); | |
| 40 | try expect((try extraFn(10, .{false})) == 1); | |
| 41 | try expect((try extraFn(10, .{ false, true })) == 2); | |
| 42 | 42 | |
| 43 | 43 | comptime { |
| 44 | expect(extraFn(10, .{}) == 0); | |
| 45 | expect(extraFn(10, .{false}) == 1); | |
| 46 | expect(extraFn(10, .{ false, true }) == 2); | |
| 44 | try expect((try extraFn(10, .{})) == 0); | |
| 45 | try expect((try extraFn(10, .{false})) == 1); | |
| 46 | try expect((try extraFn(10, .{ false, true })) == 2); | |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | fn extraFn(extra: u32, args: anytype) usize { | |
| 50 | fn extraFn(extra: u32, args: anytype) !usize { | |
| 51 | 51 | if (args.len >= 1) { |
| 52 | expect(args[0] == false); | |
| 52 | try expect(args[0] == false); | |
| 53 | 53 | } |
| 54 | 54 | if (args.len >= 2) { |
| 55 | expect(args[1] == true); | |
| 55 | try expect(args[1] == true); | |
| 56 | 56 | } |
| 57 | 57 | return args.len; |
| 58 | 58 | } |
| ... | ... | @@ -70,8 +70,8 @@ fn foo2(args: anytype) bool { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | test "array of var args functions" { |
| 73 | expect(foos[0](.{})); | |
| 74 | expect(!foos[1](.{})); | |
| 73 | try expect(foos[0](.{})); | |
| 74 | try expect(!foos[1](.{})); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | test "pass zero length array to var args param" { |
test/stage1/behavior/vector.zig+280-280| ... | ... | @@ -9,104 +9,104 @@ const Vector = std.meta.Vector; |
| 9 | 9 | |
| 10 | 10 | test "implicit cast vector to array - bool" { |
| 11 | 11 | const S = struct { |
| 12 | fn doTheTest() void { | |
| 12 | fn doTheTest() !void { | |
| 13 | 13 | const a: Vector(4, bool) = [_]bool{ true, false, true, false }; |
| 14 | 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(); | |
| 19 | comptime S.doTheTest(); | |
| 18 | try S.doTheTest(); | |
| 19 | comptime try S.doTheTest(); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | test "vector wrap operators" { |
| 23 | 23 | const S = struct { |
| 24 | fn doTheTest() void { | |
| 24 | fn doTheTest() !void { | |
| 25 | 25 | var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 26 | 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 })); | |
| 28 | expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 })); | |
| 29 | expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); | |
| 27 | try expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 })); | |
| 28 | try expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 })); | |
| 29 | try expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); | |
| 30 | 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(); | |
| 35 | comptime S.doTheTest(); | |
| 34 | try S.doTheTest(); | |
| 35 | comptime try S.doTheTest(); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | test "vector bin compares with mem.eql" { |
| 39 | 39 | const S = struct { |
| 40 | fn doTheTest() void { | |
| 40 | fn doTheTest() !void { | |
| 41 | 41 | var v: Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; |
| 42 | 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 })); | |
| 44 | expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); | |
| 45 | expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); | |
| 46 | expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true })); | |
| 47 | expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false })); | |
| 48 | expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true })); | |
| 43 | try expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); | |
| 44 | try expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); | |
| 45 | try expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); | |
| 46 | try expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true })); | |
| 47 | try expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false })); | |
| 48 | try expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true })); | |
| 49 | 49 | } |
| 50 | 50 | }; |
| 51 | S.doTheTest(); | |
| 52 | comptime S.doTheTest(); | |
| 51 | try S.doTheTest(); | |
| 52 | comptime try S.doTheTest(); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | test "vector int operators" { |
| 56 | 56 | const S = struct { |
| 57 | fn doTheTest() void { | |
| 57 | fn doTheTest() !void { | |
| 58 | 58 | var v: Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; |
| 59 | 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 })); | |
| 61 | expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); | |
| 62 | expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); | |
| 63 | expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 })); | |
| 60 | try expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); | |
| 61 | try expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); | |
| 62 | try expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); | |
| 63 | try expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 })); | |
| 64 | 64 | } |
| 65 | 65 | }; |
| 66 | S.doTheTest(); | |
| 67 | comptime S.doTheTest(); | |
| 66 | try S.doTheTest(); | |
| 67 | comptime try S.doTheTest(); | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | test "vector float operators" { |
| 71 | 71 | const S = struct { |
| 72 | fn doTheTest() void { | |
| 72 | fn doTheTest() !void { | |
| 73 | 73 | var v: Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; |
| 74 | 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 })); | |
| 76 | expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 })); | |
| 77 | expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 })); | |
| 78 | expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 })); | |
| 75 | try expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 })); | |
| 76 | try expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 })); | |
| 77 | try expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 })); | |
| 78 | try expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 })); | |
| 79 | 79 | } |
| 80 | 80 | }; |
| 81 | S.doTheTest(); | |
| 82 | comptime S.doTheTest(); | |
| 81 | try S.doTheTest(); | |
| 82 | comptime try S.doTheTest(); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | test "vector bit operators" { |
| 86 | 86 | const S = struct { |
| 87 | fn doTheTest() void { | |
| 87 | fn doTheTest() !void { | |
| 88 | 88 | var v: Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; |
| 89 | 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 })); | |
| 91 | expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); | |
| 92 | expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); | |
| 90 | try expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); | |
| 91 | try expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); | |
| 92 | try expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); | |
| 93 | 93 | } |
| 94 | 94 | }; |
| 95 | S.doTheTest(); | |
| 96 | comptime S.doTheTest(); | |
| 95 | try S.doTheTest(); | |
| 96 | comptime try S.doTheTest(); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | test "implicit cast vector to array" { |
| 100 | 100 | const S = struct { |
| 101 | fn doTheTest() void { | |
| 101 | fn doTheTest() !void { | |
| 102 | 102 | var a: Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; |
| 103 | 103 | var result_array: [4]i32 = a; |
| 104 | 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(); | |
| 109 | comptime S.doTheTest(); | |
| 108 | try S.doTheTest(); | |
| 109 | comptime try S.doTheTest(); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | test "array to vector" { |
| ... | ... | @@ -120,141 +120,141 @@ test "vector casts of sizes not divisable by 8" { |
| 120 | 120 | if (std.Target.current.os.tag == .dragonfly) return error.SkipZigTest; |
| 121 | 121 | |
| 122 | 122 | const S = struct { |
| 123 | fn doTheTest() void { | |
| 123 | fn doTheTest() !void { | |
| 124 | 124 | { |
| 125 | 125 | var v: Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; |
| 126 | 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 | 130 | var v: Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; |
| 131 | 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 | 135 | var v: Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; |
| 136 | 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 | 140 | var v: Vector(4, bool) = [4]bool{ false, false, true, false }; |
| 141 | 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(); | |
| 147 | comptime S.doTheTest(); | |
| 146 | try S.doTheTest(); | |
| 147 | comptime try S.doTheTest(); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | test "vector @splat" { |
| 151 | 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 | 153 | const T = @TypeOf(v); |
| 154 | 154 | var vec = @splat(N, v); |
| 155 | expectEqual(Vector(N, T), @TypeOf(vec)); | |
| 155 | try expectEqual(Vector(N, T), @TypeOf(vec)); | |
| 156 | 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 | 160 | // Splats with multiple-of-8 bit types that fill a 128bit vector. |
| 161 | testForT(16, @as(u8, 0xEE)); | |
| 162 | testForT(8, @as(u16, 0xBEEF)); | |
| 163 | testForT(4, @as(u32, 0xDEADBEEF)); | |
| 164 | testForT(2, @as(u64, 0xCAFEF00DDEADBEEF)); | |
| 161 | try testForT(16, @as(u8, 0xEE)); | |
| 162 | try testForT(8, @as(u16, 0xBEEF)); | |
| 163 | try testForT(4, @as(u32, 0xDEADBEEF)); | |
| 164 | try testForT(2, @as(u64, 0xCAFEF00DDEADBEEF)); | |
| 165 | 165 | |
| 166 | testForT(8, @as(f16, 3.1415)); | |
| 167 | testForT(4, @as(f32, 3.1415)); | |
| 168 | testForT(2, @as(f64, 3.1415)); | |
| 166 | try testForT(8, @as(f16, 3.1415)); | |
| 167 | try testForT(4, @as(f32, 3.1415)); | |
| 168 | try testForT(2, @as(f64, 3.1415)); | |
| 169 | 169 | |
| 170 | 170 | // Same but fill more than 128 bits. |
| 171 | testForT(16 * 2, @as(u8, 0xEE)); | |
| 172 | testForT(8 * 2, @as(u16, 0xBEEF)); | |
| 173 | testForT(4 * 2, @as(u32, 0xDEADBEEF)); | |
| 174 | testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF)); | |
| 175 | ||
| 176 | testForT(8 * 2, @as(f16, 3.1415)); | |
| 177 | testForT(4 * 2, @as(f32, 3.1415)); | |
| 178 | testForT(2 * 2, @as(f64, 3.1415)); | |
| 171 | try testForT(16 * 2, @as(u8, 0xEE)); | |
| 172 | try testForT(8 * 2, @as(u16, 0xBEEF)); | |
| 173 | try testForT(4 * 2, @as(u32, 0xDEADBEEF)); | |
| 174 | try testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF)); | |
| 175 | ||
| 176 | try testForT(8 * 2, @as(f16, 3.1415)); | |
| 177 | try testForT(4 * 2, @as(f32, 3.1415)); | |
| 178 | try testForT(2 * 2, @as(f64, 3.1415)); | |
| 179 | 179 | } |
| 180 | 180 | }; |
| 181 | S.doTheTest(); | |
| 182 | comptime S.doTheTest(); | |
| 181 | try S.doTheTest(); | |
| 182 | comptime try S.doTheTest(); | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | test "load vector elements via comptime index" { |
| 186 | 186 | const S = struct { |
| 187 | fn doTheTest() void { | |
| 187 | fn doTheTest() !void { | |
| 188 | 188 | var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; |
| 189 | expect(v[0] == 1); | |
| 190 | expect(v[1] == 2); | |
| 191 | expect(loadv(&v[2]) == 3); | |
| 189 | try expect(v[0] == 1); | |
| 190 | try expect(v[1] == 2); | |
| 191 | try expect(loadv(&v[2]) == 3); | |
| 192 | 192 | } |
| 193 | 193 | fn loadv(ptr: anytype) i32 { |
| 194 | 194 | return ptr.*; |
| 195 | 195 | } |
| 196 | 196 | }; |
| 197 | 197 | |
| 198 | S.doTheTest(); | |
| 199 | comptime S.doTheTest(); | |
| 198 | try S.doTheTest(); | |
| 199 | comptime try S.doTheTest(); | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | test "store vector elements via comptime index" { |
| 203 | 203 | const S = struct { |
| 204 | fn doTheTest() void { | |
| 204 | fn doTheTest() !void { | |
| 205 | 205 | var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 206 | 206 | |
| 207 | 207 | v[2] = 42; |
| 208 | expect(v[1] == 5); | |
| 208 | try expect(v[1] == 5); | |
| 209 | 209 | v[3] = -364; |
| 210 | expect(v[2] == 42); | |
| 211 | expect(-364 == v[3]); | |
| 210 | try expect(v[2] == 42); | |
| 211 | try expect(-364 == v[3]); | |
| 212 | 212 | |
| 213 | 213 | storev(&v[0], 100); |
| 214 | expect(v[0] == 100); | |
| 214 | try expect(v[0] == 100); | |
| 215 | 215 | } |
| 216 | 216 | fn storev(ptr: anytype, x: i32) void { |
| 217 | 217 | ptr.* = x; |
| 218 | 218 | } |
| 219 | 219 | }; |
| 220 | 220 | |
| 221 | S.doTheTest(); | |
| 222 | comptime S.doTheTest(); | |
| 221 | try S.doTheTest(); | |
| 222 | comptime try S.doTheTest(); | |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | test "load vector elements via runtime index" { |
| 226 | 226 | const S = struct { |
| 227 | fn doTheTest() void { | |
| 227 | fn doTheTest() !void { | |
| 228 | 228 | var v: Vector(4, i32) = [_]i32{ 1, 2, 3, undefined }; |
| 229 | 229 | var i: u32 = 0; |
| 230 | expect(v[i] == 1); | |
| 230 | try expect(v[i] == 1); | |
| 231 | 231 | i += 1; |
| 232 | expect(v[i] == 2); | |
| 232 | try expect(v[i] == 2); | |
| 233 | 233 | i += 1; |
| 234 | expect(v[i] == 3); | |
| 234 | try expect(v[i] == 3); | |
| 235 | 235 | } |
| 236 | 236 | }; |
| 237 | 237 | |
| 238 | S.doTheTest(); | |
| 239 | comptime S.doTheTest(); | |
| 238 | try S.doTheTest(); | |
| 239 | comptime try S.doTheTest(); | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | test "store vector elements via runtime index" { |
| 243 | 243 | const S = struct { |
| 244 | fn doTheTest() void { | |
| 244 | fn doTheTest() !void { | |
| 245 | 245 | var v: Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; |
| 246 | 246 | var i: u32 = 2; |
| 247 | 247 | v[i] = 1; |
| 248 | expect(v[1] == 5); | |
| 249 | expect(v[2] == 1); | |
| 248 | try expect(v[1] == 5); | |
| 249 | try expect(v[2] == 1); | |
| 250 | 250 | i += 1; |
| 251 | 251 | v[i] = -364; |
| 252 | expect(-364 == v[3]); | |
| 252 | try expect(-364 == v[3]); | |
| 253 | 253 | } |
| 254 | 254 | }; |
| 255 | 255 | |
| 256 | S.doTheTest(); | |
| 257 | comptime S.doTheTest(); | |
| 256 | try S.doTheTest(); | |
| 257 | comptime try S.doTheTest(); | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | test "initialize vector which is a struct field" { |
| ... | ... | @@ -263,155 +263,155 @@ test "initialize vector which is a struct field" { |
| 263 | 263 | }; |
| 264 | 264 | |
| 265 | 265 | const S = struct { |
| 266 | fn doTheTest() void { | |
| 266 | fn doTheTest() !void { | |
| 267 | 267 | var foo = Vec4Obj{ |
| 268 | 268 | .data = [_]f32{ 1, 2, 3, 4 }, |
| 269 | 269 | }; |
| 270 | 270 | } |
| 271 | 271 | }; |
| 272 | S.doTheTest(); | |
| 273 | comptime S.doTheTest(); | |
| 272 | try S.doTheTest(); | |
| 273 | comptime try S.doTheTest(); | |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | test "vector comparison operators" { |
| 277 | 277 | const S = struct { |
| 278 | fn doTheTest() void { | |
| 278 | fn doTheTest() !void { | |
| 279 | 279 | { |
| 280 | 280 | const v1: Vector(4, bool) = [_]bool{ true, false, true, false }; |
| 281 | 281 | const v2: Vector(4, bool) = [_]bool{ false, true, false, true }; |
| 282 | expectEqual(@splat(4, true), v1 == v1); | |
| 283 | expectEqual(@splat(4, false), v1 == v2); | |
| 284 | expectEqual(@splat(4, true), v1 != v2); | |
| 285 | expectEqual(@splat(4, false), v2 != v2); | |
| 282 | try expectEqual(@splat(4, true), v1 == v1); | |
| 283 | try expectEqual(@splat(4, false), v1 == v2); | |
| 284 | try expectEqual(@splat(4, true), v1 != v2); | |
| 285 | try expectEqual(@splat(4, false), v2 != v2); | |
| 286 | 286 | } |
| 287 | 287 | { |
| 288 | 288 | const v1 = @splat(4, @as(u32, 0xc0ffeeee)); |
| 289 | 289 | const v2: Vector(4, c_uint) = v1; |
| 290 | 290 | const v3 = @splat(4, @as(u32, 0xdeadbeef)); |
| 291 | expectEqual(@splat(4, true), v1 == v2); | |
| 292 | expectEqual(@splat(4, false), v1 == v3); | |
| 293 | expectEqual(@splat(4, true), v1 != v3); | |
| 294 | expectEqual(@splat(4, false), v1 != v2); | |
| 291 | try expectEqual(@splat(4, true), v1 == v2); | |
| 292 | try expectEqual(@splat(4, false), v1 == v3); | |
| 293 | try expectEqual(@splat(4, true), v1 != v3); | |
| 294 | try expectEqual(@splat(4, false), v1 != v2); | |
| 295 | 295 | } |
| 296 | 296 | { |
| 297 | 297 | // Comptime-known LHS/RHS |
| 298 | 298 | var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 }; |
| 299 | 299 | const v2 = @splat(4, @as(u32, 2)); |
| 300 | 300 | const v3: @Vector(4, bool) = [_]bool{ true, false, true, false }; |
| 301 | expectEqual(v3, v1 == v2); | |
| 302 | expectEqual(v3, v2 == v1); | |
| 301 | try expectEqual(v3, v1 == v2); | |
| 302 | try expectEqual(v3, v2 == v1); | |
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | }; |
| 306 | S.doTheTest(); | |
| 307 | comptime S.doTheTest(); | |
| 306 | try S.doTheTest(); | |
| 307 | comptime try S.doTheTest(); | |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | test "vector division operators" { |
| 311 | 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 | 313 | if (!comptime std.meta.trait.isSignedInt(T)) { |
| 314 | 314 | const d0 = x / y; |
| 315 | 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 | 319 | const d1 = @divExact(x, y); |
| 320 | 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 | 323 | const d2 = @divFloor(x, y); |
| 324 | 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 | 327 | const d3 = @divTrunc(x, y); |
| 328 | 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 | } |
| 332 | 332 | |
| 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 | 334 | if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) { |
| 335 | 335 | const r0 = x % y; |
| 336 | 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 | 340 | const r1 = @mod(x, y); |
| 341 | 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 | 344 | const r2 = @rem(x, y); |
| 345 | 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 | } |
| 349 | 349 | |
| 350 | fn doTheTest() void { | |
| 350 | fn doTheTest() !void { | |
| 351 | 351 | // https://github.com/ziglang/zig/issues/4952 |
| 352 | 352 | if (std.builtin.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 | } |
| 355 | 355 | |
| 356 | doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 }); | |
| 357 | doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 }); | |
| 356 | try doTheTestDiv(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, -1.0, -2.0 }); | |
| 357 | try doTheTestDiv(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, -1.0, -2.0 }); | |
| 358 | 358 | |
| 359 | 359 | // https://github.com/ziglang/zig/issues/4952 |
| 360 | 360 | if (std.builtin.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 }); | |
| 364 | doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 }); | |
| 365 | ||
| 366 | doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 }); | |
| 367 | doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 }); | |
| 368 | doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 }); | |
| 369 | doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 }); | |
| 370 | ||
| 371 | doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 }); | |
| 372 | doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 }); | |
| 373 | doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 }); | |
| 374 | doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 }); | |
| 375 | ||
| 376 | doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 }); | |
| 377 | doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 }); | |
| 378 | doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 }); | |
| 379 | doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 }); | |
| 380 | ||
| 381 | doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 }); | |
| 382 | doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 }); | |
| 383 | doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 }); | |
| 384 | doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 }); | |
| 363 | try doTheTestMod(f32, [4]f32{ 4.0, -4.0, 4.0, -4.0 }, [4]f32{ 1.0, 2.0, 0.5, 3.0 }); | |
| 364 | try doTheTestMod(f64, [4]f64{ 4.0, -4.0, 4.0, -4.0 }, [4]f64{ 1.0, 2.0, 0.5, 3.0 }); | |
| 365 | ||
| 366 | try doTheTestDiv(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, -1, -2 }); | |
| 367 | try doTheTestDiv(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, -1, -2 }); | |
| 368 | try doTheTestDiv(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, -1, -2 }); | |
| 369 | try doTheTestDiv(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, -1, -2 }); | |
| 370 | ||
| 371 | try doTheTestMod(i8, [4]i8{ 4, -4, 4, -4 }, [4]i8{ 1, 2, 4, 8 }); | |
| 372 | try doTheTestMod(i16, [4]i16{ 4, -4, 4, -4 }, [4]i16{ 1, 2, 4, 8 }); | |
| 373 | try doTheTestMod(i32, [4]i32{ 4, -4, 4, -4 }, [4]i32{ 1, 2, 4, 8 }); | |
| 374 | try doTheTestMod(i64, [4]i64{ 4, -4, 4, -4 }, [4]i64{ 1, 2, 4, 8 }); | |
| 375 | ||
| 376 | try doTheTestDiv(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 }); | |
| 377 | try doTheTestDiv(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 }); | |
| 378 | try doTheTestDiv(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 }); | |
| 379 | try doTheTestDiv(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 }); | |
| 380 | ||
| 381 | try doTheTestMod(u8, [4]u8{ 1, 2, 4, 8 }, [4]u8{ 1, 1, 2, 4 }); | |
| 382 | try doTheTestMod(u16, [4]u16{ 1, 2, 4, 8 }, [4]u16{ 1, 1, 2, 4 }); | |
| 383 | try doTheTestMod(u32, [4]u32{ 1, 2, 4, 8 }, [4]u32{ 1, 1, 2, 4 }); | |
| 384 | try doTheTestMod(u64, [4]u64{ 1, 2, 4, 8 }, [4]u64{ 1, 1, 2, 4 }); | |
| 385 | 385 | } |
| 386 | 386 | }; |
| 387 | 387 | |
| 388 | S.doTheTest(); | |
| 389 | comptime S.doTheTest(); | |
| 388 | try S.doTheTest(); | |
| 389 | comptime try S.doTheTest(); | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | test "vector bitwise not operator" { |
| 393 | 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 | 395 | var y = ~x; |
| 396 | 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 { | |
| 401 | doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 }); | |
| 402 | doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 }); | |
| 403 | doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 }); | |
| 404 | doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 }); | |
| 405 | ||
| 406 | doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 }); | |
| 407 | doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 }); | |
| 408 | doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 }); | |
| 409 | doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 }); | |
| 400 | fn doTheTest() !void { | |
| 401 | try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 }); | |
| 402 | try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 }); | |
| 403 | try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 }); | |
| 404 | try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 }); | |
| 405 | ||
| 406 | try doTheTestNot(u8, [_]u8{ 0, 2, 4, 255 }); | |
| 407 | try doTheTestNot(u16, [_]u16{ 0, 2, 4, 255 }); | |
| 408 | try doTheTestNot(u32, [_]u32{ 0, 2, 4, 255 }); | |
| 409 | try doTheTestNot(u64, [_]u64{ 0, 2, 4, 255 }); | |
| 410 | 410 | } |
| 411 | 411 | }; |
| 412 | 412 | |
| 413 | S.doTheTest(); | |
| 414 | comptime S.doTheTest(); | |
| 413 | try S.doTheTest(); | |
| 414 | comptime try S.doTheTest(); | |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | test "vector shift operators" { |
| ... | ... | @@ -419,7 +419,7 @@ test "vector shift operators" { |
| 419 | 419 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 420 | 420 | |
| 421 | 421 | const S = struct { |
| 422 | fn doTheTestShift(x: anytype, y: anytype) void { | |
| 422 | fn doTheTestShift(x: anytype, y: anytype) !void { | |
| 423 | 423 | const N = @typeInfo(@TypeOf(x)).Array.len; |
| 424 | 424 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 425 | 425 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| ... | ... | @@ -429,14 +429,14 @@ test "vector shift operators" { |
| 429 | 429 | |
| 430 | 430 | var z0 = xv >> yv; |
| 431 | 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 | 434 | var z1 = xv << yv; |
| 435 | 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 | 440 | const N = @typeInfo(@TypeOf(x)).Array.len; |
| 441 | 441 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 442 | 442 | const TY = @typeInfo(@TypeOf(y)).Array.child; |
| ... | ... | @@ -447,33 +447,33 @@ test "vector shift operators" { |
| 447 | 447 | var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); |
| 448 | 448 | for (@as([N]TX, z)) |v, i| { |
| 449 | 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 { | |
| 454 | doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 }); | |
| 455 | doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 }); | |
| 456 | doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 }); | |
| 457 | doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 }); | |
| 458 | doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 }); | |
| 459 | ||
| 460 | doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 }); | |
| 461 | doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 }); | |
| 462 | doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 }); | |
| 463 | doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 }); | |
| 464 | doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 }); | |
| 465 | ||
| 466 | doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right); | |
| 467 | doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right); | |
| 468 | doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right); | |
| 469 | doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right); | |
| 470 | doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right); | |
| 471 | ||
| 472 | doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left); | |
| 473 | doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left); | |
| 474 | doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left); | |
| 475 | doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left); | |
| 476 | doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left); | |
| 453 | fn doTheTest() !void { | |
| 454 | try doTheTestShift([_]u8{ 0, 2, 4, math.maxInt(u8) }, [_]u3{ 2, 0, 2, 7 }); | |
| 455 | try doTheTestShift([_]u16{ 0, 2, 4, math.maxInt(u16) }, [_]u4{ 2, 0, 2, 15 }); | |
| 456 | try doTheTestShift([_]u24{ 0, 2, 4, math.maxInt(u24) }, [_]u5{ 2, 0, 2, 23 }); | |
| 457 | try doTheTestShift([_]u32{ 0, 2, 4, math.maxInt(u32) }, [_]u5{ 2, 0, 2, 31 }); | |
| 458 | try doTheTestShift([_]u64{ 0xfe, math.maxInt(u64) }, [_]u6{ 0, 63 }); | |
| 459 | ||
| 460 | try doTheTestShift([_]i8{ 0, 2, 4, math.maxInt(i8) }, [_]u3{ 2, 0, 2, 7 }); | |
| 461 | try doTheTestShift([_]i16{ 0, 2, 4, math.maxInt(i16) }, [_]u4{ 2, 0, 2, 7 }); | |
| 462 | try doTheTestShift([_]i24{ 0, 2, 4, math.maxInt(i24) }, [_]u5{ 2, 0, 2, 7 }); | |
| 463 | try doTheTestShift([_]i32{ 0, 2, 4, math.maxInt(i32) }, [_]u5{ 2, 0, 2, 7 }); | |
| 464 | try doTheTestShift([_]i64{ 0xfe, math.maxInt(i64) }, [_]u6{ 0, 63 }); | |
| 465 | ||
| 466 | try doTheTestShiftExact([_]u8{ 0, 1, 1 << 7, math.maxInt(u8) ^ 1 }, [_]u3{ 4, 0, 7, 1 }, .Right); | |
| 467 | try doTheTestShiftExact([_]u16{ 0, 1, 1 << 15, math.maxInt(u16) ^ 1 }, [_]u4{ 4, 0, 15, 1 }, .Right); | |
| 468 | try doTheTestShiftExact([_]u24{ 0, 1, 1 << 23, math.maxInt(u24) ^ 1 }, [_]u5{ 4, 0, 23, 1 }, .Right); | |
| 469 | try doTheTestShiftExact([_]u32{ 0, 1, 1 << 31, math.maxInt(u32) ^ 1 }, [_]u5{ 4, 0, 31, 1 }, .Right); | |
| 470 | try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 63, 0 }, .Right); | |
| 471 | ||
| 472 | try doTheTestShiftExact([_]u8{ 0, 1, 1, math.maxInt(u8) ^ (1 << 7) }, [_]u3{ 4, 0, 7, 1 }, .Left); | |
| 473 | try doTheTestShiftExact([_]u16{ 0, 1, 1, math.maxInt(u16) ^ (1 << 15) }, [_]u4{ 4, 0, 15, 1 }, .Left); | |
| 474 | try doTheTestShiftExact([_]u24{ 0, 1, 1, math.maxInt(u24) ^ (1 << 23) }, [_]u5{ 4, 0, 23, 1 }, .Left); | |
| 475 | try doTheTestShiftExact([_]u32{ 0, 1, 1, math.maxInt(u32) ^ (1 << 31) }, [_]u5{ 4, 0, 31, 1 }, .Left); | |
| 476 | try doTheTestShiftExact([_]u64{ 1 << 63, 1 }, [_]u6{ 0, 63 }, .Left); | |
| 477 | 477 | } |
| 478 | 478 | }; |
| 479 | 479 | |
| ... | ... | @@ -500,19 +500,19 @@ test "vector shift operators" { |
| 500 | 500 | else => {}, |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | S.doTheTest(); | |
| 504 | comptime S.doTheTest(); | |
| 503 | try S.doTheTest(); | |
| 504 | comptime try S.doTheTest(); | |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | test "vector reduce operation" { |
| 508 | 508 | const S = struct { |
| 509 | fn doTheTestReduce(comptime op: builtin.ReduceOp, x: anytype, expected: anytype) void { | |
| 509 | fn doTheTestReduce(comptime op: builtin.ReduceOp, x: anytype, expected: anytype) !void { | |
| 510 | 510 | const N = @typeInfo(@TypeOf(x)).Array.len; |
| 511 | 511 | const TX = @typeInfo(@TypeOf(x)).Array.child; |
| 512 | 512 | |
| 513 | 513 | var r = @reduce(op, @as(Vector(N, TX), x)); |
| 514 | 514 | switch (@typeInfo(TX)) { |
| 515 | .Int, .Bool => expectEqual(expected, r), | |
| 515 | .Int, .Bool => try expectEqual(expected, r), | |
| 516 | 516 | .Float => { |
| 517 | 517 | const expected_nan = math.isNan(expected); |
| 518 | 518 | const got_nan = math.isNan(r); |
| ... | ... | @@ -521,120 +521,120 @@ test "vector reduce operation" { |
| 521 | 521 | // Do this check explicitly as two NaN values are never |
| 522 | 522 | // equal. |
| 523 | 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 | 527 | else => unreachable, |
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | fn doTheTest() void { | |
| 531 | doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106)); | |
| 532 | doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106)); | |
| 533 | doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106)); | |
| 534 | doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106)); | |
| 535 | doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106)); | |
| 536 | doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106)); | |
| 537 | doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106)); | |
| 538 | doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106)); | |
| 539 | doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9)); | |
| 540 | doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9)); | |
| 541 | doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9)); | |
| 542 | ||
| 543 | doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false)); | |
| 544 | doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0)); | |
| 545 | doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10)); | |
| 546 | doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010)); | |
| 547 | doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010)); | |
| 548 | ||
| 549 | doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1)); | |
| 550 | doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1)); | |
| 551 | doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386)); | |
| 552 | doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9)); | |
| 530 | fn doTheTest() !void { | |
| 531 | try doTheTestReduce(.Add, [4]i16{ -9, -99, -999, -9999 }, @as(i32, -11106)); | |
| 532 | try doTheTestReduce(.Add, [4]u16{ 9, 99, 999, 9999 }, @as(u32, 11106)); | |
| 533 | try doTheTestReduce(.Add, [4]i32{ -9, -99, -999, -9999 }, @as(i32, -11106)); | |
| 534 | try doTheTestReduce(.Add, [4]u32{ 9, 99, 999, 9999 }, @as(u32, 11106)); | |
| 535 | try doTheTestReduce(.Add, [4]i64{ -9, -99, -999, -9999 }, @as(i64, -11106)); | |
| 536 | try doTheTestReduce(.Add, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 11106)); | |
| 537 | try doTheTestReduce(.Add, [4]i128{ -9, -99, -999, -9999 }, @as(i128, -11106)); | |
| 538 | try doTheTestReduce(.Add, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 11106)); | |
| 539 | try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 42.9)); | |
| 540 | try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 42.9)); | |
| 541 | try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 42.9)); | |
| 542 | ||
| 543 | try doTheTestReduce(.And, [4]bool{ true, false, true, true }, @as(bool, false)); | |
| 544 | try doTheTestReduce(.And, [4]u1{ 1, 0, 1, 1 }, @as(u1, 0)); | |
| 545 | try doTheTestReduce(.And, [4]u16{ 0xffff, 0xff55, 0xaaff, 0x1010 }, @as(u16, 0x10)); | |
| 546 | try doTheTestReduce(.And, [4]u32{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u32, 0x1010)); | |
| 547 | try doTheTestReduce(.And, [4]u64{ 0xffffffff, 0xffff5555, 0xaaaaffff, 0x10101010 }, @as(u64, 0x1010)); | |
| 548 | ||
| 549 | try doTheTestReduce(.Min, [4]i16{ -1, 2, 3, 4 }, @as(i16, -1)); | |
| 550 | try doTheTestReduce(.Min, [4]u16{ 1, 2, 3, 4 }, @as(u16, 1)); | |
| 551 | try doTheTestReduce(.Min, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, -386)); | |
| 552 | try doTheTestReduce(.Min, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 9)); | |
| 553 | 553 | |
| 554 | 554 | // LLVM 11 ERROR: Cannot select type |
| 555 | 555 | // https://github.com/ziglang/zig/issues/7138 |
| 556 | 556 | if (std.builtin.arch != .aarch64) { |
| 557 | doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386)); | |
| 558 | doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9)); | |
| 557 | try doTheTestReduce(.Min, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, -386)); | |
| 558 | try doTheTestReduce(.Min, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 9)); | |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386)); | |
| 562 | doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9)); | |
| 563 | doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0)); | |
| 564 | doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0)); | |
| 565 | doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0)); | |
| 561 | try doTheTestReduce(.Min, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, -386)); | |
| 562 | try doTheTestReduce(.Min, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 9)); | |
| 563 | try doTheTestReduce(.Min, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, -100.0)); | |
| 564 | try doTheTestReduce(.Min, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, -100.0)); | |
| 565 | try doTheTestReduce(.Min, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, -100.0)); | |
| 566 | 566 | |
| 567 | doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4)); | |
| 568 | doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4)); | |
| 569 | doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567)); | |
| 570 | doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999)); | |
| 567 | try doTheTestReduce(.Max, [4]i16{ -1, 2, 3, 4 }, @as(i16, 4)); | |
| 568 | try doTheTestReduce(.Max, [4]u16{ 1, 2, 3, 4 }, @as(u16, 4)); | |
| 569 | try doTheTestReduce(.Max, [4]i32{ 1234567, -386, 0, 3 }, @as(i32, 1234567)); | |
| 570 | try doTheTestReduce(.Max, [4]u32{ 99, 9999, 9, 99999 }, @as(u32, 99999)); | |
| 571 | 571 | |
| 572 | 572 | // LLVM 11 ERROR: Cannot select type |
| 573 | 573 | // https://github.com/ziglang/zig/issues/7138 |
| 574 | 574 | if (std.builtin.arch != .aarch64) { |
| 575 | doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567)); | |
| 576 | doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999)); | |
| 575 | try doTheTestReduce(.Max, [4]i64{ 1234567, -386, 0, 3 }, @as(i64, 1234567)); | |
| 576 | try doTheTestReduce(.Max, [4]u64{ 99, 9999, 9, 99999 }, @as(u64, 99999)); | |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567)); | |
| 580 | doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999)); | |
| 581 | doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9)); | |
| 582 | doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9)); | |
| 583 | doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9)); | |
| 584 | ||
| 585 | doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24)); | |
| 586 | doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24)); | |
| 587 | doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891)); | |
| 588 | doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24)); | |
| 589 | doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891)); | |
| 590 | doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891)); | |
| 591 | doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891)); | |
| 592 | doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891)); | |
| 593 | doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7)); | |
| 594 | doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7)); | |
| 595 | doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7)); | |
| 596 | ||
| 597 | doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true)); | |
| 598 | doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1)); | |
| 599 | doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0)); | |
| 600 | doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0)); | |
| 601 | doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff)); | |
| 602 | doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff)); | |
| 603 | ||
| 604 | doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true)); | |
| 605 | doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1)); | |
| 606 | doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0)); | |
| 607 | doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0)); | |
| 608 | doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff)); | |
| 609 | doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff)); | |
| 579 | try doTheTestReduce(.Max, [4]i128{ 1234567, -386, 0, 3 }, @as(i128, 1234567)); | |
| 580 | try doTheTestReduce(.Max, [4]u128{ 99, 9999, 9, 99999 }, @as(u128, 99999)); | |
| 581 | try doTheTestReduce(.Max, [4]f16{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f16, 10.0e9)); | |
| 582 | try doTheTestReduce(.Max, [4]f32{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f32, 10.0e9)); | |
| 583 | try doTheTestReduce(.Max, [4]f64{ -10.3, 10.0e9, 13.0, -100.0 }, @as(f64, 10.0e9)); | |
| 584 | ||
| 585 | try doTheTestReduce(.Mul, [4]i16{ -1, 2, 3, 4 }, @as(i16, -24)); | |
| 586 | try doTheTestReduce(.Mul, [4]u16{ 1, 2, 3, 4 }, @as(u16, 24)); | |
| 587 | try doTheTestReduce(.Mul, [4]i32{ -9, -99, -999, 999 }, @as(i32, -889218891)); | |
| 588 | try doTheTestReduce(.Mul, [4]u32{ 1, 2, 3, 4 }, @as(u32, 24)); | |
| 589 | try doTheTestReduce(.Mul, [4]i64{ 9, 99, 999, 9999 }, @as(i64, 8900199891)); | |
| 590 | try doTheTestReduce(.Mul, [4]u64{ 9, 99, 999, 9999 }, @as(u64, 8900199891)); | |
| 591 | try doTheTestReduce(.Mul, [4]i128{ -9, -99, -999, 9999 }, @as(i128, -8900199891)); | |
| 592 | try doTheTestReduce(.Mul, [4]u128{ 9, 99, 999, 9999 }, @as(u128, 8900199891)); | |
| 593 | try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, -60.3, 100.0 }, @as(f16, 58430.7)); | |
| 594 | try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, -60.3, 100.0 }, @as(f32, 58430.7)); | |
| 595 | try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, -60.3, 100.0 }, @as(f64, 58430.7)); | |
| 596 | ||
| 597 | try doTheTestReduce(.Or, [4]bool{ false, true, false, false }, @as(bool, true)); | |
| 598 | try doTheTestReduce(.Or, [4]u1{ 0, 1, 0, 0 }, @as(u1, 1)); | |
| 599 | try doTheTestReduce(.Or, [4]u16{ 0xff00, 0xff00, 0xf0, 0xf }, ~@as(u16, 0)); | |
| 600 | try doTheTestReduce(.Or, [4]u32{ 0xffff0000, 0xff00, 0xf0, 0xf }, ~@as(u32, 0)); | |
| 601 | try doTheTestReduce(.Or, [4]u64{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u64, 0xffffffff)); | |
| 602 | try doTheTestReduce(.Or, [4]u128{ 0xffff0000, 0xff00, 0xf0, 0xf }, @as(u128, 0xffffffff)); | |
| 603 | ||
| 604 | try doTheTestReduce(.Xor, [4]bool{ true, true, true, false }, @as(bool, true)); | |
| 605 | try doTheTestReduce(.Xor, [4]u1{ 1, 1, 1, 0 }, @as(u1, 1)); | |
| 606 | try doTheTestReduce(.Xor, [4]u16{ 0x0000, 0x3333, 0x8888, 0x4444 }, ~@as(u16, 0)); | |
| 607 | try doTheTestReduce(.Xor, [4]u32{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, ~@as(u32, 0)); | |
| 608 | try doTheTestReduce(.Xor, [4]u64{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u64, 0xffffffff)); | |
| 609 | try doTheTestReduce(.Xor, [4]u128{ 0x00000000, 0x33333333, 0x88888888, 0x44444444 }, @as(u128, 0xffffffff)); | |
| 610 | 610 | |
| 611 | 611 | // Test the reduction on vectors containing NaNs. |
| 612 | 612 | const f16_nan = math.nan(f16); |
| 613 | 613 | const f32_nan = math.nan(f32); |
| 614 | 614 | const f64_nan = math.nan(f64); |
| 615 | 615 | |
| 616 | doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 617 | doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 618 | doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 616 | try doTheTestReduce(.Add, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 617 | try doTheTestReduce(.Add, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 618 | try doTheTestReduce(.Add, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 619 | 619 | |
| 620 | 620 | // LLVM 11 ERROR: Cannot select type |
| 621 | 621 | // https://github.com/ziglang/zig/issues/7138 |
| 622 | 622 | if (false) { |
| 623 | doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 624 | doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 625 | doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 623 | try doTheTestReduce(.Min, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 624 | try doTheTestReduce(.Min, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 625 | try doTheTestReduce(.Min, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 626 | 626 | |
| 627 | doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 628 | doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 629 | doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 627 | try doTheTestReduce(.Max, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 628 | try doTheTestReduce(.Max, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 629 | try doTheTestReduce(.Max, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 633 | doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 634 | doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 632 | try doTheTestReduce(.Mul, [4]f16{ -1.9, 5.1, f16_nan, 100.0 }, f16_nan); | |
| 633 | try doTheTestReduce(.Mul, [4]f32{ -1.9, 5.1, f32_nan, 100.0 }, f32_nan); | |
| 634 | try doTheTestReduce(.Mul, [4]f64{ -1.9, 5.1, f64_nan, 100.0 }, f64_nan); | |
| 635 | 635 | } |
| 636 | 636 | }; |
| 637 | 637 | |
| 638 | S.doTheTest(); | |
| 639 | comptime S.doTheTest(); | |
| 638 | try S.doTheTest(); | |
| 639 | comptime try S.doTheTest(); | |
| 640 | 640 | } |
test/stage1/behavior/void.zig+3-3| ... | ... | @@ -13,14 +13,14 @@ test "compare void with void compile time known" { |
| 13 | 13 | .b = 1, |
| 14 | 14 | .c = {}, |
| 15 | 15 | }; |
| 16 | expect(foo.a == {}); | |
| 16 | try expect(foo.a == {}); | |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | test "iterate over a void slice" { |
| 21 | 21 | var j: usize = 0; |
| 22 | 22 | for (times(10)) |_, i| { |
| 23 | expect(i == j); | |
| 23 | try expect(i == j); | |
| 24 | 24 | j += 1; |
| 25 | 25 | } |
| 26 | 26 | } |
| ... | ... | @@ -31,7 +31,7 @@ fn times(n: usize) []const void { |
| 31 | 31 | |
| 32 | 32 | test "void optional" { |
| 33 | 33 | var x: ?void = {}; |
| 34 | expect(x != null); | |
| 34 | try expect(x != null); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | test "void array as a local variable initializer" { |
test/stage1/behavior/wasm.zig+2-2| ... | ... | @@ -3,6 +3,6 @@ const expect = std.testing.expect; |
| 3 | 3 | |
| 4 | 4 | test "memory size and grow" { |
| 5 | 5 | var prev = @wasmMemorySize(0); |
| 6 | expect(prev == @wasmMemoryGrow(0, 1)); | |
| 7 | expect(prev + 1 == @wasmMemorySize(0)); | |
| 6 | try expect(prev == @wasmMemoryGrow(0, 1)); | |
| 7 | try expect(prev + 1 == @wasmMemorySize(0)); | |
| 8 | 8 | } |
test/stage1/behavior/while.zig+45-51| ... | ... | @@ -6,8 +6,8 @@ test "while loop" { |
| 6 | 6 | while (i < 4) { |
| 7 | 7 | i += 1; |
| 8 | 8 | } |
| 9 | expect(i == 4); | |
| 10 | expect(whileLoop1() == 1); | |
| 9 | try expect(i == 4); | |
| 10 | try expect(whileLoop1() == 1); | |
| 11 | 11 | } |
| 12 | 12 | fn whileLoop1() i32 { |
| 13 | 13 | return whileLoop2(); |
| ... | ... | @@ -19,7 +19,7 @@ fn whileLoop2() i32 { |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "static eval while" { |
| 22 | expect(static_eval_while_number == 1); | |
| 22 | try expect(static_eval_while_number == 1); | |
| 23 | 23 | } |
| 24 | 24 | const static_eval_while_number = staticWhileLoop1(); |
| 25 | 25 | fn staticWhileLoop1() i32 { |
| ... | ... | @@ -32,11 +32,11 @@ fn staticWhileLoop2() i32 { |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "continue and break" { |
| 35 | runContinueAndBreakTest(); | |
| 36 | expect(continue_and_break_counter == 8); | |
| 35 | try runContinueAndBreakTest(); | |
| 36 | try expect(continue_and_break_counter == 8); | |
| 37 | 37 | } |
| 38 | 38 | var continue_and_break_counter: i32 = 0; |
| 39 | fn runContinueAndBreakTest() void { | |
| 39 | fn runContinueAndBreakTest() !void { | |
| 40 | 40 | var i: i32 = 0; |
| 41 | 41 | while (true) { |
| 42 | 42 | continue_and_break_counter += 2; |
| ... | ... | @@ -46,7 +46,7 @@ fn runContinueAndBreakTest() void { |
| 46 | 46 | } |
| 47 | 47 | break; |
| 48 | 48 | } |
| 49 | expect(i == 4); | |
| 49 | try expect(i == 4); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | test "return with implicit cast from while loop" { |
| ... | ... | @@ -67,7 +67,7 @@ test "while with continue expression" { |
| 67 | 67 | sum += i; |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | expect(sum == 40); | |
| 70 | try expect(sum == 40); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | test "while with else" { |
| ... | ... | @@ -79,8 +79,8 @@ test "while with else" { |
| 79 | 79 | } else { |
| 80 | 80 | got_else += 1; |
| 81 | 81 | } |
| 82 | expect(sum == 10); | |
| 83 | expect(got_else == 1); | |
| 82 | try expect(sum == 10); | |
| 83 | try expect(got_else == 1); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "while with optional as condition" { |
| ... | ... | @@ -89,7 +89,7 @@ test "while with optional as condition" { |
| 89 | 89 | while (getNumberOrNull()) |value| { |
| 90 | 90 | sum += value; |
| 91 | 91 | } |
| 92 | expect(sum == 45); | |
| 92 | try expect(sum == 45); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | test "while with optional as condition with else" { |
| ... | ... | @@ -98,12 +98,12 @@ test "while with optional as condition with else" { |
| 98 | 98 | var got_else: i32 = 0; |
| 99 | 99 | while (getNumberOrNull()) |value| { |
| 100 | 100 | sum += value; |
| 101 | expect(got_else == 0); | |
| 101 | try expect(got_else == 0); | |
| 102 | 102 | } else { |
| 103 | 103 | got_else += 1; |
| 104 | 104 | } |
| 105 | expect(sum == 45); | |
| 106 | expect(got_else == 1); | |
| 105 | try expect(sum == 45); | |
| 106 | try expect(got_else == 1); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | test "while with error union condition" { |
| ... | ... | @@ -113,11 +113,11 @@ test "while with error union condition" { |
| 113 | 113 | while (getNumberOrErr()) |value| { |
| 114 | 114 | sum += value; |
| 115 | 115 | } else |err| { |
| 116 | expect(err == error.OutOfNumbers); | |
| 116 | try expect(err == error.OutOfNumbers); | |
| 117 | 117 | got_else += 1; |
| 118 | 118 | } |
| 119 | expect(sum == 45); | |
| 120 | expect(got_else == 1); | |
| 119 | try expect(sum == 45); | |
| 120 | try expect(got_else == 1); | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | var numbers_left: i32 = undefined; |
| ... | ... | @@ -137,49 +137,43 @@ fn getNumberOrNull() ?i32 { |
| 137 | 137 | test "while on optional with else result follow else prong" { |
| 138 | 138 | const result = while (returnNull()) |value| { |
| 139 | 139 | break value; |
| 140 | } else | |
| 141 | @as(i32, 2); | |
| 142 | expect(result == 2); | |
| 140 | } else @as(i32, 2); | |
| 141 | try expect(result == 2); | |
| 143 | 142 | } |
| 144 | 143 | |
| 145 | 144 | test "while on optional with else result follow break prong" { |
| 146 | 145 | const result = while (returnOptional(10)) |value| { |
| 147 | 146 | break value; |
| 148 | } else | |
| 149 | @as(i32, 2); | |
| 150 | expect(result == 10); | |
| 147 | } else @as(i32, 2); | |
| 148 | try expect(result == 10); | |
| 151 | 149 | } |
| 152 | 150 | |
| 153 | 151 | test "while on error union with else result follow else prong" { |
| 154 | 152 | const result = while (returnError()) |value| { |
| 155 | 153 | break value; |
| 156 | } else |err| | |
| 157 | @as(i32, 2); | |
| 158 | expect(result == 2); | |
| 154 | } else |err| @as(i32, 2); | |
| 155 | try expect(result == 2); | |
| 159 | 156 | } |
| 160 | 157 | |
| 161 | 158 | test "while on error union with else result follow break prong" { |
| 162 | 159 | const result = while (returnSuccess(10)) |value| { |
| 163 | 160 | break value; |
| 164 | } else |err| | |
| 165 | @as(i32, 2); | |
| 166 | expect(result == 10); | |
| 161 | } else |err| @as(i32, 2); | |
| 162 | try expect(result == 10); | |
| 167 | 163 | } |
| 168 | 164 | |
| 169 | 165 | test "while on bool with else result follow else prong" { |
| 170 | 166 | const result = while (returnFalse()) { |
| 171 | 167 | break @as(i32, 10); |
| 172 | } else | |
| 173 | @as(i32, 2); | |
| 174 | expect(result == 2); | |
| 168 | } else @as(i32, 2); | |
| 169 | try expect(result == 2); | |
| 175 | 170 | } |
| 176 | 171 | |
| 177 | 172 | test "while on bool with else result follow break prong" { |
| 178 | 173 | const result = while (returnTrue()) { |
| 179 | 174 | break @as(i32, 10); |
| 180 | } else | |
| 181 | @as(i32, 2); | |
| 182 | expect(result == 10); | |
| 175 | } else @as(i32, 2); | |
| 176 | try expect(result == 10); | |
| 183 | 177 | } |
| 184 | 178 | |
| 185 | 179 | test "break from outer while loop" { |
| ... | ... | @@ -230,60 +224,60 @@ fn returnTrue() bool { |
| 230 | 224 | |
| 231 | 225 | test "while bool 2 break statements and an else" { |
| 232 | 226 | const S = struct { |
| 233 | fn entry(t: bool, f: bool) void { | |
| 227 | fn entry(t: bool, f: bool) !void { | |
| 234 | 228 | var ok = false; |
| 235 | 229 | ok = while (t) { |
| 236 | 230 | if (f) break false; |
| 237 | 231 | if (t) break true; |
| 238 | 232 | } else false; |
| 239 | expect(ok); | |
| 233 | try expect(ok); | |
| 240 | 234 | } |
| 241 | 235 | }; |
| 242 | S.entry(true, false); | |
| 243 | comptime S.entry(true, false); | |
| 236 | try S.entry(true, false); | |
| 237 | comptime try S.entry(true, false); | |
| 244 | 238 | } |
| 245 | 239 | |
| 246 | 240 | test "while optional 2 break statements and an else" { |
| 247 | 241 | const S = struct { |
| 248 | fn entry(opt_t: ?bool, f: bool) void { | |
| 242 | fn entry(opt_t: ?bool, f: bool) !void { | |
| 249 | 243 | var ok = false; |
| 250 | 244 | ok = while (opt_t) |t| { |
| 251 | 245 | if (f) break false; |
| 252 | 246 | if (t) break true; |
| 253 | 247 | } else false; |
| 254 | expect(ok); | |
| 248 | try expect(ok); | |
| 255 | 249 | } |
| 256 | 250 | }; |
| 257 | S.entry(true, false); | |
| 258 | comptime S.entry(true, false); | |
| 251 | try S.entry(true, false); | |
| 252 | comptime try S.entry(true, false); | |
| 259 | 253 | } |
| 260 | 254 | |
| 261 | 255 | test "while error 2 break statements and an else" { |
| 262 | 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 | 258 | var ok = false; |
| 265 | 259 | ok = while (opt_t) |t| { |
| 266 | 260 | if (f) break false; |
| 267 | 261 | if (t) break true; |
| 268 | 262 | } else |_| false; |
| 269 | expect(ok); | |
| 263 | try expect(ok); | |
| 270 | 264 | } |
| 271 | 265 | }; |
| 272 | S.entry(true, false); | |
| 273 | comptime S.entry(true, false); | |
| 266 | try S.entry(true, false); | |
| 267 | comptime try S.entry(true, false); | |
| 274 | 268 | } |
| 275 | 269 | |
| 276 | 270 | test "while copies its payload" { |
| 277 | 271 | const S = struct { |
| 278 | fn doTheTest() void { | |
| 272 | fn doTheTest() !void { | |
| 279 | 273 | var tmp: ?i32 = 10; |
| 280 | 274 | while (tmp) |value| { |
| 281 | 275 | // Modify the original variable |
| 282 | 276 | tmp = null; |
| 283 | expect(value == 10); | |
| 277 | try expect(value == 10); | |
| 284 | 278 | } |
| 285 | 279 | } |
| 286 | 280 | }; |
| 287 | S.doTheTest(); | |
| 288 | comptime S.doTheTest(); | |
| 281 | try S.doTheTest(); | |
| 282 | comptime try S.doTheTest(); | |
| 289 | 283 | } |
test/stage1/behavior/widening.zig+6-6| ... | ... | @@ -9,13 +9,13 @@ test "integer widening" { |
| 9 | 9 | var d: u64 = c; |
| 10 | 10 | var e: u64 = d; |
| 11 | 11 | var f: u128 = e; |
| 12 | expect(f == a); | |
| 12 | try expect(f == a); | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | test "implicit unsigned integer to signed integer" { |
| 16 | 16 | var a: u8 = 250; |
| 17 | 17 | var b: i16 = a; |
| 18 | expect(b == 250); | |
| 18 | try expect(b == 250); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | test "float widening" { |
| ... | ... | @@ -23,9 +23,9 @@ test "float widening" { |
| 23 | 23 | var b: f32 = a; |
| 24 | 24 | var c: f64 = b; |
| 25 | 25 | var d: f128 = c; |
| 26 | expect(a == b); | |
| 27 | expect(b == c); | |
| 28 | expect(c == d); | |
| 26 | try expect(a == b); | |
| 27 | try expect(b == c); | |
| 28 | try expect(c == d); | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | test "float widening f16 to f128" { |
| ... | ... | @@ -35,5 +35,5 @@ test "float widening f16 to f128" { |
| 35 | 35 | |
| 36 | 36 | var x: f16 = 12.34; |
| 37 | 37 | var y: f128 = x; |
| 38 | expect(x == y); | |
| 38 | try expect(x == y); | |
| 39 | 39 | } |
test/stage1/c_abi/main.zig+58-58| ... | ... | @@ -24,11 +24,11 @@ extern fn c_i64(i64) void; |
| 24 | 24 | extern fn c_five_integers(i32, i32, i32, i32, i32) void; |
| 25 | 25 | |
| 26 | 26 | export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void { |
| 27 | expect(a == 12); | |
| 28 | expect(b == 34); | |
| 29 | expect(c == 56); | |
| 30 | expect(d == 78); | |
| 31 | expect(e == 90); | |
| 27 | expect(a == 12) catch @panic("test failure"); | |
| 28 | expect(b == 34) catch @panic("test failure"); | |
| 29 | expect(c == 56) catch @panic("test failure"); | |
| 30 | expect(d == 78) catch @panic("test failure"); | |
| 31 | expect(e == 90) catch @panic("test failure"); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | test "C ABI integers" { |
| ... | ... | @@ -45,28 +45,28 @@ test "C ABI integers" { |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | export fn zig_u8(x: u8) void { |
| 48 | expect(x == 0xff); | |
| 48 | expect(x == 0xff) catch @panic("test failure"); | |
| 49 | 49 | } |
| 50 | 50 | export fn zig_u16(x: u16) void { |
| 51 | expect(x == 0xfffe); | |
| 51 | expect(x == 0xfffe) catch @panic("test failure"); | |
| 52 | 52 | } |
| 53 | 53 | export fn zig_u32(x: u32) void { |
| 54 | expect(x == 0xfffffffd); | |
| 54 | expect(x == 0xfffffffd) catch @panic("test failure"); | |
| 55 | 55 | } |
| 56 | 56 | export fn zig_u64(x: u64) void { |
| 57 | expect(x == 0xfffffffffffffffc); | |
| 57 | expect(x == 0xfffffffffffffffc) catch @panic("test failure"); | |
| 58 | 58 | } |
| 59 | 59 | export fn zig_i8(x: i8) void { |
| 60 | expect(x == -1); | |
| 60 | expect(x == -1) catch @panic("test failure"); | |
| 61 | 61 | } |
| 62 | 62 | export fn zig_i16(x: i16) void { |
| 63 | expect(x == -2); | |
| 63 | expect(x == -2) catch @panic("test failure"); | |
| 64 | 64 | } |
| 65 | 65 | export fn zig_i32(x: i32) void { |
| 66 | expect(x == -3); | |
| 66 | expect(x == -3) catch @panic("test failure"); | |
| 67 | 67 | } |
| 68 | 68 | export fn zig_i64(x: i64) void { |
| 69 | expect(x == -4); | |
| 69 | expect(x == -4) catch @panic("test failure"); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | extern fn c_f32(f32) void; |
| ... | ... | @@ -76,11 +76,11 @@ extern fn c_f64(f64) void; |
| 76 | 76 | extern fn c_five_floats(f32, f32, f32, f32, f32) void; |
| 77 | 77 | |
| 78 | 78 | export fn zig_five_floats(a: f32, b: f32, c: f32, d: f32, e: f32) void { |
| 79 | expect(a == 1.0); | |
| 80 | expect(b == 2.0); | |
| 81 | expect(c == 3.0); | |
| 82 | expect(d == 4.0); | |
| 83 | expect(e == 5.0); | |
| 79 | expect(a == 1.0) catch @panic("test failure"); | |
| 80 | expect(b == 2.0) catch @panic("test failure"); | |
| 81 | expect(c == 3.0) catch @panic("test failure"); | |
| 82 | expect(d == 4.0) catch @panic("test failure"); | |
| 83 | expect(e == 5.0) catch @panic("test failure"); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | test "C ABI floats" { |
| ... | ... | @@ -90,10 +90,10 @@ test "C ABI floats" { |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | export fn zig_f32(x: f32) void { |
| 93 | expect(x == 12.34); | |
| 93 | expect(x == 12.34) catch @panic("test failure"); | |
| 94 | 94 | } |
| 95 | 95 | export fn zig_f64(x: f64) void { |
| 96 | expect(x == 56.78); | |
| 96 | expect(x == 56.78) catch @panic("test failure"); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | extern fn c_ptr(*c_void) void; |
| ... | ... | @@ -103,7 +103,7 @@ test "C ABI pointer" { |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | export fn zig_ptr(x: *c_void) void { |
| 106 | expect(@ptrToInt(x) == 0xdeadbeef); | |
| 106 | expect(@ptrToInt(x) == 0xdeadbeef) catch @panic("test failure"); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | extern fn c_bool(bool) void; |
| ... | ... | @@ -113,7 +113,7 @@ test "C ABI bool" { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | export fn zig_bool(x: bool) void { |
| 116 | expect(x); | |
| 116 | expect(x) catch @panic("test failure"); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | const BigStruct = extern struct { |
| ... | ... | @@ -137,11 +137,11 @@ test "C ABI big struct" { |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | export fn zig_big_struct(x: BigStruct) void { |
| 140 | expect(x.a == 1); | |
| 141 | expect(x.b == 2); | |
| 142 | expect(x.c == 3); | |
| 143 | expect(x.d == 4); | |
| 144 | expect(x.e == 5); | |
| 140 | expect(x.a == 1) catch @panic("test failure"); | |
| 141 | expect(x.b == 2) catch @panic("test failure"); | |
| 142 | expect(x.c == 3) catch @panic("test failure"); | |
| 143 | expect(x.d == 4) catch @panic("test failure"); | |
| 144 | expect(x.e == 5) catch @panic("test failure"); | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | const BigUnion = extern union { |
| ... | ... | @@ -163,11 +163,11 @@ test "C ABI big union" { |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | export fn zig_big_union(x: BigUnion) void { |
| 166 | expect(x.a.a == 1); | |
| 167 | expect(x.a.b == 2); | |
| 168 | expect(x.a.c == 3); | |
| 169 | expect(x.a.d == 4); | |
| 170 | expect(x.a.e == 5); | |
| 166 | expect(x.a.a == 1) catch @panic("test failure"); | |
| 167 | expect(x.a.b == 2) catch @panic("test failure"); | |
| 168 | expect(x.a.c == 3) catch @panic("test failure"); | |
| 169 | expect(x.a.d == 4) catch @panic("test failure"); | |
| 170 | expect(x.a.e == 5) catch @panic("test failure"); | |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | const SmallStructInts = extern struct { |
| ... | ... | @@ -189,10 +189,10 @@ test "C ABI small struct of ints" { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | export fn zig_small_struct_ints(x: SmallStructInts) void { |
| 192 | expect(x.a == 1); | |
| 193 | expect(x.b == 2); | |
| 194 | expect(x.c == 3); | |
| 195 | expect(x.d == 4); | |
| 192 | expect(x.a == 1) catch @panic("test failure"); | |
| 193 | expect(x.b == 2) catch @panic("test failure"); | |
| 194 | expect(x.c == 3) catch @panic("test failure"); | |
| 195 | expect(x.d == 4) catch @panic("test failure"); | |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | const SplitStructInt = extern struct { |
| ... | ... | @@ -212,9 +212,9 @@ test "C ABI split struct of ints" { |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | export fn zig_split_struct_ints(x: SplitStructInt) void { |
| 215 | expect(x.a == 1234); | |
| 216 | expect(x.b == 100); | |
| 217 | expect(x.c == 1337); | |
| 215 | expect(x.a == 1234) catch @panic("test failure"); | |
| 216 | expect(x.b == 100) catch @panic("test failure"); | |
| 217 | expect(x.c == 1337) catch @panic("test failure"); | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | extern fn c_big_struct_both(BigStruct) BigStruct; |
| ... | ... | @@ -228,19 +228,19 @@ test "C ABI sret and byval together" { |
| 228 | 228 | .e = 5, |
| 229 | 229 | }; |
| 230 | 230 | var y = c_big_struct_both(s); |
| 231 | expect(y.a == 10); | |
| 232 | expect(y.b == 11); | |
| 233 | expect(y.c == 12); | |
| 234 | expect(y.d == 13); | |
| 235 | expect(y.e == 14); | |
| 231 | try expect(y.a == 10); | |
| 232 | try expect(y.b == 11); | |
| 233 | try expect(y.c == 12); | |
| 234 | try expect(y.d == 13); | |
| 235 | try expect(y.e == 14); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | export fn zig_big_struct_both(x: BigStruct) BigStruct { |
| 239 | expect(x.a == 30); | |
| 240 | expect(x.b == 31); | |
| 241 | expect(x.c == 32); | |
| 242 | expect(x.d == 33); | |
| 243 | expect(x.e == 34); | |
| 239 | expect(x.a == 30) catch @panic("test failure"); | |
| 240 | expect(x.b == 31) catch @panic("test failure"); | |
| 241 | expect(x.c == 32) catch @panic("test failure"); | |
| 242 | expect(x.d == 33) catch @panic("test failure"); | |
| 243 | expect(x.e == 34) catch @panic("test failure"); | |
| 244 | 244 | var s = BigStruct{ |
| 245 | 245 | .a = 20, |
| 246 | 246 | .b = 21, |
| ... | ... | @@ -324,15 +324,15 @@ extern fn c_ret_i32() i32; |
| 324 | 324 | extern fn c_ret_i64() i64; |
| 325 | 325 | |
| 326 | 326 | test "C ABI integer return types" { |
| 327 | expect(c_ret_bool() == true); | |
| 327 | try expect(c_ret_bool() == true); | |
| 328 | 328 | |
| 329 | expect(c_ret_u8() == 0xff); | |
| 330 | expect(c_ret_u16() == 0xffff); | |
| 331 | expect(c_ret_u32() == 0xffffffff); | |
| 332 | expect(c_ret_u64() == 0xffffffffffffffff); | |
| 329 | try expect(c_ret_u8() == 0xff); | |
| 330 | try expect(c_ret_u16() == 0xffff); | |
| 331 | try expect(c_ret_u32() == 0xffffffff); | |
| 332 | try expect(c_ret_u64() == 0xffffffffffffffff); | |
| 333 | 333 | |
| 334 | expect(c_ret_i8() == -1); | |
| 335 | expect(c_ret_i16() == -1); | |
| 336 | expect(c_ret_i32() == -1); | |
| 337 | expect(c_ret_i64() == -1); | |
| 334 | try expect(c_ret_i8() == -1); | |
| 335 | try expect(c_ret_i16() == -1); | |
| 336 | try expect(c_ret_i32() == -1); | |
| 337 | try expect(c_ret_i64() == -1); | |
| 338 | 338 | } |
test/standalone/brace_expansion/main.zig+31-31| ... | ... | @@ -241,52 +241,52 @@ pub fn main() !void { |
| 241 | 241 | test "invalid inputs" { |
| 242 | 242 | global_allocator = std.testing.allocator; |
| 243 | 243 | |
| 244 | expectError("}ABC", error.InvalidInput); | |
| 245 | expectError("{ABC", error.InvalidInput); | |
| 246 | expectError("}{", error.InvalidInput); | |
| 247 | expectError("{}", error.InvalidInput); | |
| 248 | expectError("A,B,C", error.InvalidInput); | |
| 249 | expectError("{A{B,C}", error.InvalidInput); | |
| 250 | expectError("{A,}", error.InvalidInput); | |
| 251 | ||
| 252 | expectError("\n", error.InvalidInput); | |
| 244 | try expectError("}ABC", error.InvalidInput); | |
| 245 | try expectError("{ABC", error.InvalidInput); | |
| 246 | try expectError("}{", error.InvalidInput); | |
| 247 | try expectError("{}", error.InvalidInput); | |
| 248 | try expectError("A,B,C", error.InvalidInput); | |
| 249 | try expectError("{A{B,C}", error.InvalidInput); | |
| 250 | try expectError("{A,}", error.InvalidInput); | |
| 251 | ||
| 252 | try expectError("\n", error.InvalidInput); | |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | fn expectError(test_input: []const u8, expected_err: anyerror) void { | |
| 255 | fn expectError(test_input: []const u8, expected_err: anyerror) !void { | |
| 256 | 256 | var output_buf = ArrayList(u8).init(global_allocator); |
| 257 | 257 | defer output_buf.deinit(); |
| 258 | 258 | |
| 259 | testing.expectError(expected_err, expandString(test_input, &output_buf)); | |
| 259 | try testing.expectError(expected_err, expandString(test_input, &output_buf)); | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | test "valid inputs" { |
| 263 | 263 | global_allocator = std.testing.allocator; |
| 264 | 264 | |
| 265 | expectExpansion("{x,y,z}", "x y z"); | |
| 266 | expectExpansion("{A,B}{x,y}", "Ax Ay Bx By"); | |
| 267 | expectExpansion("{A,B{x,y}}", "A Bx By"); | |
| 268 | ||
| 269 | expectExpansion("{ABC}", "ABC"); | |
| 270 | expectExpansion("{A,B,C}", "A B C"); | |
| 271 | expectExpansion("ABC", "ABC"); | |
| 272 | ||
| 273 | expectExpansion("", ""); | |
| 274 | expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh"); | |
| 275 | expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh"); | |
| 276 | expectExpansion("{A,B}a", "Aa Ba"); | |
| 277 | expectExpansion("{C,{x,y}}", "C x y"); | |
| 278 | expectExpansion("z{C,{x,y}}", "zC zx zy"); | |
| 279 | expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg"); | |
| 280 | expectExpansion("a{x,y}b", "axb ayb"); | |
| 281 | expectExpansion("z{{a,b}}", "za zb"); | |
| 282 | expectExpansion("a{b}", "ab"); | |
| 265 | try expectExpansion("{x,y,z}", "x y z"); | |
| 266 | try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By"); | |
| 267 | try expectExpansion("{A,B{x,y}}", "A Bx By"); | |
| 268 | ||
| 269 | try expectExpansion("{ABC}", "ABC"); | |
| 270 | try expectExpansion("{A,B,C}", "A B C"); | |
| 271 | try expectExpansion("ABC", "ABC"); | |
| 272 | ||
| 273 | try expectExpansion("", ""); | |
| 274 | try expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh"); | |
| 275 | try expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh"); | |
| 276 | try expectExpansion("{A,B}a", "Aa Ba"); | |
| 277 | try expectExpansion("{C,{x,y}}", "C x y"); | |
| 278 | try expectExpansion("z{C,{x,y}}", "zC zx zy"); | |
| 279 | try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg"); | |
| 280 | try expectExpansion("a{x,y}b", "axb ayb"); | |
| 281 | try expectExpansion("z{{a,b}}", "za zb"); | |
| 282 | try expectExpansion("a{b}", "ab"); | |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | fn expectExpansion(test_input: []const u8, expected_result: []const u8) void { | |
| 285 | fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void { | |
| 286 | 286 | var result = ArrayList(u8).init(global_allocator); |
| 287 | 287 | defer result.deinit(); |
| 288 | 288 | |
| 289 | 289 | expandString(test_input, &result) catch unreachable; |
| 290 | 290 | |
| 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 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | pub fn main() void { | |
| 3 | pub fn main() !void { | |
| 4 | 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 | 4 | extern var obj2_integer: usize; |
| 5 | 5 | |
| 6 | 6 | test "access the external integers" { |
| 7 | std.testing.expect(obj1_integer == 421); | |
| 8 | std.testing.expect(obj2_integer == 422); | |
| 7 | try std.testing.expect(obj1_integer == 421); | |
| 8 | try std.testing.expect(obj2_integer == 422); | |
| 9 | 9 | } |
test/standalone/issue_794/main.zig+1-1| ... | ... | @@ -3,5 +3,5 @@ const std = @import("std"); |
| 3 | 3 | const testing = std.testing; |
| 4 | 4 | |
| 5 | 5 | test "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 | 4 | |
| 5 | 5 | test "import C sub" { |
| 6 | 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 | 4 | |
| 5 | 5 | test "C add" { |
| 6 | 6 | const result = c.add(1, 2); |
| 7 | expect(result == 3); | |
| 7 | try expect(result == 3); | |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | test "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 | 6 | .a = 1, |
| 7 | 7 | .b = 1, |
| 8 | 8 | }; |
| 9 | expect(foo.a + foo.b == 2); | |
| 9 | try expect(foo.a + foo.b == 2); | |
| 10 | 10 | } |