| author | |
| committer | |
| log | 12191c8a220ca5594b278b5077bff98e8fecac08 |
| tree | ce6552d68161c363dd18826220febbaa7f733c62 |
| parent | 5ae838d10596a272644da314937b01aa1a271a73 |
Now these show up as "example usage" in generated documentation.26 files changed, 311 insertions(+), 289 deletions(-)
lib/std/ascii.zig+9-9| ... | @@ -147,7 +147,7 @@ pub fn isWhitespace(c: u8) bool { | ... | @@ -147,7 +147,7 @@ pub fn isWhitespace(c: u8) bool { |
| 147 | /// See also: `isWhitespace` | 147 | /// See also: `isWhitespace` |
| 148 | pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff }; | 148 | pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff }; |
| 149 | 149 | ||
| 150 | test "whitespace" { | 150 | test whitespace { |
| 151 | for (whitespace) |char| try std.testing.expect(isWhitespace(char)); | 151 | for (whitespace) |char| try std.testing.expect(isWhitespace(char)); |
| 152 | 152 | ||
| 153 | var i: u8 = 0; | 153 | var i: u8 = 0; |
| ... | @@ -278,7 +278,7 @@ pub fn lowerString(output: []u8, ascii_string: []const u8) []u8 { | ... | @@ -278,7 +278,7 @@ pub fn lowerString(output: []u8, ascii_string: []const u8) []u8 { |
| 278 | return output[0..ascii_string.len]; | 278 | return output[0..ascii_string.len]; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | test "lowerString" { | 281 | test lowerString { |
| 282 | var buf: [1024]u8 = undefined; | 282 | var buf: [1024]u8 = undefined; |
| 283 | const result = lowerString(&buf, "aBcDeFgHiJkLmNOPqrst0234+π©!"); | 283 | const result = lowerString(&buf, "aBcDeFgHiJkLmNOPqrst0234+π©!"); |
| 284 | try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+π©!", result); | 284 | try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+π©!", result); |
| ... | @@ -291,7 +291,7 @@ pub fn allocLowerString(allocator: std.mem.Allocator, ascii_string: []const u8) | ... | @@ -291,7 +291,7 @@ pub fn allocLowerString(allocator: std.mem.Allocator, ascii_string: []const u8) |
| 291 | return lowerString(result, ascii_string); | 291 | return lowerString(result, ascii_string); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | test "allocLowerString" { | 294 | test allocLowerString { |
| 295 | const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!"); | 295 | const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!"); |
| 296 | defer std.testing.allocator.free(result); | 296 | defer std.testing.allocator.free(result); |
| 297 | try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+π©!", result); | 297 | try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+π©!", result); |
| ... | @@ -307,7 +307,7 @@ pub fn upperString(output: []u8, ascii_string: []const u8) []u8 { | ... | @@ -307,7 +307,7 @@ pub fn upperString(output: []u8, ascii_string: []const u8) []u8 { |
| 307 | return output[0..ascii_string.len]; | 307 | return output[0..ascii_string.len]; |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | test "upperString" { | 310 | test upperString { |
| 311 | var buf: [1024]u8 = undefined; | 311 | var buf: [1024]u8 = undefined; |
| 312 | const result = upperString(&buf, "aBcDeFgHiJkLmNOPqrst0234+π©!"); | 312 | const result = upperString(&buf, "aBcDeFgHiJkLmNOPqrst0234+π©!"); |
| 313 | try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+π©!", result); | 313 | try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+π©!", result); |
| ... | @@ -320,7 +320,7 @@ pub fn allocUpperString(allocator: std.mem.Allocator, ascii_string: []const u8) | ... | @@ -320,7 +320,7 @@ pub fn allocUpperString(allocator: std.mem.Allocator, ascii_string: []const u8) |
| 320 | return upperString(result, ascii_string); | 320 | return upperString(result, ascii_string); |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | test "allocUpperString" { | 323 | test allocUpperString { |
| 324 | const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!"); | 324 | const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+π©!"); |
| 325 | defer std.testing.allocator.free(result); | 325 | defer std.testing.allocator.free(result); |
| 326 | try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+π©!", result); | 326 | try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+π©!", result); |
| ... | @@ -335,7 +335,7 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool { | ... | @@ -335,7 +335,7 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool { |
| 335 | return true; | 335 | return true; |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | test "eqlIgnoreCase" { | 338 | test eqlIgnoreCase { |
| 339 | try std.testing.expect(eqlIgnoreCase("HElπ©Lo!", "helπ©lo!")); | 339 | try std.testing.expect(eqlIgnoreCase("HElπ©Lo!", "helπ©lo!")); |
| 340 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! ")); | 340 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! ")); |
| 341 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!")); | 341 | try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!")); |
| ... | @@ -345,7 +345,7 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { | ... | @@ -345,7 +345,7 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { |
| 345 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[0..needle.len], needle); | 345 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[0..needle.len], needle); |
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | test "startsWithIgnoreCase" { | 348 | test startsWithIgnoreCase { |
| 349 | try std.testing.expect(startsWithIgnoreCase("boB", "Bo")); | 349 | try std.testing.expect(startsWithIgnoreCase("boB", "Bo")); |
| 350 | try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack")); | 350 | try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack")); |
| 351 | } | 351 | } |
| ... | @@ -354,7 +354,7 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { | ... | @@ -354,7 +354,7 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool { |
| 354 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[haystack.len - needle.len ..], needle); | 354 | return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[haystack.len - needle.len ..], needle); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | test "endsWithIgnoreCase" { | 357 | test endsWithIgnoreCase { |
| 358 | try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack")); | 358 | try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack")); |
| 359 | try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); | 359 | try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo")); |
| 360 | } | 360 | } |
| ... | @@ -409,7 +409,7 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz | ... | @@ -409,7 +409,7 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz |
| 409 | } | 409 | } |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | test "indexOfIgnoreCase" { | 412 | test indexOfIgnoreCase { |
| 413 | try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14); | 413 | try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14); |
| 414 | try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null); | 414 | try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null); |
| 415 | try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0); | 415 | try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0); |
lib/std/bit_set.zig+5-5| ... | @@ -1648,7 +1648,7 @@ fn testStaticBitSet(comptime Set: type) !void { | ... | @@ -1648,7 +1648,7 @@ fn testStaticBitSet(comptime Set: type) !void { |
| 1648 | try testPureBitSet(Set); | 1648 | try testPureBitSet(Set); |
| 1649 | } | 1649 | } |
| 1650 | 1650 | ||
| 1651 | test "IntegerBitSet" { | 1651 | test IntegerBitSet { |
| 1652 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 1652 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 1653 | 1653 | ||
| 1654 | try testStaticBitSet(IntegerBitSet(0)); | 1654 | try testStaticBitSet(IntegerBitSet(0)); |
| ... | @@ -1661,7 +1661,7 @@ test "IntegerBitSet" { | ... | @@ -1661,7 +1661,7 @@ test "IntegerBitSet" { |
| 1661 | try testStaticBitSet(IntegerBitSet(127)); | 1661 | try testStaticBitSet(IntegerBitSet(127)); |
| 1662 | } | 1662 | } |
| 1663 | 1663 | ||
| 1664 | test "ArrayBitSet" { | 1664 | test ArrayBitSet { |
| 1665 | inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| { | 1665 | inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| { |
| 1666 | try testStaticBitSet(ArrayBitSet(u8, size)); | 1666 | try testStaticBitSet(ArrayBitSet(u8, size)); |
| 1667 | try testStaticBitSet(ArrayBitSet(u16, size)); | 1667 | try testStaticBitSet(ArrayBitSet(u16, size)); |
| ... | @@ -1671,7 +1671,7 @@ test "ArrayBitSet" { | ... | @@ -1671,7 +1671,7 @@ test "ArrayBitSet" { |
| 1671 | } | 1671 | } |
| 1672 | } | 1672 | } |
| 1673 | 1673 | ||
| 1674 | test "DynamicBitSetUnmanaged" { | 1674 | test DynamicBitSetUnmanaged { |
| 1675 | const allocator = std.testing.allocator; | 1675 | const allocator = std.testing.allocator; |
| 1676 | var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300); | 1676 | var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300); |
| 1677 | try testing.expectEqual(@as(usize, 0), a.count()); | 1677 | try testing.expectEqual(@as(usize, 0), a.count()); |
| ... | @@ -1724,7 +1724,7 @@ test "DynamicBitSetUnmanaged" { | ... | @@ -1724,7 +1724,7 @@ test "DynamicBitSetUnmanaged" { |
| 1724 | } | 1724 | } |
| 1725 | } | 1725 | } |
| 1726 | 1726 | ||
| 1727 | test "DynamicBitSet" { | 1727 | test DynamicBitSet { |
| 1728 | const allocator = std.testing.allocator; | 1728 | const allocator = std.testing.allocator; |
| 1729 | var a = try DynamicBitSet.initEmpty(allocator, 300); | 1729 | var a = try DynamicBitSet.initEmpty(allocator, 300); |
| 1730 | try testing.expectEqual(@as(usize, 0), a.count()); | 1730 | try testing.expectEqual(@as(usize, 0), a.count()); |
| ... | @@ -1765,7 +1765,7 @@ test "DynamicBitSet" { | ... | @@ -1765,7 +1765,7 @@ test "DynamicBitSet" { |
| 1765 | } | 1765 | } |
| 1766 | } | 1766 | } |
| 1767 | 1767 | ||
| 1768 | test "StaticBitSet" { | 1768 | test StaticBitSet { |
| 1769 | try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0)); | 1769 | try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0)); |
| 1770 | try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5)); | 1770 | try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5)); |
| 1771 | try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize))); | 1771 | try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize))); |
lib/std/bounded_array.zig+1-1| ... | @@ -287,7 +287,7 @@ pub fn BoundedArrayAligned( | ... | @@ -287,7 +287,7 @@ pub fn BoundedArrayAligned( |
| 287 | }; | 287 | }; |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | test "BoundedArray" { | 290 | test BoundedArray { |
| 291 | var a = try BoundedArray(u8, 64).init(32); | 291 | var a = try BoundedArray(u8, 64).init(32); |
| 292 | 292 | ||
| 293 | try testing.expectEqual(a.capacity(), 64); | 293 | try testing.expectEqual(a.capacity(), 64); |
lib/std/child_process.zig+3-3| ... | @@ -1231,7 +1231,7 @@ fn windowsCreateProcessSupportsExtension(ext: []const u16) ?CreateProcessSupport | ... | @@ -1231,7 +1231,7 @@ fn windowsCreateProcessSupportsExtension(ext: []const u16) ?CreateProcessSupport |
| 1231 | return null; | 1231 | return null; |
| 1232 | } | 1232 | } |
| 1233 | 1233 | ||
| 1234 | test "windowsCreateProcessSupportsExtension" { | 1234 | test windowsCreateProcessSupportsExtension { |
| 1235 | try std.testing.expectEqual(CreateProcessSupportedExtension.exe, windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e' }).?); | 1235 | try std.testing.expectEqual(CreateProcessSupportedExtension.exe, windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e' }).?); |
| 1236 | try std.testing.expect(windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e', 'c' }) == null); | 1236 | try std.testing.expect(windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e', 'c' }) == null); |
| 1237 | } | 1237 | } |
| ... | @@ -1322,7 +1322,7 @@ pub fn argvToCommandLineWindows( | ... | @@ -1322,7 +1322,7 @@ pub fn argvToCommandLineWindows( |
| 1322 | return try unicode.wtf8ToWtf16LeAllocZ(allocator, buf.items); | 1322 | return try unicode.wtf8ToWtf16LeAllocZ(allocator, buf.items); |
| 1323 | } | 1323 | } |
| 1324 | 1324 | ||
| 1325 | test "argvToCommandLineWindows" { | 1325 | test argvToCommandLineWindows { |
| 1326 | const t = testArgvToCommandLineWindows; | 1326 | const t = testArgvToCommandLineWindows; |
| 1327 | 1327 | ||
| 1328 | try t(&.{ | 1328 | try t(&.{ |
| ... | @@ -1556,7 +1556,7 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ! | ... | @@ -1556,7 +1556,7 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) ! |
| 1556 | return envp_buf; | 1556 | return envp_buf; |
| 1557 | } | 1557 | } |
| 1558 | 1558 | ||
| 1559 | test "createNullDelimitedEnvMap" { | 1559 | test createNullDelimitedEnvMap { |
| 1560 | const testing = std.testing; | 1560 | const testing = std.testing; |
| 1561 | const allocator = testing.allocator; | 1561 | const allocator = testing.allocator; |
| 1562 | var envmap = EnvMap.init(allocator); | 1562 | var envmap = EnvMap.init(allocator); |
lib/std/crypto/utils.zig+3-3| ... | @@ -138,7 +138,7 @@ pub inline fn secureZero(comptime T: type, s: []T) void { | ... | @@ -138,7 +138,7 @@ pub inline fn secureZero(comptime T: type, s: []T) void { |
| 138 | @memset(@as([]volatile T, s), 0); | 138 | @memset(@as([]volatile T, s), 0); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | test "timingSafeEql" { | 141 | test timingSafeEql { |
| 142 | var a: [100]u8 = undefined; | 142 | var a: [100]u8 = undefined; |
| 143 | var b: [100]u8 = undefined; | 143 | var b: [100]u8 = undefined; |
| 144 | random.bytes(a[0..]); | 144 | random.bytes(a[0..]); |
| ... | @@ -162,7 +162,7 @@ test "timingSafeEql (vectors)" { | ... | @@ -162,7 +162,7 @@ test "timingSafeEql (vectors)" { |
| 162 | try testing.expect(timingSafeEql(@Vector(100, u8), v1, v3)); | 162 | try testing.expect(timingSafeEql(@Vector(100, u8), v1, v3)); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | test "timingSafeCompare" { | 165 | test timingSafeCompare { |
| 166 | var a = [_]u8{10} ** 32; | 166 | var a = [_]u8{10} ** 32; |
| 167 | var b = [_]u8{10} ** 32; | 167 | var b = [_]u8{10} ** 32; |
| 168 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq); | 168 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq); |
| ... | @@ -195,7 +195,7 @@ test "timingSafe{Add,Sub}" { | ... | @@ -195,7 +195,7 @@ test "timingSafe{Add,Sub}" { |
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | test "secureZero" { | 198 | test secureZero { |
| 199 | var a = [_]u8{0xfe} ** 8; | 199 | var a = [_]u8{0xfe} ** 8; |
| 200 | var b = [_]u8{0xfe} ** 8; | 200 | var b = [_]u8{0xfe} ** 8; |
| 201 | 201 |
lib/std/debug.zig+2-2| ... | @@ -905,7 +905,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach | ... | @@ -905,7 +905,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach |
| 905 | return null; | 905 | return null; |
| 906 | } | 906 | } |
| 907 | 907 | ||
| 908 | test "machoSearchSymbols" { | 908 | test machoSearchSymbols { |
| 909 | const symbols = [_]MachoSymbol{ | 909 | const symbols = [_]MachoSymbol{ |
| 910 | .{ .addr = 100, .strx = undefined, .size = undefined, .ofile = undefined }, | 910 | .{ .addr = 100, .strx = undefined, .size = undefined, .ofile = undefined }, |
| 911 | .{ .addr = 200, .strx = undefined, .size = undefined, .ofile = undefined }, | 911 | .{ .addr = 200, .strx = undefined, .size = undefined, .ofile = undefined }, |
| ... | @@ -1504,7 +1504,7 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void { | ... | @@ -1504,7 +1504,7 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void { |
| 1504 | } | 1504 | } |
| 1505 | } | 1505 | } |
| 1506 | 1506 | ||
| 1507 | test "printLineFromFileAnyOs" { | 1507 | test printLineFromFileAnyOs { |
| 1508 | var output = std.ArrayList(u8).init(std.testing.allocator); | 1508 | var output = std.ArrayList(u8).init(std.testing.allocator); |
| 1509 | defer output.deinit(); | 1509 | defer output.deinit(); |
| 1510 | const output_stream = output.writer(); | 1510 | const output_stream = output.writer(); |
lib/std/fifo.zig+1-1| ... | @@ -507,7 +507,7 @@ test "LinearFifo(u8, .Dynamic)" { | ... | @@ -507,7 +507,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 507 | } | 507 | } |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | test "LinearFifo" { | 510 | test LinearFifo { |
| 511 | inline for ([_]type{ u1, u8, u16, u64 }) |T| { | 511 | inline for ([_]type{ u1, u8, u16, u64 }) |T| { |
| 512 | inline for ([_]LinearFifoBufferType{ LinearFifoBufferType{ .Static = 32 }, .Slice, .Dynamic }) |bt| { | 512 | inline for ([_]LinearFifoBufferType{ LinearFifoBufferType{ .Static = 32 }, .Slice, .Dynamic }) |bt| { |
| 513 | const FifoType = LinearFifo(T, bt); | 513 | const FifoType = LinearFifo(T, bt); |
lib/std/fmt.zig+9-9| ... | @@ -1303,7 +1303,7 @@ pub fn fmtDuration(ns: u64) Formatter(formatDuration) { | ... | @@ -1303,7 +1303,7 @@ pub fn fmtDuration(ns: u64) Formatter(formatDuration) { |
| 1303 | return .{ .data = data }; | 1303 | return .{ .data = data }; |
| 1304 | } | 1304 | } |
| 1305 | 1305 | ||
| 1306 | test "fmtDuration" { | 1306 | test fmtDuration { |
| 1307 | var buf: [24]u8 = undefined; | 1307 | var buf: [24]u8 = undefined; |
| 1308 | inline for (.{ | 1308 | inline for (.{ |
| 1309 | .{ .s = "0ns", .d = 0 }, | 1309 | .{ .s = "0ns", .d = 0 }, |
| ... | @@ -1367,7 +1367,7 @@ pub fn fmtDurationSigned(ns: i64) Formatter(formatDurationSigned) { | ... | @@ -1367,7 +1367,7 @@ pub fn fmtDurationSigned(ns: i64) Formatter(formatDurationSigned) { |
| 1367 | return .{ .data = ns }; | 1367 | return .{ .data = ns }; |
| 1368 | } | 1368 | } |
| 1369 | 1369 | ||
| 1370 | test "fmtDurationSigned" { | 1370 | test fmtDurationSigned { |
| 1371 | var buf: [24]u8 = undefined; | 1371 | var buf: [24]u8 = undefined; |
| 1372 | inline for (.{ | 1372 | inline for (.{ |
| 1373 | .{ .s = "0ns", .d = 0 }, | 1373 | .{ .s = "0ns", .d = 0 }, |
| ... | @@ -1497,7 +1497,7 @@ pub fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T { | ... | @@ -1497,7 +1497,7 @@ pub fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T { |
| 1497 | return parseWithSign(T, buf, base, .pos); | 1497 | return parseWithSign(T, buf, base, .pos); |
| 1498 | } | 1498 | } |
| 1499 | 1499 | ||
| 1500 | test "parseInt" { | 1500 | test parseInt { |
| 1501 | try std.testing.expect((try parseInt(i32, "-10", 10)) == -10); | 1501 | try std.testing.expect((try parseInt(i32, "-10", 10)) == -10); |
| 1502 | try std.testing.expect((try parseInt(i32, "+10", 10)) == 10); | 1502 | try std.testing.expect((try parseInt(i32, "+10", 10)) == 10); |
| 1503 | try std.testing.expect((try parseInt(u32, "+10", 10)) == 10); | 1503 | try std.testing.expect((try parseInt(u32, "+10", 10)) == 10); |
| ... | @@ -1639,7 +1639,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError! | ... | @@ -1639,7 +1639,7 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError! |
| 1639 | return parseWithSign(T, buf, base, .pos); | 1639 | return parseWithSign(T, buf, base, .pos); |
| 1640 | } | 1640 | } |
| 1641 | 1641 | ||
| 1642 | test "parseUnsigned" { | 1642 | test parseUnsigned { |
| 1643 | try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124); | 1643 | try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124); |
| 1644 | try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535); | 1644 | try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535); |
| 1645 | try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535); | 1645 | try std.testing.expect((try parseUnsigned(u16, "65_535", 10)) == 65535); |
| ... | @@ -1713,7 +1713,7 @@ pub fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize { | ... | @@ -1713,7 +1713,7 @@ pub fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize { |
| 1713 | return math.mul(usize, number, multiplier); | 1713 | return math.mul(usize, number, multiplier); |
| 1714 | } | 1714 | } |
| 1715 | 1715 | ||
| 1716 | test "parseIntSizeSuffix" { | 1716 | test parseIntSizeSuffix { |
| 1717 | try std.testing.expect(try parseIntSizeSuffix("2", 10) == 2); | 1717 | try std.testing.expect(try parseIntSizeSuffix("2", 10) == 2); |
| 1718 | try std.testing.expect(try parseIntSizeSuffix("2B", 10) == 2); | 1718 | try std.testing.expect(try parseIntSizeSuffix("2B", 10) == 2); |
| 1719 | try std.testing.expect(try parseIntSizeSuffix("2kB", 10) == 2000); | 1719 | try std.testing.expect(try parseIntSizeSuffix("2kB", 10) == 2000); |
| ... | @@ -1796,7 +1796,7 @@ pub fn allocPrintZ(allocator: mem.Allocator, comptime fmt: []const u8, args: any | ... | @@ -1796,7 +1796,7 @@ pub fn allocPrintZ(allocator: mem.Allocator, comptime fmt: []const u8, args: any |
| 1796 | return result[0 .. result.len - 1 :0]; | 1796 | return result[0 .. result.len - 1 :0]; |
| 1797 | } | 1797 | } |
| 1798 | 1798 | ||
| 1799 | test "bufPrintInt" { | 1799 | test bufPrintIntToSlice { |
| 1800 | var buffer: [100]u8 = undefined; | 1800 | var buffer: [100]u8 = undefined; |
| 1801 | const buf = buffer[0..]; | 1801 | const buf = buffer[0..]; |
| 1802 | 1802 | ||
| ... | @@ -1830,7 +1830,7 @@ pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [cou | ... | @@ -1830,7 +1830,7 @@ pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [cou |
| 1830 | } | 1830 | } |
| 1831 | } | 1831 | } |
| 1832 | 1832 | ||
| 1833 | test "comptimePrint" { | 1833 | test comptimePrint { |
| 1834 | @setEvalBranchQuota(2000); | 1834 | @setEvalBranchQuota(2000); |
| 1835 | try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptimePrint("{}", .{100}))); | 1835 | try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptimePrint("{}", .{100}))); |
| 1836 | try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); | 1836 | try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100})); |
| ... | @@ -2445,14 +2445,14 @@ pub fn hexToBytes(out: []u8, input: []const u8) ![]u8 { | ... | @@ -2445,14 +2445,14 @@ pub fn hexToBytes(out: []u8, input: []const u8) ![]u8 { |
| 2445 | return out[0 .. in_i / 2]; | 2445 | return out[0 .. in_i / 2]; |
| 2446 | } | 2446 | } |
| 2447 | 2447 | ||
| 2448 | test "bytesToHex" { | 2448 | test bytesToHex { |
| 2449 | const input = "input slice"; | 2449 | const input = "input slice"; |
| 2450 | const encoded = bytesToHex(input, .lower); | 2450 | const encoded = bytesToHex(input, .lower); |
| 2451 | var decoded: [input.len]u8 = undefined; | 2451 | var decoded: [input.len]u8 = undefined; |
| 2452 | try std.testing.expectEqualSlices(u8, input, try hexToBytes(&decoded, &encoded)); | 2452 | try std.testing.expectEqualSlices(u8, input, try hexToBytes(&decoded, &encoded)); |
| 2453 | } | 2453 | } |
| 2454 | 2454 | ||
| 2455 | test "hexToBytes" { | 2455 | test hexToBytes { |
| 2456 | var buf: [32]u8 = undefined; | 2456 | var buf: [32]u8 = undefined; |
| 2457 | try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))}); | 2457 | try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))}); |
| 2458 | try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))}); | 2458 | try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))}); |
lib/std/fs/get_app_data_dir.zig+1-1| ... | @@ -61,7 +61,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi | ... | @@ -61,7 +61,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi |
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | test "getAppDataDir" { | 64 | test getAppDataDir { |
| 65 | if (native_os == .wasi) return error.SkipZigTest; | 65 | if (native_os == .wasi) return error.SkipZigTest; |
| 66 | 66 | ||
| 67 | // We can't actually validate the result | 67 | // We can't actually validate the result |
lib/std/fs/path.zig+10-10| ... | @@ -180,7 +180,7 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo | ... | @@ -180,7 +180,7 @@ fn testJoinMaybeZPosix(paths: []const []const u8, expected: []const u8, zero: bo |
| 180 | try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual); | 180 | try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | test "join" { | 183 | test join { |
| 184 | { | 184 | { |
| 185 | const actual: []u8 = try join(testing.allocator, &[_][]const u8{}); | 185 | const actual: []u8 = try join(testing.allocator, &[_][]const u8{}); |
| 186 | defer testing.allocator.free(actual); | 186 | defer testing.allocator.free(actual); |
| ... | @@ -303,7 +303,7 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { | ... | @@ -303,7 +303,7 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { |
| 303 | return isAbsolutePosix(mem.sliceTo(path_c, 0)); | 303 | return isAbsolutePosix(mem.sliceTo(path_c, 0)); |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | test "isAbsoluteWindows" { | 306 | test isAbsoluteWindows { |
| 307 | try testIsAbsoluteWindows("", false); | 307 | try testIsAbsoluteWindows("", false); |
| 308 | try testIsAbsoluteWindows("/", true); | 308 | try testIsAbsoluteWindows("/", true); |
| 309 | try testIsAbsoluteWindows("//", true); | 309 | try testIsAbsoluteWindows("//", true); |
| ... | @@ -326,7 +326,7 @@ test "isAbsoluteWindows" { | ... | @@ -326,7 +326,7 @@ test "isAbsoluteWindows" { |
| 326 | try testIsAbsoluteWindows("/usr/local", true); | 326 | try testIsAbsoluteWindows("/usr/local", true); |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | test "isAbsolutePosix" { | 329 | test isAbsolutePosix { |
| 330 | try testIsAbsolutePosix("", false); | 330 | try testIsAbsolutePosix("", false); |
| 331 | try testIsAbsolutePosix("/home/foo", true); | 331 | try testIsAbsolutePosix("/home/foo", true); |
| 332 | try testIsAbsolutePosix("/home/foo/..", true); | 332 | try testIsAbsolutePosix("/home/foo/..", true); |
| ... | @@ -400,7 +400,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { | ... | @@ -400,7 +400,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 400 | return relative_path; | 400 | return relative_path; |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | test "windowsParsePath" { | 403 | test windowsParsePath { |
| 404 | { | 404 | { |
| 405 | const parsed = windowsParsePath("//a/b"); | 405 | const parsed = windowsParsePath("//a/b"); |
| 406 | try testing.expect(parsed.is_abs); | 406 | try testing.expect(parsed.is_abs); |
| ... | @@ -884,7 +884,7 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 { | ... | @@ -884,7 +884,7 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 { |
| 884 | return path[0..end_index]; | 884 | return path[0..end_index]; |
| 885 | } | 885 | } |
| 886 | 886 | ||
| 887 | test "dirnamePosix" { | 887 | test dirnamePosix { |
| 888 | try testDirnamePosix("/a/b/c", "/a/b"); | 888 | try testDirnamePosix("/a/b/c", "/a/b"); |
| 889 | try testDirnamePosix("/a/b/c///", "/a/b"); | 889 | try testDirnamePosix("/a/b/c///", "/a/b"); |
| 890 | try testDirnamePosix("/a", "/"); | 890 | try testDirnamePosix("/a", "/"); |
| ... | @@ -898,7 +898,7 @@ test "dirnamePosix" { | ... | @@ -898,7 +898,7 @@ test "dirnamePosix" { |
| 898 | try testDirnamePosix("a//", null); | 898 | try testDirnamePosix("a//", null); |
| 899 | } | 899 | } |
| 900 | 900 | ||
| 901 | test "dirnameWindows" { | 901 | test dirnameWindows { |
| 902 | try testDirnameWindows("c:\\", null); | 902 | try testDirnameWindows("c:\\", null); |
| 903 | try testDirnameWindows("c:\\foo", "c:\\"); | 903 | try testDirnameWindows("c:\\foo", "c:\\"); |
| 904 | try testDirnameWindows("c:\\foo\\", "c:\\"); | 904 | try testDirnameWindows("c:\\foo\\", "c:\\"); |
| ... | @@ -1011,7 +1011,7 @@ pub fn basenameWindows(path: []const u8) []const u8 { | ... | @@ -1011,7 +1011,7 @@ pub fn basenameWindows(path: []const u8) []const u8 { |
| 1011 | return path[start_index + 1 .. end_index]; | 1011 | return path[start_index + 1 .. end_index]; |
| 1012 | } | 1012 | } |
| 1013 | 1013 | ||
| 1014 | test "basename" { | 1014 | test basename { |
| 1015 | try testBasename("", ""); | 1015 | try testBasename("", ""); |
| 1016 | try testBasename("/", ""); | 1016 | try testBasename("/", ""); |
| 1017 | try testBasename("/dir/basename.ext", "basename.ext"); | 1017 | try testBasename("/dir/basename.ext", "basename.ext"); |
| ... | @@ -1186,7 +1186,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![] | ... | @@ -1186,7 +1186,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![] |
| 1186 | return [_]u8{}; | 1186 | return [_]u8{}; |
| 1187 | } | 1187 | } |
| 1188 | 1188 | ||
| 1189 | test "relative" { | 1189 | test relative { |
| 1190 | try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games"); | 1190 | try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games"); |
| 1191 | try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", ".."); | 1191 | try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", ".."); |
| 1192 | try testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc"); | 1192 | try testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc"); |
| ... | @@ -1271,7 +1271,7 @@ fn testExtension(path: []const u8, expected: []const u8) !void { | ... | @@ -1271,7 +1271,7 @@ fn testExtension(path: []const u8, expected: []const u8) !void { |
| 1271 | try testing.expectEqualStrings(expected, extension(path)); | 1271 | try testing.expectEqualStrings(expected, extension(path)); |
| 1272 | } | 1272 | } |
| 1273 | 1273 | ||
| 1274 | test "extension" { | 1274 | test extension { |
| 1275 | try testExtension("", ""); | 1275 | try testExtension("", ""); |
| 1276 | try testExtension(".", ""); | 1276 | try testExtension(".", ""); |
| 1277 | try testExtension("a.", "."); | 1277 | try testExtension("a.", "."); |
| ... | @@ -1328,7 +1328,7 @@ fn testStem(path: []const u8, expected: []const u8) !void { | ... | @@ -1328,7 +1328,7 @@ fn testStem(path: []const u8, expected: []const u8) !void { |
| 1328 | try testing.expectEqualStrings(expected, stem(path)); | 1328 | try testing.expectEqualStrings(expected, stem(path)); |
| 1329 | } | 1329 | } |
| 1330 | 1330 | ||
| 1331 | test "stem" { | 1331 | test stem { |
| 1332 | try testStem("hello/world/lib.tar.gz", "lib.tar"); | 1332 | try testStem("hello/world/lib.tar.gz", "lib.tar"); |
| 1333 | try testStem("hello/world/lib.tar", "lib"); | 1333 | try testStem("hello/world/lib.tar", "lib"); |
| 1334 | try testStem("hello/world/lib", "lib"); | 1334 | try testStem("hello/world/lib", "lib"); |
lib/std/io.zig+1-1| ... | @@ -421,7 +421,7 @@ fn dummyWrite(context: void, data: []const u8) error{}!usize { | ... | @@ -421,7 +421,7 @@ fn dummyWrite(context: void, data: []const u8) error{}!usize { |
| 421 | return data.len; | 421 | return data.len; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | test "null_writer" { | 424 | test null_writer { |
| 425 | null_writer.writeAll("yay" ** 10) catch |err| switch (err) {}; | 425 | null_writer.writeAll("yay" ** 10) catch |err| switch (err) {}; |
| 426 | } | 426 | } |
| 427 | 427 |
lib/std/math.zig+90-70| ... | @@ -167,28 +167,51 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool { | ... | @@ -167,28 +167,51 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool { |
| 167 | return @abs(x - y) <= @max(@abs(x), @abs(y)) * tolerance; | 167 | return @abs(x - y) <= @max(@abs(x), @abs(y)) * tolerance; |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | test "approxEqAbs and approxEqRel" { | 170 | test approxEqAbs { |
| 171 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { | 171 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
| 172 | const eps_value = comptime floatEps(T); | 172 | const eps_value = comptime floatEps(T); |
| 173 | const sqrt_eps_value = comptime sqrt(eps_value); | ||
| 174 | const nan_value = comptime nan(T); | ||
| 175 | const inf_value = comptime inf(T); | ||
| 176 | const min_value = comptime floatMin(T); | 173 | const min_value = comptime floatMin(T); |
| 177 | 174 | ||
| 178 | try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value)); | 175 | try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value)); |
| 179 | try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value)); | 176 | try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value)); |
| 180 | try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value)); | 177 | try testing.expect(approxEqAbs(T, 0.0, -0.0, eps_value)); |
| 181 | try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value)); | ||
| 182 | try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value)); | ||
| 183 | try testing.expect(!approxEqAbs(T, 1.0 + 2 * eps_value, 1.0, eps_value)); | 178 | try testing.expect(!approxEqAbs(T, 1.0 + 2 * eps_value, 1.0, eps_value)); |
| 184 | try testing.expect(approxEqAbs(T, 1.0 + 1 * eps_value, 1.0, eps_value)); | 179 | try testing.expect(approxEqAbs(T, 1.0 + 1 * eps_value, 1.0, eps_value)); |
| 180 | try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2)); | ||
| 181 | try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2)); | ||
| 182 | } | ||
| 183 | |||
| 184 | comptime { | ||
| 185 | // `comptime_float` is guaranteed to have the same precision and operations of | ||
| 186 | // the largest other floating point type, which is f128 but it doesn't have a | ||
| 187 | // defined layout so we can't rely on `@bitCast` to construct the smallest | ||
| 188 | // possible epsilon value like we do in the tests above. In the same vein, we | ||
| 189 | // also can't represent a max/min, `NaN` or `Inf` values. | ||
| 190 | const eps_value = 1e-4; | ||
| 191 | |||
| 192 | try testing.expect(approxEqAbs(comptime_float, 0.0, 0.0, eps_value)); | ||
| 193 | try testing.expect(approxEqAbs(comptime_float, -0.0, -0.0, eps_value)); | ||
| 194 | try testing.expect(approxEqAbs(comptime_float, 0.0, -0.0, eps_value)); | ||
| 195 | try testing.expect(!approxEqAbs(comptime_float, 1.0 + 2 * eps_value, 1.0, eps_value)); | ||
| 196 | try testing.expect(approxEqAbs(comptime_float, 1.0 + 1 * eps_value, 1.0, eps_value)); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | test approxEqRel { | ||
| 201 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { | ||
| 202 | const eps_value = comptime floatEps(T); | ||
| 203 | const sqrt_eps_value = comptime sqrt(eps_value); | ||
| 204 | const nan_value = comptime nan(T); | ||
| 205 | const inf_value = comptime inf(T); | ||
| 206 | const min_value = comptime floatMin(T); | ||
| 207 | |||
| 208 | try testing.expect(approxEqRel(T, 1.0, 1.0, sqrt_eps_value)); | ||
| 209 | try testing.expect(!approxEqRel(T, 1.0, 0.0, sqrt_eps_value)); | ||
| 185 | try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value)); | 210 | try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value)); |
| 186 | try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value)); | 211 | try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value)); |
| 187 | try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value)); | 212 | try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value)); |
| 188 | try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value)); | 213 | try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value)); |
| 189 | try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value)); | 214 | try testing.expect(approxEqRel(T, -min_value, -min_value, sqrt_eps_value)); |
| 190 | try testing.expect(approxEqAbs(T, min_value, 0.0, eps_value * 2)); | ||
| 191 | try testing.expect(approxEqAbs(T, -min_value, 0.0, eps_value * 2)); | ||
| 192 | } | 215 | } |
| 193 | 216 | ||
| 194 | comptime { | 217 | comptime { |
| ... | @@ -200,13 +223,8 @@ test "approxEqAbs and approxEqRel" { | ... | @@ -200,13 +223,8 @@ test "approxEqAbs and approxEqRel" { |
| 200 | const eps_value = 1e-4; | 223 | const eps_value = 1e-4; |
| 201 | const sqrt_eps_value = sqrt(eps_value); | 224 | const sqrt_eps_value = sqrt(eps_value); |
| 202 | 225 | ||
| 203 | try testing.expect(approxEqAbs(comptime_float, 0.0, 0.0, eps_value)); | ||
| 204 | try testing.expect(approxEqAbs(comptime_float, -0.0, -0.0, eps_value)); | ||
| 205 | try testing.expect(approxEqAbs(comptime_float, 0.0, -0.0, eps_value)); | ||
| 206 | try testing.expect(approxEqRel(comptime_float, 1.0, 1.0, sqrt_eps_value)); | 226 | try testing.expect(approxEqRel(comptime_float, 1.0, 1.0, sqrt_eps_value)); |
| 207 | try testing.expect(!approxEqRel(comptime_float, 1.0, 0.0, sqrt_eps_value)); | 227 | try testing.expect(!approxEqRel(comptime_float, 1.0, 0.0, sqrt_eps_value)); |
| 208 | try testing.expect(!approxEqAbs(comptime_float, 1.0 + 2 * eps_value, 1.0, eps_value)); | ||
| 209 | try testing.expect(approxEqAbs(comptime_float, 1.0 + 1 * eps_value, 1.0, eps_value)); | ||
| 210 | } | 228 | } |
| 211 | } | 229 | } |
| 212 | 230 | ||
| ... | @@ -310,7 +328,7 @@ pub fn radiansToDegrees(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime | ... | @@ -310,7 +328,7 @@ pub fn radiansToDegrees(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime |
| 310 | @compileError("Input must be float or a comptime number, or a vector of floats."); | 328 | @compileError("Input must be float or a comptime number, or a vector of floats."); |
| 311 | } | 329 | } |
| 312 | 330 | ||
| 313 | test "radiansToDegrees" { | 331 | test radiansToDegrees { |
| 314 | const zero: f32 = 0; | 332 | const zero: f32 = 0; |
| 315 | const half_pi: f32 = pi / 2.0; | 333 | const half_pi: f32 = pi / 2.0; |
| 316 | const neg_quart_pi: f32 = -pi / 4.0; | 334 | const neg_quart_pi: f32 = -pi / 4.0; |
| ... | @@ -345,7 +363,7 @@ pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime | ... | @@ -345,7 +363,7 @@ pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime |
| 345 | @compileError("Input must be float or a comptime number, or a vector of floats."); | 363 | @compileError("Input must be float or a comptime number, or a vector of floats."); |
| 346 | } | 364 | } |
| 347 | 365 | ||
| 348 | test "degreesToRadians" { | 366 | test degreesToRadians { |
| 349 | const ninety: f32 = 90; | 367 | const ninety: f32 = 90; |
| 350 | const neg_two_seventy: f32 = -270; | 368 | const neg_two_seventy: f32 = -270; |
| 351 | const three_sixty: f32 = 360; | 369 | const three_sixty: f32 = 360; |
| ... | @@ -506,7 +524,7 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) { | ... | @@ -506,7 +524,7 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) { |
| 506 | }, | 524 | }, |
| 507 | } | 525 | } |
| 508 | } | 526 | } |
| 509 | test "wrap" { | 527 | test wrap { |
| 510 | // Within range | 528 | // Within range |
| 511 | try testing.expect(wrap(@as(i32, -75), @as(i32, 180)) == -75); | 529 | try testing.expect(wrap(@as(i32, -75), @as(i32, 180)) == -75); |
| 512 | try testing.expect(wrap(@as(i32, -75), @as(i32, -180)) == -75); | 530 | try testing.expect(wrap(@as(i32, -75), @as(i32, -180)) == -75); |
| ... | @@ -543,8 +561,7 @@ test "wrap" { | ... | @@ -543,8 +561,7 @@ test "wrap" { |
| 543 | var i: i32 = 1; | 561 | var i: i32 = 1; |
| 544 | _ = &i; | 562 | _ = &i; |
| 545 | try testing.expect(wrap(i, 10) == 1); | 563 | try testing.expect(wrap(i, 10) == 1); |
| 546 | } | 564 | |
| 547 | test wrap { | ||
| 548 | const limit: i32 = 180; | 565 | const limit: i32 = 180; |
| 549 | // Within range | 566 | // Within range |
| 550 | try testing.expect(wrap(@as(i32, -75), limit) == -75); | 567 | try testing.expect(wrap(@as(i32, -75), limit) == -75); |
| ... | @@ -569,7 +586,7 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u | ... | @@ -569,7 +586,7 @@ pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, u |
| 569 | assert(lower <= upper); | 586 | assert(lower <= upper); |
| 570 | return @max(lower, @min(val, upper)); | 587 | return @max(lower, @min(val, upper)); |
| 571 | } | 588 | } |
| 572 | test "clamp" { | 589 | test clamp { |
| 573 | // Within range | 590 | // Within range |
| 574 | try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1); | 591 | try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1); |
| 575 | // Below | 592 | // Below |
| ... | @@ -650,7 +667,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T { | ... | @@ -650,7 +667,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T { |
| 650 | return a << casted_shift_amt; | 667 | return a << casted_shift_amt; |
| 651 | } | 668 | } |
| 652 | 669 | ||
| 653 | test "shl" { | 670 | test shl { |
| 654 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { | 671 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 655 | // https://github.com/ziglang/zig/issues/12012 | 672 | // https://github.com/ziglang/zig/issues/12012 |
| 656 | return error.SkipZigTest; | 673 | return error.SkipZigTest; |
| ... | @@ -695,7 +712,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T { | ... | @@ -695,7 +712,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T { |
| 695 | return a >> casted_shift_amt; | 712 | return a >> casted_shift_amt; |
| 696 | } | 713 | } |
| 697 | 714 | ||
| 698 | test "shr" { | 715 | test shr { |
| 699 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { | 716 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 700 | // https://github.com/ziglang/zig/issues/12012 | 717 | // https://github.com/ziglang/zig/issues/12012 |
| 701 | return error.SkipZigTest; | 718 | return error.SkipZigTest; |
| ... | @@ -741,7 +758,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T { | ... | @@ -741,7 +758,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T { |
| 741 | } | 758 | } |
| 742 | } | 759 | } |
| 743 | 760 | ||
| 744 | test "rotr" { | 761 | test rotr { |
| 745 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { | 762 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 746 | // https://github.com/ziglang/zig/issues/12012 | 763 | // https://github.com/ziglang/zig/issues/12012 |
| 747 | return error.SkipZigTest; | 764 | return error.SkipZigTest; |
| ... | @@ -787,7 +804,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T { | ... | @@ -787,7 +804,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T { |
| 787 | } | 804 | } |
| 788 | } | 805 | } |
| 789 | 806 | ||
| 790 | test "rotl" { | 807 | test rotl { |
| 791 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { | 808 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 792 | // https://github.com/ziglang/zig/issues/12012 | 809 | // https://github.com/ziglang/zig/issues/12012 |
| 793 | return error.SkipZigTest; | 810 | return error.SkipZigTest; |
| ... | @@ -850,7 +867,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t | ... | @@ -850,7 +867,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t |
| 850 | return std.meta.Int(signedness, magnitude_bits); | 867 | return std.meta.Int(signedness, magnitude_bits); |
| 851 | } | 868 | } |
| 852 | 869 | ||
| 853 | test "IntFittingRange" { | 870 | test IntFittingRange { |
| 854 | try testing.expect(IntFittingRange(0, 0) == u0); | 871 | try testing.expect(IntFittingRange(0, 0) == u0); |
| 855 | try testing.expect(IntFittingRange(0, 1) == u1); | 872 | try testing.expect(IntFittingRange(0, 1) == u1); |
| 856 | try testing.expect(IntFittingRange(0, 2) == u2); | 873 | try testing.expect(IntFittingRange(0, 2) == u2); |
| ... | @@ -918,7 +935,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -918,7 +935,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { |
| 918 | return @divTrunc(numerator, denominator); | 935 | return @divTrunc(numerator, denominator); |
| 919 | } | 936 | } |
| 920 | 937 | ||
| 921 | test "divTrunc" { | 938 | test divTrunc { |
| 922 | try testDivTrunc(); | 939 | try testDivTrunc(); |
| 923 | try comptime testDivTrunc(); | 940 | try comptime testDivTrunc(); |
| 924 | } | 941 | } |
| ... | @@ -942,7 +959,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -942,7 +959,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T { |
| 942 | return @divFloor(numerator, denominator); | 959 | return @divFloor(numerator, denominator); |
| 943 | } | 960 | } |
| 944 | 961 | ||
| 945 | test "divFloor" { | 962 | test divFloor { |
| 946 | try testDivFloor(); | 963 | try testDivFloor(); |
| 947 | try comptime testDivFloor(); | 964 | try comptime testDivFloor(); |
| 948 | } | 965 | } |
| ... | @@ -979,7 +996,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -979,7 +996,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T { |
| 979 | } | 996 | } |
| 980 | } | 997 | } |
| 981 | 998 | ||
| 982 | test "divCeil" { | 999 | test divCeil { |
| 983 | try testDivCeil(); | 1000 | try testDivCeil(); |
| 984 | try comptime testDivCeil(); | 1001 | try comptime testDivCeil(); |
| 985 | } | 1002 | } |
| ... | @@ -1023,7 +1040,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -1023,7 +1040,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T { |
| 1023 | return result; | 1040 | return result; |
| 1024 | } | 1041 | } |
| 1025 | 1042 | ||
| 1026 | test "divExact" { | 1043 | test divExact { |
| 1027 | try testDivExact(); | 1044 | try testDivExact(); |
| 1028 | try comptime testDivExact(); | 1045 | try comptime testDivExact(); |
| 1029 | } | 1046 | } |
| ... | @@ -1049,7 +1066,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -1049,7 +1066,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T { |
| 1049 | return @mod(numerator, denominator); | 1066 | return @mod(numerator, denominator); |
| 1050 | } | 1067 | } |
| 1051 | 1068 | ||
| 1052 | test "mod" { | 1069 | test mod { |
| 1053 | try testMod(); | 1070 | try testMod(); |
| 1054 | try comptime testMod(); | 1071 | try comptime testMod(); |
| 1055 | } | 1072 | } |
| ... | @@ -1075,7 +1092,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T { | ... | @@ -1075,7 +1092,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T { |
| 1075 | return @rem(numerator, denominator); | 1092 | return @rem(numerator, denominator); |
| 1076 | } | 1093 | } |
| 1077 | 1094 | ||
| 1078 | test "rem" { | 1095 | test rem { |
| 1079 | try testRem(); | 1096 | try testRem(); |
| 1080 | try comptime testRem(); | 1097 | try comptime testRem(); |
| 1081 | } | 1098 | } |
| ... | @@ -1104,7 +1121,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) { | ... | @@ -1104,7 +1121,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) { |
| 1104 | return -@as(int, @intCast(x)); | 1121 | return -@as(int, @intCast(x)); |
| 1105 | } | 1122 | } |
| 1106 | 1123 | ||
| 1107 | test "negateCast" { | 1124 | test negateCast { |
| 1108 | try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); | 1125 | try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); |
| 1109 | try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); | 1126 | try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); |
| 1110 | 1127 | ||
| ... | @@ -1129,7 +1146,7 @@ pub fn cast(comptime T: type, x: anytype) ?T { | ... | @@ -1129,7 +1146,7 @@ pub fn cast(comptime T: type, x: anytype) ?T { |
| 1129 | } | 1146 | } |
| 1130 | } | 1147 | } |
| 1131 | 1148 | ||
| 1132 | test "cast" { | 1149 | test cast { |
| 1133 | try testing.expect(cast(u8, 300) == null); | 1150 | try testing.expect(cast(u8, 300) == null); |
| 1134 | try testing.expect(cast(u8, @as(u32, 300)) == null); | 1151 | try testing.expect(cast(u8, @as(u32, 300)) == null); |
| 1135 | try testing.expect(cast(i8, -200) == null); | 1152 | try testing.expect(cast(i8, -200) == null); |
| ... | @@ -1188,7 +1205,7 @@ pub fn ByteAlignedInt(comptime T: type) type { | ... | @@ -1188,7 +1205,7 @@ pub fn ByteAlignedInt(comptime T: type) type { |
| 1188 | return extended_type; | 1205 | return extended_type; |
| 1189 | } | 1206 | } |
| 1190 | 1207 | ||
| 1191 | test "ByteAlignedInt" { | 1208 | test ByteAlignedInt { |
| 1192 | try testing.expect(ByteAlignedInt(u0) == u0); | 1209 | try testing.expect(ByteAlignedInt(u0) == u0); |
| 1193 | try testing.expect(ByteAlignedInt(i0) == i0); | 1210 | try testing.expect(ByteAlignedInt(i0) == i0); |
| 1194 | try testing.expect(ByteAlignedInt(u3) == u8); | 1211 | try testing.expect(ByteAlignedInt(u3) == u8); |
| ... | @@ -1226,7 +1243,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T { | ... | @@ -1226,7 +1243,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T { |
| 1226 | return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value))); | 1243 | return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value))); |
| 1227 | } | 1244 | } |
| 1228 | 1245 | ||
| 1229 | test "floorPowerOfTwo" { | 1246 | test floorPowerOfTwo { |
| 1230 | try testFloorPowerOfTwo(); | 1247 | try testFloorPowerOfTwo(); |
| 1231 | try comptime testFloorPowerOfTwo(); | 1248 | try comptime testFloorPowerOfTwo(); |
| 1232 | } | 1249 | } |
| ... | @@ -1288,7 +1305,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T { | ... | @@ -1288,7 +1305,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T { |
| 1288 | return ceilPowerOfTwo(T, value) catch unreachable; | 1305 | return ceilPowerOfTwo(T, value) catch unreachable; |
| 1289 | } | 1306 | } |
| 1290 | 1307 | ||
| 1291 | test "ceilPowerOfTwoPromote" { | 1308 | test ceilPowerOfTwoPromote { |
| 1292 | try testCeilPowerOfTwoPromote(); | 1309 | try testCeilPowerOfTwoPromote(); |
| 1293 | try comptime testCeilPowerOfTwoPromote(); | 1310 | try comptime testCeilPowerOfTwoPromote(); |
| 1294 | } | 1311 | } |
| ... | @@ -1305,7 +1322,7 @@ fn testCeilPowerOfTwoPromote() !void { | ... | @@ -1305,7 +1322,7 @@ fn testCeilPowerOfTwoPromote() !void { |
| 1305 | try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); | 1322 | try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9)); |
| 1306 | } | 1323 | } |
| 1307 | 1324 | ||
| 1308 | test "ceilPowerOfTwo" { | 1325 | test ceilPowerOfTwo { |
| 1309 | try testCeilPowerOfTwo(); | 1326 | try testCeilPowerOfTwo(); |
| 1310 | try comptime testCeilPowerOfTwo(); | 1327 | try comptime testCeilPowerOfTwo(); |
| 1311 | } | 1328 | } |
| ... | @@ -1398,7 +1415,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T { | ... | @@ -1398,7 +1415,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T { |
| 1398 | } | 1415 | } |
| 1399 | } | 1416 | } |
| 1400 | 1417 | ||
| 1401 | test "lossyCast" { | 1418 | test lossyCast { |
| 1402 | try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767)); | 1419 | try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767)); |
| 1403 | try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0)); | 1420 | try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0)); |
| 1404 | try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200)); | 1421 | try testing.expect(lossyCast(i9, @as(u32, 200)) == @as(i9, 200)); |
| ... | @@ -1417,7 +1434,7 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) { | ... | @@ -1417,7 +1434,7 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) { |
| 1417 | return @mulAdd(Type, b - a, t, a); | 1434 | return @mulAdd(Type, b - a, t, a); |
| 1418 | } | 1435 | } |
| 1419 | 1436 | ||
| 1420 | test "lerp" { | 1437 | test lerp { |
| 1421 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884 | 1438 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884 |
| 1422 | if (builtin.zig_backend == .stage2_x86_64 and | 1439 | if (builtin.zig_backend == .stage2_x86_64 and |
| 1423 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest; | 1440 | !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest; |
| ... | @@ -1483,7 +1500,7 @@ pub fn minInt(comptime T: type) comptime_int { | ... | @@ -1483,7 +1500,7 @@ pub fn minInt(comptime T: type) comptime_int { |
| 1483 | return -(1 << (bit_count - 1)); | 1500 | return -(1 << (bit_count - 1)); |
| 1484 | } | 1501 | } |
| 1485 | 1502 | ||
| 1486 | test "minInt and maxInt" { | 1503 | test maxInt { |
| 1487 | try testing.expect(maxInt(u0) == 0); | 1504 | try testing.expect(maxInt(u0) == 0); |
| 1488 | try testing.expect(maxInt(u1) == 1); | 1505 | try testing.expect(maxInt(u1) == 1); |
| 1489 | try testing.expect(maxInt(u8) == 255); | 1506 | try testing.expect(maxInt(u8) == 255); |
| ... | @@ -1500,7 +1517,9 @@ test "minInt and maxInt" { | ... | @@ -1500,7 +1517,9 @@ test "minInt and maxInt" { |
| 1500 | try testing.expect(maxInt(i63) == 4611686018427387903); | 1517 | try testing.expect(maxInt(i63) == 4611686018427387903); |
| 1501 | try testing.expect(maxInt(i64) == 9223372036854775807); | 1518 | try testing.expect(maxInt(i64) == 9223372036854775807); |
| 1502 | try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727); | 1519 | try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727); |
| 1520 | } | ||
| 1503 | 1521 | ||
| 1522 | test minInt { | ||
| 1504 | try testing.expect(minInt(u0) == 0); | 1523 | try testing.expect(minInt(u0) == 0); |
| 1505 | try testing.expect(minInt(u1) == 0); | 1524 | try testing.expect(minInt(u1) == 0); |
| 1506 | try testing.expect(minInt(u8) == 0); | 1525 | try testing.expect(minInt(u8) == 0); |
| ... | @@ -1538,7 +1557,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int( | ... | @@ -1538,7 +1557,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int( |
| 1538 | return @as(ResultInt, a) * @as(ResultInt, b); | 1557 | return @as(ResultInt, a) * @as(ResultInt, b); |
| 1539 | } | 1558 | } |
| 1540 | 1559 | ||
| 1541 | test "mulWide" { | 1560 | test mulWide { |
| 1542 | try testing.expect(mulWide(u8, 5, 5) == 25); | 1561 | try testing.expect(mulWide(u8, 5, 5) == 25); |
| 1543 | try testing.expect(mulWide(i8, 5, -5) == -25); | 1562 | try testing.expect(mulWide(i8, 5, -5) == -25); |
| 1544 | try testing.expect(mulWide(u8, 100, 100) == 10000); | 1563 | try testing.expect(mulWide(u8, 100, 100) == 10000); |
| ... | @@ -1563,6 +1582,12 @@ pub const Order = enum { | ... | @@ -1563,6 +1582,12 @@ pub const Order = enum { |
| 1563 | }; | 1582 | }; |
| 1564 | } | 1583 | } |
| 1565 | 1584 | ||
| 1585 | test invert { | ||
| 1586 | try testing.expect(Order.invert(order(0, 0)) == .eq); | ||
| 1587 | try testing.expect(Order.invert(order(1, 0)) == .lt); | ||
| 1588 | try testing.expect(Order.invert(order(-1, 0)) == .gt); | ||
| 1589 | } | ||
| 1590 | |||
| 1566 | pub fn compare(self: Order, op: CompareOperator) bool { | 1591 | pub fn compare(self: Order, op: CompareOperator) bool { |
| 1567 | return switch (self) { | 1592 | return switch (self) { |
| 1568 | .lt => switch (op) { | 1593 | .lt => switch (op) { |
| ... | @@ -1591,6 +1616,18 @@ pub const Order = enum { | ... | @@ -1591,6 +1616,18 @@ pub const Order = enum { |
| 1591 | }, | 1616 | }, |
| 1592 | }; | 1617 | }; |
| 1593 | } | 1618 | } |
| 1619 | |||
| 1620 | // https://github.com/ziglang/zig/issues/19295 | ||
| 1621 | test "compare" { | ||
| 1622 | try testing.expect(order(-1, 0).compare(.lt)); | ||
| 1623 | try testing.expect(order(-1, 0).compare(.lte)); | ||
| 1624 | try testing.expect(order(0, 0).compare(.lte)); | ||
| 1625 | try testing.expect(order(0, 0).compare(.eq)); | ||
| 1626 | try testing.expect(order(0, 0).compare(.gte)); | ||
| 1627 | try testing.expect(order(1, 0).compare(.gte)); | ||
| 1628 | try testing.expect(order(1, 0).compare(.gt)); | ||
| 1629 | try testing.expect(order(1, 0).compare(.neq)); | ||
| 1630 | } | ||
| 1594 | }; | 1631 | }; |
| 1595 | 1632 | ||
| 1596 | /// Given two numbers, this function returns the order they are with respect to each other. | 1633 | /// Given two numbers, this function returns the order they are with respect to each other. |
| ... | @@ -1633,6 +1670,15 @@ pub const CompareOperator = enum { | ... | @@ -1633,6 +1670,15 @@ pub const CompareOperator = enum { |
| 1633 | .neq => .neq, | 1670 | .neq => .neq, |
| 1634 | }; | 1671 | }; |
| 1635 | } | 1672 | } |
| 1673 | |||
| 1674 | test reverse { | ||
| 1675 | inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| { | ||
| 1676 | const op = @as(CompareOperator, @enumFromInt(op_field.value)); | ||
| 1677 | try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2)); | ||
| 1678 | try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3)); | ||
| 1679 | try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4)); | ||
| 1680 | } | ||
| 1681 | } | ||
| 1636 | }; | 1682 | }; |
| 1637 | 1683 | ||
| 1638 | /// This function does the same thing as comparison operators, however the | 1684 | /// This function does the same thing as comparison operators, however the |
| ... | @@ -1649,7 +1695,7 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool { | ... | @@ -1649,7 +1695,7 @@ pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool { |
| 1649 | }; | 1695 | }; |
| 1650 | } | 1696 | } |
| 1651 | 1697 | ||
| 1652 | test "compare between signed and unsigned" { | 1698 | test compare { |
| 1653 | try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255))); | 1699 | try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255))); |
| 1654 | try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1))); | 1700 | try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1))); |
| 1655 | try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255))); | 1701 | try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255))); |
| ... | @@ -1669,38 +1715,12 @@ test "compare between signed and unsigned" { | ... | @@ -1669,38 +1715,12 @@ test "compare between signed and unsigned" { |
| 1669 | try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); | 1715 | try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); |
| 1670 | } | 1716 | } |
| 1671 | 1717 | ||
| 1672 | test "order" { | 1718 | test order { |
| 1673 | try testing.expect(order(0, 0) == .eq); | 1719 | try testing.expect(order(0, 0) == .eq); |
| 1674 | try testing.expect(order(1, 0) == .gt); | 1720 | try testing.expect(order(1, 0) == .gt); |
| 1675 | try testing.expect(order(-1, 0) == .lt); | 1721 | try testing.expect(order(-1, 0) == .lt); |
| 1676 | } | 1722 | } |
| 1677 | 1723 | ||
| 1678 | test "order.invert" { | ||
| 1679 | try testing.expect(Order.invert(order(0, 0)) == .eq); | ||
| 1680 | try testing.expect(Order.invert(order(1, 0)) == .lt); | ||
| 1681 | try testing.expect(Order.invert(order(-1, 0)) == .gt); | ||
| 1682 | } | ||
| 1683 | |||
| 1684 | test "order.compare" { | ||
| 1685 | try testing.expect(order(-1, 0).compare(.lt)); | ||
| 1686 | try testing.expect(order(-1, 0).compare(.lte)); | ||
| 1687 | try testing.expect(order(0, 0).compare(.lte)); | ||
| 1688 | try testing.expect(order(0, 0).compare(.eq)); | ||
| 1689 | try testing.expect(order(0, 0).compare(.gte)); | ||
| 1690 | try testing.expect(order(1, 0).compare(.gte)); | ||
| 1691 | try testing.expect(order(1, 0).compare(.gt)); | ||
| 1692 | try testing.expect(order(1, 0).compare(.neq)); | ||
| 1693 | } | ||
| 1694 | |||
| 1695 | test "compare.reverse" { | ||
| 1696 | inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| { | ||
| 1697 | const op = @as(CompareOperator, @enumFromInt(op_field.value)); | ||
| 1698 | try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2)); | ||
| 1699 | try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3)); | ||
| 1700 | try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4)); | ||
| 1701 | } | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | /// Returns a mask of all ones if value is true, | 1724 | /// Returns a mask of all ones if value is true, |
| 1705 | /// and a mask of all zeroes if value is false. | 1725 | /// and a mask of all zeroes if value is false. |
| 1706 | /// Compiles to one instruction for register sized integers. | 1726 | /// Compiles to one instruction for register sized integers. |
| ... | @@ -1722,7 +1742,7 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { | ... | @@ -1722,7 +1742,7 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { |
| 1722 | return -%@as(MaskInt, @intCast(@intFromBool(value))); | 1742 | return -%@as(MaskInt, @intCast(@intFromBool(value))); |
| 1723 | } | 1743 | } |
| 1724 | 1744 | ||
| 1725 | test "boolMask" { | 1745 | test boolMask { |
| 1726 | const runTest = struct { | 1746 | const runTest = struct { |
| 1727 | fn runTest() !void { | 1747 | fn runTest() !void { |
| 1728 | try testing.expectEqual(@as(u1, 0), boolMask(u1, false)); | 1748 | try testing.expectEqual(@as(u1, 0), boolMask(u1, false)); |
| ... | @@ -1870,7 +1890,7 @@ fn testSign() !void { | ... | @@ -1870,7 +1890,7 @@ fn testSign() !void { |
| 1870 | try std.testing.expectEqual(0.0, sign(0.0)); | 1890 | try std.testing.expectEqual(0.0, sign(0.0)); |
| 1871 | } | 1891 | } |
| 1872 | 1892 | ||
| 1873 | test "sign" { | 1893 | test sign { |
| 1874 | if (builtin.zig_backend == .stage2_llvm) { | 1894 | if (builtin.zig_backend == .stage2_llvm) { |
| 1875 | // https://github.com/ziglang/zig/issues/12012 | 1895 | // https://github.com/ziglang/zig/issues/12012 |
| 1876 | return error.SkipZigTest; | 1896 | return error.SkipZigTest; |
lib/std/mem.zig+66-64| ... | @@ -306,7 +306,7 @@ pub fn zeroes(comptime T: type) T { | ... | @@ -306,7 +306,7 @@ pub fn zeroes(comptime T: type) T { |
| 306 | } | 306 | } |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | test "zeroes" { | 309 | test zeroes { |
| 310 | const C_struct = extern struct { | 310 | const C_struct = extern struct { |
| 311 | x: u32, | 311 | x: u32, |
| 312 | y: u32 align(128), | 312 | y: u32 align(128), |
| ... | @@ -475,7 +475,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T { | ... | @@ -475,7 +475,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T { |
| 475 | } | 475 | } |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | test "zeroInit" { | 478 | test zeroInit { |
| 479 | const I = struct { | 479 | const I = struct { |
| 480 | d: f64, | 480 | d: f64, |
| 481 | }; | 481 | }; |
| ... | @@ -606,16 +606,19 @@ pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order | ... | @@ -606,16 +606,19 @@ pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order |
| 606 | return math.order(lhs[i], rhs[i]); | 606 | return math.order(lhs[i], rhs[i]); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | test "order and orderZ" { | 609 | test order { |
| 610 | try testing.expect(order(u8, "abcd", "bee") == .lt); | 610 | try testing.expect(order(u8, "abcd", "bee") == .lt); |
| 611 | try testing.expect(orderZ(u8, "abcd", "bee") == .lt); | ||
| 612 | try testing.expect(order(u8, "abc", "abc") == .eq); | 611 | try testing.expect(order(u8, "abc", "abc") == .eq); |
| 613 | try testing.expect(orderZ(u8, "abc", "abc") == .eq); | ||
| 614 | try testing.expect(order(u8, "abc", "abc0") == .lt); | 612 | try testing.expect(order(u8, "abc", "abc0") == .lt); |
| 615 | try testing.expect(orderZ(u8, "abc", "abc0") == .lt); | ||
| 616 | try testing.expect(order(u8, "", "") == .eq); | 613 | try testing.expect(order(u8, "", "") == .eq); |
| 617 | try testing.expect(orderZ(u8, "", "") == .eq); | ||
| 618 | try testing.expect(order(u8, "", "a") == .lt); | 614 | try testing.expect(order(u8, "", "a") == .lt); |
| 615 | } | ||
| 616 | |||
| 617 | test orderZ { | ||
| 618 | try testing.expect(orderZ(u8, "abcd", "bee") == .lt); | ||
| 619 | try testing.expect(orderZ(u8, "abc", "abc") == .eq); | ||
| 620 | try testing.expect(orderZ(u8, "abc", "abc0") == .lt); | ||
| 621 | try testing.expect(orderZ(u8, "", "") == .eq); | ||
| 619 | try testing.expect(orderZ(u8, "", "a") == .lt); | 622 | try testing.expect(orderZ(u8, "", "a") == .lt); |
| 620 | } | 623 | } |
| 621 | 624 | ||
| ... | @@ -624,7 +627,7 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool { | ... | @@ -624,7 +627,7 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool { |
| 624 | return order(T, lhs, rhs) == .lt; | 627 | return order(T, lhs, rhs) == .lt; |
| 625 | } | 628 | } |
| 626 | 629 | ||
| 627 | test "lessThan" { | 630 | test lessThan { |
| 628 | try testing.expect(lessThan(u8, "abcd", "bee")); | 631 | try testing.expect(lessThan(u8, "abcd", "bee")); |
| 629 | try testing.expect(!lessThan(u8, "abc", "abc")); | 632 | try testing.expect(!lessThan(u8, "abc", "abc")); |
| 630 | try testing.expect(lessThan(u8, "abc", "abc0")); | 633 | try testing.expect(lessThan(u8, "abc", "abc0")); |
| ... | @@ -726,7 +729,7 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize { | ... | @@ -726,7 +729,7 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize { |
| 726 | return if (a.len == b.len) null else shortest; | 729 | return if (a.len == b.len) null else shortest; |
| 727 | } | 730 | } |
| 728 | 731 | ||
| 729 | test "indexOfDiff" { | 732 | test indexOfDiff { |
| 730 | try testing.expectEqual(indexOfDiff(u8, "one", "one"), null); | 733 | try testing.expectEqual(indexOfDiff(u8, "one", "one"), null); |
| 731 | try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3); | 734 | try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3); |
| 732 | try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3); | 735 | try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3); |
| ... | @@ -759,7 +762,7 @@ fn Span(comptime T: type) type { | ... | @@ -759,7 +762,7 @@ fn Span(comptime T: type) type { |
| 759 | @compileError("invalid type given to std.mem.span: " ++ @typeName(T)); | 762 | @compileError("invalid type given to std.mem.span: " ++ @typeName(T)); |
| 760 | } | 763 | } |
| 761 | 764 | ||
| 762 | test "Span" { | 765 | test Span { |
| 763 | try testing.expect(Span([*:1]u16) == [:1]u16); | 766 | try testing.expect(Span([*:1]u16) == [:1]u16); |
| 764 | try testing.expect(Span(?[*:1]u16) == ?[:1]u16); | 767 | try testing.expect(Span(?[*:1]u16) == ?[:1]u16); |
| 765 | try testing.expect(Span([*:1]const u8) == [:1]const u8); | 768 | try testing.expect(Span([*:1]const u8) == [:1]const u8); |
| ... | @@ -793,7 +796,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) { | ... | @@ -793,7 +796,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) { |
| 793 | } | 796 | } |
| 794 | } | 797 | } |
| 795 | 798 | ||
| 796 | test "span" { | 799 | test span { |
| 797 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; | 800 | var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 }; |
| 798 | const ptr = @as([*:3]u16, array[0..2 :3]); | 801 | const ptr = @as([*:3]u16, array[0..2 :3]); |
| 799 | try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 })); | 802 | try testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 })); |
| ... | @@ -877,7 +880,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo( | ... | @@ -877,7 +880,7 @@ pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo( |
| 877 | } | 880 | } |
| 878 | } | 881 | } |
| 879 | 882 | ||
| 880 | test "sliceTo" { | 883 | test sliceTo { |
| 881 | try testing.expectEqualSlices(u8, "aoeu", sliceTo("aoeu", 0)); | 884 | try testing.expectEqualSlices(u8, "aoeu", sliceTo("aoeu", 0)); |
| 882 | 885 | ||
| 883 | { | 886 | { |
| ... | @@ -963,7 +966,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { | ... | @@ -963,7 +966,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { |
| 963 | @compileError("invalid type given to std.mem.sliceTo: " ++ @typeName(@TypeOf(ptr))); | 966 | @compileError("invalid type given to std.mem.sliceTo: " ++ @typeName(@TypeOf(ptr))); |
| 964 | } | 967 | } |
| 965 | 968 | ||
| 966 | test "lenSliceTo" { | 969 | test lenSliceTo { |
| 967 | try testing.expect(lenSliceTo("aoeu", 0) == 4); | 970 | try testing.expect(lenSliceTo("aoeu", 0) == 4); |
| 968 | 971 | ||
| 969 | { | 972 | { |
| ... | @@ -1018,7 +1021,7 @@ pub fn len(value: anytype) usize { | ... | @@ -1018,7 +1021,7 @@ pub fn len(value: anytype) usize { |
| 1018 | } | 1021 | } |
| 1019 | } | 1022 | } |
| 1020 | 1023 | ||
| 1021 | test "len" { | 1024 | test len { |
| 1022 | var array: [5]u16 = [_]u16{ 1, 2, 0, 4, 5 }; | 1025 | var array: [5]u16 = [_]u16{ 1, 2, 0, 4, 5 }; |
| 1023 | const ptr = @as([*:4]u16, array[0..3 :4]); | 1026 | const ptr = @as([*:4]u16, array[0..3 :4]); |
| 1024 | try testing.expect(len(ptr) == 3); | 1027 | try testing.expect(len(ptr) == 3); |
| ... | @@ -1157,7 +1160,7 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co | ... | @@ -1157,7 +1160,7 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co |
| 1157 | return slice[begin..end]; | 1160 | return slice[begin..end]; |
| 1158 | } | 1161 | } |
| 1159 | 1162 | ||
| 1160 | test "trim" { | 1163 | test trim { |
| 1161 | try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); | 1164 | try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); |
| 1162 | try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); | 1165 | try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); |
| 1163 | try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); | 1166 | try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); |
| ... | @@ -1240,7 +1243,7 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, | ... | @@ -1240,7 +1243,7 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, |
| 1240 | return null; | 1243 | return null; |
| 1241 | } | 1244 | } |
| 1242 | 1245 | ||
| 1243 | test "indexOfScalarPos" { | 1246 | test indexOfScalarPos { |
| 1244 | const Types = [_]type{ u8, u16, u32, u64 }; | 1247 | const Types = [_]type{ u8, u16, u32, u64 }; |
| 1245 | 1248 | ||
| 1246 | inline for (Types) |T| { | 1249 | inline for (Types) |T| { |
| ... | @@ -1316,7 +1319,7 @@ pub fn indexOfNonePos(comptime T: type, slice: []const T, start_index: usize, va | ... | @@ -1316,7 +1319,7 @@ pub fn indexOfNonePos(comptime T: type, slice: []const T, start_index: usize, va |
| 1316 | return null; | 1319 | return null; |
| 1317 | } | 1320 | } |
| 1318 | 1321 | ||
| 1319 | test "indexOfNone" { | 1322 | test indexOfNone { |
| 1320 | try testing.expect(indexOfNone(u8, "abc123", "123").? == 0); | 1323 | try testing.expect(indexOfNone(u8, "abc123", "123").? == 0); |
| 1321 | try testing.expect(lastIndexOfNone(u8, "abc123", "123").? == 2); | 1324 | try testing.expect(lastIndexOfNone(u8, "abc123", "123").? == 2); |
| 1322 | try testing.expect(indexOfNone(u8, "123abc", "123").? == 3); | 1325 | try testing.expect(indexOfNone(u8, "123abc", "123").? == 3); |
| ... | @@ -1460,7 +1463,7 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee | ... | @@ -1460,7 +1463,7 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee |
| 1460 | return null; | 1463 | return null; |
| 1461 | } | 1464 | } |
| 1462 | 1465 | ||
| 1463 | test "indexOf" { | 1466 | test indexOf { |
| 1464 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | 1467 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); |
| 1465 | try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); | 1468 | try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); |
| 1466 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); | 1469 | try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); |
| ... | @@ -1533,7 +1536,7 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize { | ... | @@ -1533,7 +1536,7 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize { |
| 1533 | return found; | 1536 | return found; |
| 1534 | } | 1537 | } |
| 1535 | 1538 | ||
| 1536 | test "count" { | 1539 | test count { |
| 1537 | try testing.expect(count(u8, "", "h") == 0); | 1540 | try testing.expect(count(u8, "", "h") == 0); |
| 1538 | try testing.expect(count(u8, "h", "h") == 1); | 1541 | try testing.expect(count(u8, "h", "h") == 1); |
| 1539 | try testing.expect(count(u8, "hh", "h") == 2); | 1542 | try testing.expect(count(u8, "hh", "h") == 2); |
| ... | @@ -1565,7 +1568,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us | ... | @@ -1565,7 +1568,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us |
| 1565 | return false; | 1568 | return false; |
| 1566 | } | 1569 | } |
| 1567 | 1570 | ||
| 1568 | test "containsAtLeast" { | 1571 | test containsAtLeast { |
| 1569 | try testing.expect(containsAtLeast(u8, "aa", 0, "a")); | 1572 | try testing.expect(containsAtLeast(u8, "aa", 0, "a")); |
| 1570 | try testing.expect(containsAtLeast(u8, "aa", 1, "a")); | 1573 | try testing.expect(containsAtLeast(u8, "aa", 1, "a")); |
| 1571 | try testing.expect(containsAtLeast(u8, "aa", 2, "a")); | 1574 | try testing.expect(containsAtLeast(u8, "aa", 2, "a")); |
| ... | @@ -1698,6 +1701,9 @@ test readInt { | ... | @@ -1698,6 +1701,9 @@ test readInt { |
| 1698 | 1701 | ||
| 1699 | try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3); | 1702 | try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3); |
| 1700 | try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4); | 1703 | try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4); |
| 1704 | |||
| 1705 | try moreReadIntTests(); | ||
| 1706 | try comptime moreReadIntTests(); | ||
| 1701 | } | 1707 | } |
| 1702 | 1708 | ||
| 1703 | fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T { | 1709 | fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T { |
| ... | @@ -2027,7 +2033,7 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { | ... | @@ -2027,7 +2033,7 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { |
| 2027 | } | 2033 | } |
| 2028 | } | 2034 | } |
| 2029 | 2035 | ||
| 2030 | test "byteSwapAllFields" { | 2036 | test byteSwapAllFields { |
| 2031 | const T = extern struct { | 2037 | const T = extern struct { |
| 2032 | f0: u8, | 2038 | f0: u8, |
| 2033 | f1: u16, | 2039 | f1: u16, |
| ... | @@ -2136,7 +2142,7 @@ pub fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIt | ... | @@ -2136,7 +2142,7 @@ pub fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIt |
| 2136 | }; | 2142 | }; |
| 2137 | } | 2143 | } |
| 2138 | 2144 | ||
| 2139 | test "tokenizeScalar" { | 2145 | test tokenizeScalar { |
| 2140 | var it = tokenizeScalar(u8, " abc def ghi ", ' '); | 2146 | var it = tokenizeScalar(u8, " abc def ghi ", ' '); |
| 2141 | try testing.expect(eql(u8, it.next().?, "abc")); | 2147 | try testing.expect(eql(u8, it.next().?, "abc")); |
| 2142 | try testing.expect(eql(u8, it.peek().?, "def")); | 2148 | try testing.expect(eql(u8, it.peek().?, "def")); |
| ... | @@ -2177,7 +2183,7 @@ test "tokenizeScalar" { | ... | @@ -2177,7 +2183,7 @@ test "tokenizeScalar" { |
| 2177 | try testing.expect(it16.next() == null); | 2183 | try testing.expect(it16.next() == null); |
| 2178 | } | 2184 | } |
| 2179 | 2185 | ||
| 2180 | test "tokenizeAny" { | 2186 | test tokenizeAny { |
| 2181 | var it = tokenizeAny(u8, "a|b,c/d e", " /,|"); | 2187 | var it = tokenizeAny(u8, "a|b,c/d e", " /,|"); |
| 2182 | try testing.expect(eql(u8, it.next().?, "a")); | 2188 | try testing.expect(eql(u8, it.next().?, "a")); |
| 2183 | try testing.expect(eql(u8, it.peek().?, "b")); | 2189 | try testing.expect(eql(u8, it.peek().?, "b")); |
| ... | @@ -2205,7 +2211,7 @@ test "tokenizeAny" { | ... | @@ -2205,7 +2211,7 @@ test "tokenizeAny" { |
| 2205 | try testing.expect(it16.next() == null); | 2211 | try testing.expect(it16.next() == null); |
| 2206 | } | 2212 | } |
| 2207 | 2213 | ||
| 2208 | test "tokenizeSequence" { | 2214 | test tokenizeSequence { |
| 2209 | var it = tokenizeSequence(u8, "a<>b<><>c><>d><", "<>"); | 2215 | var it = tokenizeSequence(u8, "a<>b<><>c><>d><", "<>"); |
| 2210 | try testing.expectEqualStrings("a", it.next().?); | 2216 | try testing.expectEqualStrings("a", it.next().?); |
| 2211 | try testing.expectEqualStrings("b", it.peek().?); | 2217 | try testing.expectEqualStrings("b", it.peek().?); |
| ... | @@ -2334,7 +2340,7 @@ pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitItera | ... | @@ -2334,7 +2340,7 @@ pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitItera |
| 2334 | }; | 2340 | }; |
| 2335 | } | 2341 | } |
| 2336 | 2342 | ||
| 2337 | test "splitScalar" { | 2343 | test splitScalar { |
| 2338 | var it = splitScalar(u8, "abc|def||ghi", '|'); | 2344 | var it = splitScalar(u8, "abc|def||ghi", '|'); |
| 2339 | try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi"); | 2345 | try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi"); |
| 2340 | try testing.expectEqualSlices(u8, it.first(), "abc"); | 2346 | try testing.expectEqualSlices(u8, it.first(), "abc"); |
| ... | @@ -2377,7 +2383,7 @@ test "splitScalar" { | ... | @@ -2377,7 +2383,7 @@ test "splitScalar" { |
| 2377 | try testing.expect(it16.next() == null); | 2383 | try testing.expect(it16.next() == null); |
| 2378 | } | 2384 | } |
| 2379 | 2385 | ||
| 2380 | test "splitSequence" { | 2386 | test splitSequence { |
| 2381 | var it = splitSequence(u8, "a, b ,, c, d, e", ", "); | 2387 | var it = splitSequence(u8, "a, b ,, c, d, e", ", "); |
| 2382 | try testing.expectEqualSlices(u8, it.first(), "a"); | 2388 | try testing.expectEqualSlices(u8, it.first(), "a"); |
| 2383 | try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e"); | 2389 | try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e"); |
| ... | @@ -2400,7 +2406,7 @@ test "splitSequence" { | ... | @@ -2400,7 +2406,7 @@ test "splitSequence" { |
| 2400 | try testing.expect(it16.next() == null); | 2406 | try testing.expect(it16.next() == null); |
| 2401 | } | 2407 | } |
| 2402 | 2408 | ||
| 2403 | test "splitAny" { | 2409 | test splitAny { |
| 2404 | var it = splitAny(u8, "a,b, c d e", ", "); | 2410 | var it = splitAny(u8, "a,b, c d e", ", "); |
| 2405 | try testing.expectEqualSlices(u8, it.first(), "a"); | 2411 | try testing.expectEqualSlices(u8, it.first(), "a"); |
| 2406 | try testing.expectEqualSlices(u8, it.rest(), "b, c d e"); | 2412 | try testing.expectEqualSlices(u8, it.rest(), "b, c d e"); |
| ... | @@ -2536,7 +2542,7 @@ pub fn splitBackwardsScalar(comptime T: type, buffer: []const T, delimiter: T) S | ... | @@ -2536,7 +2542,7 @@ pub fn splitBackwardsScalar(comptime T: type, buffer: []const T, delimiter: T) S |
| 2536 | }; | 2542 | }; |
| 2537 | } | 2543 | } |
| 2538 | 2544 | ||
| 2539 | test "splitBackwardsScalar" { | 2545 | test splitBackwardsScalar { |
| 2540 | var it = splitBackwardsScalar(u8, "abc|def||ghi", '|'); | 2546 | var it = splitBackwardsScalar(u8, "abc|def||ghi", '|'); |
| 2541 | try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi"); | 2547 | try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi"); |
| 2542 | try testing.expectEqualSlices(u8, it.first(), "ghi"); | 2548 | try testing.expectEqualSlices(u8, it.first(), "ghi"); |
| ... | @@ -2575,7 +2581,7 @@ test "splitBackwardsScalar" { | ... | @@ -2575,7 +2581,7 @@ test "splitBackwardsScalar" { |
| 2575 | try testing.expect(it16.next() == null); | 2581 | try testing.expect(it16.next() == null); |
| 2576 | } | 2582 | } |
| 2577 | 2583 | ||
| 2578 | test "splitBackwardsSequence" { | 2584 | test splitBackwardsSequence { |
| 2579 | var it = splitBackwardsSequence(u8, "a, b ,, c, d, e", ", "); | 2585 | var it = splitBackwardsSequence(u8, "a, b ,, c, d, e", ", "); |
| 2580 | try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e"); | 2586 | try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e"); |
| 2581 | try testing.expectEqualSlices(u8, it.first(), "e"); | 2587 | try testing.expectEqualSlices(u8, it.first(), "e"); |
| ... | @@ -2608,7 +2614,7 @@ test "splitBackwardsSequence" { | ... | @@ -2608,7 +2614,7 @@ test "splitBackwardsSequence" { |
| 2608 | try testing.expect(it16.next() == null); | 2614 | try testing.expect(it16.next() == null); |
| 2609 | } | 2615 | } |
| 2610 | 2616 | ||
| 2611 | test "splitBackwardsAny" { | 2617 | test splitBackwardsAny { |
| 2612 | var it = splitBackwardsAny(u8, "a,b, c d e", ", "); | 2618 | var it = splitBackwardsAny(u8, "a,b, c d e", ", "); |
| 2613 | try testing.expectEqualSlices(u8, it.rest(), "a,b, c d e"); | 2619 | try testing.expectEqualSlices(u8, it.rest(), "a,b, c d e"); |
| 2614 | try testing.expectEqualSlices(u8, it.first(), "e"); | 2620 | try testing.expectEqualSlices(u8, it.first(), "e"); |
| ... | @@ -2715,7 +2721,7 @@ pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) | ... | @@ -2715,7 +2721,7 @@ pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) |
| 2715 | }; | 2721 | }; |
| 2716 | } | 2722 | } |
| 2717 | 2723 | ||
| 2718 | test "window" { | 2724 | test window { |
| 2719 | { | 2725 | { |
| 2720 | // moving average size 3 | 2726 | // moving average size 3 |
| 2721 | var it = window(u8, "abcdefg", 3, 1); | 2727 | var it = window(u8, "abcdefg", 3, 1); |
| ... | @@ -2841,7 +2847,7 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool | ... | @@ -2841,7 +2847,7 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool |
| 2841 | return if (needle.len > haystack.len) false else eql(T, haystack[0..needle.len], needle); | 2847 | return if (needle.len > haystack.len) false else eql(T, haystack[0..needle.len], needle); |
| 2842 | } | 2848 | } |
| 2843 | 2849 | ||
| 2844 | test "startsWith" { | 2850 | test startsWith { |
| 2845 | try testing.expect(startsWith(u8, "Bob", "Bo")); | 2851 | try testing.expect(startsWith(u8, "Bob", "Bo")); |
| 2846 | try testing.expect(!startsWith(u8, "Needle in haystack", "haystack")); | 2852 | try testing.expect(!startsWith(u8, "Needle in haystack", "haystack")); |
| 2847 | } | 2853 | } |
| ... | @@ -2850,7 +2856,7 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { | ... | @@ -2850,7 +2856,7 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool { |
| 2850 | return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len ..], needle); | 2856 | return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len ..], needle); |
| 2851 | } | 2857 | } |
| 2852 | 2858 | ||
| 2853 | test "endsWith" { | 2859 | test endsWith { |
| 2854 | try testing.expect(endsWith(u8, "Needle in haystack", "haystack")); | 2860 | try testing.expect(endsWith(u8, "Needle in haystack", "haystack")); |
| 2855 | try testing.expect(!endsWith(u8, "Bob", "Bo")); | 2861 | try testing.expect(!endsWith(u8, "Bob", "Bo")); |
| 2856 | } | 2862 | } |
| ... | @@ -3086,7 +3092,7 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con | ... | @@ -3086,7 +3092,7 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con |
| 3086 | return buf; | 3092 | return buf; |
| 3087 | } | 3093 | } |
| 3088 | 3094 | ||
| 3089 | test "join" { | 3095 | test join { |
| 3090 | { | 3096 | { |
| 3091 | const str = try join(testing.allocator, ",", &[_][]const u8{}); | 3097 | const str = try join(testing.allocator, ",", &[_][]const u8{}); |
| 3092 | defer testing.allocator.free(str); | 3098 | defer testing.allocator.free(str); |
| ... | @@ -3109,7 +3115,7 @@ test "join" { | ... | @@ -3109,7 +3115,7 @@ test "join" { |
| 3109 | } | 3115 | } |
| 3110 | } | 3116 | } |
| 3111 | 3117 | ||
| 3112 | test "joinZ" { | 3118 | test joinZ { |
| 3113 | { | 3119 | { |
| 3114 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{}); | 3120 | const str = try joinZ(testing.allocator, ",", &[_][]const u8{}); |
| 3115 | defer testing.allocator.free(str); | 3121 | defer testing.allocator.free(str); |
| ... | @@ -3181,7 +3187,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con | ... | @@ -3181,7 +3187,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con |
| 3181 | return buf; | 3187 | return buf; |
| 3182 | } | 3188 | } |
| 3183 | 3189 | ||
| 3184 | test "concat" { | 3190 | test concat { |
| 3185 | { | 3191 | { |
| 3186 | const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }); | 3192 | const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }); |
| 3187 | defer testing.allocator.free(str); | 3193 | defer testing.allocator.free(str); |
| ... | @@ -3219,17 +3225,13 @@ test "concat" { | ... | @@ -3219,17 +3225,13 @@ test "concat" { |
| 3219 | } | 3225 | } |
| 3220 | } | 3226 | } |
| 3221 | 3227 | ||
| 3222 | test "testStringEquality" { | 3228 | test eql { |
| 3223 | try testing.expect(eql(u8, "abcd", "abcd")); | 3229 | try testing.expect(eql(u8, "abcd", "abcd")); |
| 3224 | try testing.expect(!eql(u8, "abcdef", "abZdef")); | 3230 | try testing.expect(!eql(u8, "abcdef", "abZdef")); |
| 3225 | try testing.expect(!eql(u8, "abcdefg", "abcdef")); | 3231 | try testing.expect(!eql(u8, "abcdefg", "abcdef")); |
| 3226 | } | 3232 | } |
| 3227 | 3233 | ||
| 3228 | test "testReadInt" { | 3234 | fn moreReadIntTests() !void { |
| 3229 | try testReadIntImpl(); | ||
| 3230 | try comptime testReadIntImpl(); | ||
| 3231 | } | ||
| 3232 | fn testReadIntImpl() !void { | ||
| 3233 | { | 3235 | { |
| 3234 | const bytes = [_]u8{ | 3236 | const bytes = [_]u8{ |
| 3235 | 0x12, | 3237 | 0x12, |
| ... | @@ -3287,7 +3289,7 @@ pub fn min(comptime T: type, slice: []const T) T { | ... | @@ -3287,7 +3289,7 @@ pub fn min(comptime T: type, slice: []const T) T { |
| 3287 | return best; | 3289 | return best; |
| 3288 | } | 3290 | } |
| 3289 | 3291 | ||
| 3290 | test "min" { | 3292 | test min { |
| 3291 | try testing.expectEqual(min(u8, "abcdefg"), 'a'); | 3293 | try testing.expectEqual(min(u8, "abcdefg"), 'a'); |
| 3292 | try testing.expectEqual(min(u8, "bcdefga"), 'a'); | 3294 | try testing.expectEqual(min(u8, "bcdefga"), 'a'); |
| 3293 | try testing.expectEqual(min(u8, "a"), 'a'); | 3295 | try testing.expectEqual(min(u8, "a"), 'a'); |
| ... | @@ -3304,7 +3306,7 @@ pub fn max(comptime T: type, slice: []const T) T { | ... | @@ -3304,7 +3306,7 @@ pub fn max(comptime T: type, slice: []const T) T { |
| 3304 | return best; | 3306 | return best; |
| 3305 | } | 3307 | } |
| 3306 | 3308 | ||
| 3307 | test "max" { | 3309 | test max { |
| 3308 | try testing.expectEqual(max(u8, "abcdefg"), 'g'); | 3310 | try testing.expectEqual(max(u8, "abcdefg"), 'g'); |
| 3309 | try testing.expectEqual(max(u8, "gabcdef"), 'g'); | 3311 | try testing.expectEqual(max(u8, "gabcdef"), 'g'); |
| 3310 | try testing.expectEqual(max(u8, "g"), 'g'); | 3312 | try testing.expectEqual(max(u8, "g"), 'g'); |
| ... | @@ -3357,7 +3359,7 @@ pub fn indexOfMin(comptime T: type, slice: []const T) usize { | ... | @@ -3357,7 +3359,7 @@ pub fn indexOfMin(comptime T: type, slice: []const T) usize { |
| 3357 | return index; | 3359 | return index; |
| 3358 | } | 3360 | } |
| 3359 | 3361 | ||
| 3360 | test "indexOfMin" { | 3362 | test indexOfMin { |
| 3361 | try testing.expectEqual(indexOfMin(u8, "abcdefg"), 0); | 3363 | try testing.expectEqual(indexOfMin(u8, "abcdefg"), 0); |
| 3362 | try testing.expectEqual(indexOfMin(u8, "bcdefga"), 6); | 3364 | try testing.expectEqual(indexOfMin(u8, "bcdefga"), 6); |
| 3363 | try testing.expectEqual(indexOfMin(u8, "a"), 0); | 3365 | try testing.expectEqual(indexOfMin(u8, "a"), 0); |
| ... | @@ -3378,7 +3380,7 @@ pub fn indexOfMax(comptime T: type, slice: []const T) usize { | ... | @@ -3378,7 +3380,7 @@ pub fn indexOfMax(comptime T: type, slice: []const T) usize { |
| 3378 | return index; | 3380 | return index; |
| 3379 | } | 3381 | } |
| 3380 | 3382 | ||
| 3381 | test "indexOfMax" { | 3383 | test indexOfMax { |
| 3382 | try testing.expectEqual(indexOfMax(u8, "abcdefg"), 6); | 3384 | try testing.expectEqual(indexOfMax(u8, "abcdefg"), 6); |
| 3383 | try testing.expectEqual(indexOfMax(u8, "gabcdef"), 0); | 3385 | try testing.expectEqual(indexOfMax(u8, "gabcdef"), 0); |
| 3384 | try testing.expectEqual(indexOfMax(u8, "a"), 0); | 3386 | try testing.expectEqual(indexOfMax(u8, "a"), 0); |
| ... | @@ -3406,7 +3408,7 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { usize, usize } | ... | @@ -3406,7 +3408,7 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { usize, usize } |
| 3406 | return .{ minIdx, maxIdx }; | 3408 | return .{ minIdx, maxIdx }; |
| 3407 | } | 3409 | } |
| 3408 | 3410 | ||
| 3409 | test "indexOfMinMax" { | 3411 | test indexOfMinMax { |
| 3410 | try testing.expectEqual(.{ 0, 6 }, indexOfMinMax(u8, "abcdefg")); | 3412 | try testing.expectEqual(.{ 0, 6 }, indexOfMinMax(u8, "abcdefg")); |
| 3411 | try testing.expectEqual(.{ 1, 0 }, indexOfMinMax(u8, "gabcdef")); | 3413 | try testing.expectEqual(.{ 1, 0 }, indexOfMinMax(u8, "gabcdef")); |
| 3412 | try testing.expectEqual(.{ 0, 0 }, indexOfMinMax(u8, "a")); | 3414 | try testing.expectEqual(.{ 0, 0 }, indexOfMinMax(u8, "a")); |
| ... | @@ -3427,7 +3429,7 @@ pub fn reverse(comptime T: type, items: []T) void { | ... | @@ -3427,7 +3429,7 @@ pub fn reverse(comptime T: type, items: []T) void { |
| 3427 | } | 3429 | } |
| 3428 | } | 3430 | } |
| 3429 | 3431 | ||
| 3430 | test "reverse" { | 3432 | test reverse { |
| 3431 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; | 3433 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; |
| 3432 | reverse(i32, arr[0..]); | 3434 | reverse(i32, arr[0..]); |
| 3433 | 3435 | ||
| ... | @@ -3488,7 +3490,7 @@ pub fn reverseIterator(slice: anytype) ReverseIterator(@TypeOf(slice)) { | ... | @@ -3488,7 +3490,7 @@ pub fn reverseIterator(slice: anytype) ReverseIterator(@TypeOf(slice)) { |
| 3488 | return .{ .ptr = slice.ptr, .index = slice.len }; | 3490 | return .{ .ptr = slice.ptr, .index = slice.len }; |
| 3489 | } | 3491 | } |
| 3490 | 3492 | ||
| 3491 | test "reverseIterator" { | 3493 | test reverseIterator { |
| 3492 | { | 3494 | { |
| 3493 | var it = reverseIterator("abc"); | 3495 | var it = reverseIterator("abc"); |
| 3494 | try testing.expectEqual(@as(?u8, 'c'), it.next()); | 3496 | try testing.expectEqual(@as(?u8, 'c'), it.next()); |
| ... | @@ -3546,7 +3548,7 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void { | ... | @@ -3546,7 +3548,7 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void { |
| 3546 | reverse(T, items); | 3548 | reverse(T, items); |
| 3547 | } | 3549 | } |
| 3548 | 3550 | ||
| 3549 | test "rotate" { | 3551 | test rotate { |
| 3550 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; | 3552 | var arr = [_]i32{ 5, 3, 1, 2, 4 }; |
| 3551 | rotate(i32, arr[0..], 2); | 3553 | rotate(i32, arr[0..], 2); |
| 3552 | 3554 | ||
| ... | @@ -3580,7 +3582,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen | ... | @@ -3580,7 +3582,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen |
| 3580 | return replacements; | 3582 | return replacements; |
| 3581 | } | 3583 | } |
| 3582 | 3584 | ||
| 3583 | test "replace" { | 3585 | test replace { |
| 3584 | var output: [29]u8 = undefined; | 3586 | var output: [29]u8 = undefined; |
| 3585 | var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]); | 3587 | var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]); |
| 3586 | var expected: []const u8 = "All your Zig are belong to us"; | 3588 | var expected: []const u8 = "All your Zig are belong to us"; |
| ... | @@ -3643,7 +3645,7 @@ fn testCollapseRepeats(str: []const u8, elem: u8, expected: []const u8) !void { | ... | @@ -3643,7 +3645,7 @@ fn testCollapseRepeats(str: []const u8, elem: u8, expected: []const u8) !void { |
| 3643 | defer std.testing.allocator.free(mutable); | 3645 | defer std.testing.allocator.free(mutable); |
| 3644 | try testing.expect(std.mem.eql(u8, collapseRepeats(u8, mutable, elem), expected)); | 3646 | try testing.expect(std.mem.eql(u8, collapseRepeats(u8, mutable, elem), expected)); |
| 3645 | } | 3647 | } |
| 3646 | test "collapseRepeats" { | 3648 | test collapseRepeats { |
| 3647 | try testCollapseRepeats("", '/', ""); | 3649 | try testCollapseRepeats("", '/', ""); |
| 3648 | try testCollapseRepeats("a", '/', "a"); | 3650 | try testCollapseRepeats("a", '/', "a"); |
| 3649 | try testCollapseRepeats("/", '/', "/"); | 3651 | try testCollapseRepeats("/", '/', "/"); |
| ... | @@ -3677,7 +3679,7 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re | ... | @@ -3677,7 +3679,7 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re |
| 3677 | return size; | 3679 | return size; |
| 3678 | } | 3680 | } |
| 3679 | 3681 | ||
| 3680 | test "replacementSize" { | 3682 | test replacementSize { |
| 3681 | try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29); | 3683 | try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29); |
| 3682 | try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29); | 3684 | try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29); |
| 3683 | try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41); | 3685 | try testing.expect(replacementSize(u8, "Only one obvious way to do things.", "things.", "things in Zig.") == 41); |
| ... | @@ -3697,7 +3699,7 @@ pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, ne | ... | @@ -3697,7 +3699,7 @@ pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, ne |
| 3697 | return output; | 3699 | return output; |
| 3698 | } | 3700 | } |
| 3699 | 3701 | ||
| 3700 | test "replaceOwned" { | 3702 | test replaceOwned { |
| 3701 | const gpa = std.testing.allocator; | 3703 | const gpa = std.testing.allocator; |
| 3702 | 3704 | ||
| 3703 | const base_replace = replaceOwned(u8, gpa, "All your base are belong to us", "base", "Zig") catch @panic("out of memory"); | 3705 | const base_replace = replaceOwned(u8, gpa, "All your base are belong to us", "base", "Zig") catch @panic("out of memory"); |
| ... | @@ -3801,7 +3803,7 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) { | ... | @@ -3801,7 +3803,7 @@ pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) { |
| 3801 | return @alignCast(ptr + adjust_off); | 3803 | return @alignCast(ptr + adjust_off); |
| 3802 | } | 3804 | } |
| 3803 | 3805 | ||
| 3804 | test "alignPointer" { | 3806 | test alignPointer { |
| 3805 | const S = struct { | 3807 | const S = struct { |
| 3806 | fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void { | 3808 | fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void { |
| 3807 | const ptr: T = @ptrFromInt(base); | 3809 | const ptr: T = @ptrFromInt(base); |
| ... | @@ -3850,7 +3852,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { | ... | @@ -3850,7 +3852,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { |
| 3850 | return @ptrCast(@alignCast(ptr)); | 3852 | return @ptrCast(@alignCast(ptr)); |
| 3851 | } | 3853 | } |
| 3852 | 3854 | ||
| 3853 | test "asBytes" { | 3855 | test asBytes { |
| 3854 | const deadbeef = @as(u32, 0xDEADBEEF); | 3856 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 3855 | const deadbeef_bytes = switch (native_endian) { | 3857 | const deadbeef_bytes = switch (native_endian) { |
| 3856 | .big => "\xDE\xAD\xBE\xEF", | 3858 | .big => "\xDE\xAD\xBE\xEF", |
| ... | @@ -3910,7 +3912,7 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { | ... | @@ -3910,7 +3912,7 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { |
| 3910 | return asBytes(&value).*; | 3912 | return asBytes(&value).*; |
| 3911 | } | 3913 | } |
| 3912 | 3914 | ||
| 3913 | test "toBytes" { | 3915 | test toBytes { |
| 3914 | var my_bytes = toBytes(@as(u32, 0x12345678)); | 3916 | var my_bytes = toBytes(@as(u32, 0x12345678)); |
| 3915 | switch (native_endian) { | 3917 | switch (native_endian) { |
| 3916 | .big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | 3918 | .big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), |
| ... | @@ -3934,7 +3936,7 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, | ... | @@ -3934,7 +3936,7 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, |
| 3934 | return @ptrCast(bytes); | 3936 | return @ptrCast(bytes); |
| 3935 | } | 3937 | } |
| 3936 | 3938 | ||
| 3937 | test "bytesAsValue" { | 3939 | test bytesAsValue { |
| 3938 | const deadbeef = @as(u32, 0xDEADBEEF); | 3940 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 3939 | const deadbeef_bytes = switch (native_endian) { | 3941 | const deadbeef_bytes = switch (native_endian) { |
| 3940 | .big => "\xDE\xAD\xBE\xEF", | 3942 | .big => "\xDE\xAD\xBE\xEF", |
| ... | @@ -3993,7 +3995,7 @@ test "bytesAsValue preserves pointer attributes" { | ... | @@ -3993,7 +3995,7 @@ test "bytesAsValue preserves pointer attributes" { |
| 3993 | pub fn bytesToValue(comptime T: type, bytes: anytype) T { | 3995 | pub fn bytesToValue(comptime T: type, bytes: anytype) T { |
| 3994 | return bytesAsValue(T, bytes).*; | 3996 | return bytesAsValue(T, bytes).*; |
| 3995 | } | 3997 | } |
| 3996 | test "bytesToValue" { | 3998 | test bytesToValue { |
| 3997 | const deadbeef_bytes = switch (native_endian) { | 3999 | const deadbeef_bytes = switch (native_endian) { |
| 3998 | .big => "\xDE\xAD\xBE\xEF", | 4000 | .big => "\xDE\xAD\xBE\xEF", |
| 3999 | .little => "\xEF\xBE\xAD\xDE", | 4001 | .little => "\xEF\xBE\xAD\xDE", |
| ... | @@ -4021,7 +4023,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T, | ... | @@ -4021,7 +4023,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T, |
| 4021 | return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))]; | 4023 | return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))]; |
| 4022 | } | 4024 | } |
| 4023 | 4025 | ||
| 4024 | test "bytesAsSlice" { | 4026 | test bytesAsSlice { |
| 4025 | { | 4027 | { |
| 4026 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; | 4028 | const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF }; |
| 4027 | const slice = bytesAsSlice(u16, bytes[0..]); | 4029 | const slice = bytesAsSlice(u16, bytes[0..]); |
| ... | @@ -4110,7 +4112,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) { | ... | @@ -4110,7 +4112,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) { |
| 4110 | return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(std.meta.Elem(Slice))]; | 4112 | return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(std.meta.Elem(Slice))]; |
| 4111 | } | 4113 | } |
| 4112 | 4114 | ||
| 4113 | test "sliceAsBytes" { | 4115 | test sliceAsBytes { |
| 4114 | const bytes = [_]u16{ 0xDEAD, 0xBEEF }; | 4116 | const bytes = [_]u16{ 0xDEAD, 0xBEEF }; |
| 4115 | const slice = sliceAsBytes(bytes[0..]); | 4117 | const slice = sliceAsBytes(bytes[0..]); |
| 4116 | try testing.expect(slice.len == 4); | 4118 | try testing.expect(slice.len == 4); |
| ... | @@ -4268,7 +4270,7 @@ fn doNotOptimizeAwayC(ptr: anytype) void { | ... | @@ -4268,7 +4270,7 @@ fn doNotOptimizeAwayC(ptr: anytype) void { |
| 4268 | dest.* = 0; | 4270 | dest.* = 0; |
| 4269 | } | 4271 | } |
| 4270 | 4272 | ||
| 4271 | test "doNotOptimizeAway" { | 4273 | test doNotOptimizeAway { |
| 4272 | comptime doNotOptimizeAway("test"); | 4274 | comptime doNotOptimizeAway("test"); |
| 4273 | 4275 | ||
| 4274 | doNotOptimizeAway(null); | 4276 | doNotOptimizeAway(null); |
| ... | @@ -4293,7 +4295,7 @@ test "doNotOptimizeAway" { | ... | @@ -4293,7 +4295,7 @@ test "doNotOptimizeAway" { |
| 4293 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); | 4295 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); |
| 4294 | } | 4296 | } |
| 4295 | 4297 | ||
| 4296 | test "alignForward" { | 4298 | test alignForward { |
| 4297 | try testing.expect(alignForward(usize, 1, 1) == 1); | 4299 | try testing.expect(alignForward(usize, 1, 1) == 1); |
| 4298 | try testing.expect(alignForward(usize, 2, 1) == 2); | 4300 | try testing.expect(alignForward(usize, 2, 1) == 2); |
| 4299 | try testing.expect(alignForward(usize, 1, 2) == 2); | 4301 | try testing.expect(alignForward(usize, 1, 2) == 2); |
| ... | @@ -4362,7 +4364,7 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool { | ... | @@ -4362,7 +4364,7 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool { |
| 4362 | return alignBackward(T, addr, alignment) == addr; | 4364 | return alignBackward(T, addr, alignment) == addr; |
| 4363 | } | 4365 | } |
| 4364 | 4366 | ||
| 4365 | test "isAligned" { | 4367 | test isAligned { |
| 4366 | try testing.expect(isAligned(0, 4)); | 4368 | try testing.expect(isAligned(0, 4)); |
| 4367 | try testing.expect(isAligned(1, 1)); | 4369 | try testing.expect(isAligned(1, 1)); |
| 4368 | try testing.expect(isAligned(2, 1)); | 4370 | try testing.expect(isAligned(2, 1)); |
lib/std/meta/trailer_flags.zig+1-1| ... | @@ -132,7 +132,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -132,7 +132,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 132 | }; | 132 | }; |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | test "TrailerFlags" { | 135 | test TrailerFlags { |
| 136 | const Flags = TrailerFlags(struct { | 136 | const Flags = TrailerFlags(struct { |
| 137 | a: i32, | 137 | a: i32, |
| 138 | b: bool, | 138 | b: bool, |
lib/std/os/windows.zig+3-3| ... | @@ -1379,7 +1379,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -1379,7 +1379,7 @@ pub fn GetFinalPathNameByHandle( |
| 1379 | } | 1379 | } |
| 1380 | } | 1380 | } |
| 1381 | 1381 | ||
| 1382 | test "GetFinalPathNameByHandle" { | 1382 | test GetFinalPathNameByHandle { |
| 1383 | if (builtin.os.tag != .windows) | 1383 | if (builtin.os.tag != .windows) |
| 1384 | return; | 1384 | return; |
| 1385 | 1385 | ||
| ... | @@ -2601,7 +2601,7 @@ pub fn ntToWin32Namespace(path: []const u16) !PathSpace { | ... | @@ -2601,7 +2601,7 @@ pub fn ntToWin32Namespace(path: []const u16) !PathSpace { |
| 2601 | } | 2601 | } |
| 2602 | } | 2602 | } |
| 2603 | 2603 | ||
| 2604 | test "ntToWin32Namespace" { | 2604 | test ntToWin32Namespace { |
| 2605 | const L = std.unicode.utf8ToUtf16LeStringLiteral; | 2605 | const L = std.unicode.utf8ToUtf16LeStringLiteral; |
| 2606 | 2606 | ||
| 2607 | try testNtToWin32Namespace(L("UNC"), L("\\??\\UNC")); | 2607 | try testNtToWin32Namespace(L("UNC"), L("\\??\\UNC")); |
| ... | @@ -3539,7 +3539,7 @@ pub const GUID = extern struct { | ... | @@ -3539,7 +3539,7 @@ pub const GUID = extern struct { |
| 3539 | } | 3539 | } |
| 3540 | }; | 3540 | }; |
| 3541 | 3541 | ||
| 3542 | test "GUID" { | 3542 | test GUID { |
| 3543 | try std.testing.expectEqual( | 3543 | try std.testing.expectEqual( |
| 3544 | GUID{ | 3544 | GUID{ |
| 3545 | .Data1 = 0x01234567, | 3545 | .Data1 = 0x01234567, |
lib/std/process.zig+3-3| ... | @@ -215,7 +215,7 @@ pub const EnvMap = struct { | ... | @@ -215,7 +215,7 @@ pub const EnvMap = struct { |
| 215 | } | 215 | } |
| 216 | }; | 216 | }; |
| 217 | 217 | ||
| 218 | test "EnvMap" { | 218 | test EnvMap { |
| 219 | var env = EnvMap.init(testing.allocator); | 219 | var env = EnvMap.init(testing.allocator); |
| 220 | defer env.deinit(); | 220 | defer env.deinit(); |
| 221 | 221 | ||
| ... | @@ -377,7 +377,7 @@ pub fn getEnvMap(allocator: Allocator) GetEnvMapError!EnvMap { | ... | @@ -377,7 +377,7 @@ pub fn getEnvMap(allocator: Allocator) GetEnvMapError!EnvMap { |
| 377 | } | 377 | } |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | test "getEnvMap" { | 380 | test getEnvMap { |
| 381 | var env = try getEnvMap(testing.allocator); | 381 | var env = try getEnvMap(testing.allocator); |
| 382 | defer env.deinit(); | 382 | defer env.deinit(); |
| 383 | } | 383 | } |
| ... | @@ -1181,7 +1181,7 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void { | ... | @@ -1181,7 +1181,7 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void { |
| 1181 | return allocator.free(aligned_allocated_buf); | 1181 | return allocator.free(aligned_allocated_buf); |
| 1182 | } | 1182 | } |
| 1183 | 1183 | ||
| 1184 | test "ArgIteratorWindows" { | 1184 | test ArgIteratorWindows { |
| 1185 | const t = testArgIteratorWindows; | 1185 | const t = testArgIteratorWindows; |
| 1186 | 1186 | ||
| 1187 | try t( | 1187 | try t( |
lib/std/sort.zig+9-9| ... | @@ -430,7 +430,7 @@ pub fn binarySearch( | ... | @@ -430,7 +430,7 @@ pub fn binarySearch( |
| 430 | return null; | 430 | return null; |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | test "binarySearch" { | 433 | test binarySearch { |
| 434 | const S = struct { | 434 | const S = struct { |
| 435 | fn order_u32(context: void, lhs: u32, rhs: u32) math.Order { | 435 | fn order_u32(context: void, lhs: u32, rhs: u32) math.Order { |
| 436 | _ = context; | 436 | _ = context; |
| ... | @@ -537,7 +537,7 @@ pub fn lowerBound( | ... | @@ -537,7 +537,7 @@ pub fn lowerBound( |
| 537 | return left; | 537 | return left; |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | test "lowerBound" { | 540 | test lowerBound { |
| 541 | const S = struct { | 541 | const S = struct { |
| 542 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { | 542 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { |
| 543 | _ = context; | 543 | _ = context; |
| ... | @@ -627,7 +627,7 @@ pub fn upperBound( | ... | @@ -627,7 +627,7 @@ pub fn upperBound( |
| 627 | return left; | 627 | return left; |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | test "upperBound" { | 630 | test upperBound { |
| 631 | const S = struct { | 631 | const S = struct { |
| 632 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { | 632 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { |
| 633 | _ = context; | 633 | _ = context; |
| ... | @@ -712,7 +712,7 @@ pub fn equalRange( | ... | @@ -712,7 +712,7 @@ pub fn equalRange( |
| 712 | }; | 712 | }; |
| 713 | } | 713 | } |
| 714 | 714 | ||
| 715 | test "equalRange" { | 715 | test equalRange { |
| 716 | const S = struct { | 716 | const S = struct { |
| 717 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { | 717 | fn lower_u32(context: void, lhs: u32, rhs: u32) bool { |
| 718 | _ = context; | 718 | _ = context; |
| ... | @@ -792,7 +792,7 @@ pub fn argMin( | ... | @@ -792,7 +792,7 @@ pub fn argMin( |
| 792 | return smallest_index; | 792 | return smallest_index; |
| 793 | } | 793 | } |
| 794 | 794 | ||
| 795 | test "argMin" { | 795 | test argMin { |
| 796 | try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32)); | 796 | try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32)); |
| 797 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32)); | 797 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32)); |
| 798 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | 798 | try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); |
| ... | @@ -812,7 +812,7 @@ pub fn min( | ... | @@ -812,7 +812,7 @@ pub fn min( |
| 812 | return items[i]; | 812 | return items[i]; |
| 813 | } | 813 | } |
| 814 | 814 | ||
| 815 | test "min" { | 815 | test min { |
| 816 | try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32)); | 816 | try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32)); |
| 817 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32)); | 817 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32)); |
| 818 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | 818 | try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); |
| ... | @@ -844,7 +844,7 @@ pub fn argMax( | ... | @@ -844,7 +844,7 @@ pub fn argMax( |
| 844 | return biggest_index; | 844 | return biggest_index; |
| 845 | } | 845 | } |
| 846 | 846 | ||
| 847 | test "argMax" { | 847 | test argMax { |
| 848 | try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32)); | 848 | try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32)); |
| 849 | try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32)); | 849 | try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32)); |
| 850 | try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | 850 | try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); |
| ... | @@ -864,7 +864,7 @@ pub fn max( | ... | @@ -864,7 +864,7 @@ pub fn max( |
| 864 | return items[i]; | 864 | return items[i]; |
| 865 | } | 865 | } |
| 866 | 866 | ||
| 867 | test "max" { | 867 | test max { |
| 868 | try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32)); | 868 | try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32)); |
| 869 | try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32)); | 869 | try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32)); |
| 870 | try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | 870 | try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); |
| ... | @@ -890,7 +890,7 @@ pub fn isSorted( | ... | @@ -890,7 +890,7 @@ pub fn isSorted( |
| 890 | return true; | 890 | return true; |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | test "isSorted" { | 893 | test isSorted { |
| 894 | try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32)); | 894 | try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32)); |
| 895 | try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32)); | 895 | try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32)); |
| 896 | try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); | 896 | try testing.expect(isSorted(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32)); |
lib/std/tar.zig+2-2| ... | @@ -676,7 +676,7 @@ fn stripComponents(path: []const u8, count: u32) []const u8 { | ... | @@ -676,7 +676,7 @@ fn stripComponents(path: []const u8, count: u32) []const u8 { |
| 676 | return path[i..]; | 676 | return path[i..]; |
| 677 | } | 677 | } |
| 678 | 678 | ||
| 679 | test "stripComponents" { | 679 | test stripComponents { |
| 680 | const expectEqualStrings = testing.expectEqualStrings; | 680 | const expectEqualStrings = testing.expectEqualStrings; |
| 681 | try expectEqualStrings("a/b/c", stripComponents("a/b/c", 0)); | 681 | try expectEqualStrings("a/b/c", stripComponents("a/b/c", 0)); |
| 682 | try expectEqualStrings("b/c", stripComponents("a/b/c", 1)); | 682 | try expectEqualStrings("b/c", stripComponents("a/b/c", 1)); |
| ... | @@ -685,7 +685,7 @@ test "stripComponents" { | ... | @@ -685,7 +685,7 @@ test "stripComponents" { |
| 685 | try expectEqualStrings("", stripComponents("a/b/c", 4)); | 685 | try expectEqualStrings("", stripComponents("a/b/c", 4)); |
| 686 | } | 686 | } |
| 687 | 687 | ||
| 688 | test "PaxIterator" { | 688 | test PaxIterator { |
| 689 | const Attr = struct { | 689 | const Attr = struct { |
| 690 | kind: PaxAttributeKind, | 690 | kind: PaxAttributeKind, |
| 691 | value: []const u8 = undefined, | 691 | value: []const u8 = undefined, |
lib/std/testing.zig+2-2| ... | @@ -242,7 +242,7 @@ fn expectApproxEqAbsInner(comptime T: type, expected: T, actual: T, tolerance: T | ... | @@ -242,7 +242,7 @@ fn expectApproxEqAbsInner(comptime T: type, expected: T, actual: T, tolerance: T |
| 242 | } | 242 | } |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | test "expectApproxEqAbs" { | 245 | test expectApproxEqAbs { |
| 246 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { | 246 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
| 247 | const pos_x: T = 12.0; | 247 | const pos_x: T = 12.0; |
| 248 | const pos_y: T = 12.06; | 248 | const pos_y: T = 12.06; |
| ... | @@ -278,7 +278,7 @@ fn expectApproxEqRelInner(comptime T: type, expected: T, actual: T, tolerance: T | ... | @@ -278,7 +278,7 @@ fn expectApproxEqRelInner(comptime T: type, expected: T, actual: T, tolerance: T |
| 278 | } | 278 | } |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | test "expectApproxEqRel" { | 281 | test expectApproxEqRel { |
| 282 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { | 282 | inline for ([_]type{ f16, f32, f64, f128 }) |T| { |
| 283 | const eps_value = comptime math.floatEps(T); | 283 | const eps_value = comptime math.floatEps(T); |
| 284 | const sqrt_eps_value = comptime @sqrt(eps_value); | 284 | const sqrt_eps_value = comptime @sqrt(eps_value); |
lib/std/time.zig+3-3| ... | @@ -53,7 +53,7 @@ pub fn sleep(nanoseconds: u64) void { | ... | @@ -53,7 +53,7 @@ pub fn sleep(nanoseconds: u64) void { |
| 53 | posix.nanosleep(s, ns); | 53 | posix.nanosleep(s, ns); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | test "sleep" { | 56 | test sleep { |
| 57 | sleep(1); | 57 | sleep(1); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| ... | @@ -123,7 +123,7 @@ pub fn nanoTimestamp() i128 { | ... | @@ -123,7 +123,7 @@ pub fn nanoTimestamp() i128 { |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | test "timestamp" { | 126 | test milliTimestamp { |
| 127 | const margin = ns_per_ms * 50; | 127 | const margin = ns_per_ms * 50; |
| 128 | 128 | ||
| 129 | const time_0 = milliTimestamp(); | 129 | const time_0 = milliTimestamp(); |
| ... | @@ -327,7 +327,7 @@ pub const Timer = struct { | ... | @@ -327,7 +327,7 @@ pub const Timer = struct { |
| 327 | } | 327 | } |
| 328 | }; | 328 | }; |
| 329 | 329 | ||
| 330 | test "Timer + Instant" { | 330 | test Timer { |
| 331 | const margin = ns_per_ms * 150; | 331 | const margin = ns_per_ms * 150; |
| 332 | 332 | ||
| 333 | var timer = try Timer.start(); | 333 | var timer = try Timer.start(); |
lib/std/time/epoch.zig+1-1| ... | @@ -53,7 +53,7 @@ pub fn isLeapYear(year: Year) bool { | ... | @@ -53,7 +53,7 @@ pub fn isLeapYear(year: Year) bool { |
| 53 | return (0 == @mod(year, 400)); | 53 | return (0 == @mod(year, 400)); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | test "isLeapYear" { | 56 | test isLeapYear { |
| 57 | try testing.expectEqual(false, isLeapYear(2095)); | 57 | try testing.expectEqual(false, isLeapYear(2095)); |
| 58 | try testing.expectEqual(true, isLeapYear(2096)); | 58 | try testing.expectEqual(true, isLeapYear(2096)); |
| 59 | try testing.expectEqual(false, isLeapYear(2100)); | 59 | try testing.expectEqual(false, isLeapYear(2100)); |
lib/std/unicode.zig+4-4| ... | @@ -907,7 +907,7 @@ pub fn fmtUtf8(utf8: []const u8) std.fmt.Formatter(formatUtf8) { | ... | @@ -907,7 +907,7 @@ pub fn fmtUtf8(utf8: []const u8) std.fmt.Formatter(formatUtf8) { |
| 907 | return .{ .data = utf8 }; | 907 | return .{ .data = utf8 }; |
| 908 | } | 908 | } |
| 909 | 909 | ||
| 910 | test "fmtUtf8" { | 910 | test fmtUtf8 { |
| 911 | const expectFmt = testing.expectFmt; | 911 | const expectFmt = testing.expectFmt; |
| 912 | try expectFmt("", "{}", .{fmtUtf8("")}); | 912 | try expectFmt("", "{}", .{fmtUtf8("")}); |
| 913 | try expectFmt("foo", "{}", .{fmtUtf8("foo")}); | 913 | try expectFmt("foo", "{}", .{fmtUtf8("foo")}); |
| ... | @@ -1249,7 +1249,7 @@ pub fn utf8ToUtf16LeImpl(utf16le: []u16, utf8: []const u8, comptime surrogates: | ... | @@ -1249,7 +1249,7 @@ pub fn utf8ToUtf16LeImpl(utf16le: []u16, utf8: []const u8, comptime surrogates: |
| 1249 | return dest_index; | 1249 | return dest_index; |
| 1250 | } | 1250 | } |
| 1251 | 1251 | ||
| 1252 | test "utf8ToUtf16Le" { | 1252 | test utf8ToUtf16Le { |
| 1253 | var utf16le: [128]u16 = undefined; | 1253 | var utf16le: [128]u16 = undefined; |
| 1254 | { | 1254 | { |
| 1255 | const length = try utf8ToUtf16Le(utf16le[0..], "π·"); | 1255 | const length = try utf8ToUtf16Le(utf16le[0..], "π·"); |
| ... | @@ -1430,7 +1430,7 @@ pub fn fmtUtf16Le(utf16le: []const u16) std.fmt.Formatter(formatUtf16Le) { | ... | @@ -1430,7 +1430,7 @@ pub fn fmtUtf16Le(utf16le: []const u16) std.fmt.Formatter(formatUtf16Le) { |
| 1430 | return .{ .data = utf16le }; | 1430 | return .{ .data = utf16le }; |
| 1431 | } | 1431 | } |
| 1432 | 1432 | ||
| 1433 | test "fmtUtf16Le" { | 1433 | test fmtUtf16Le { |
| 1434 | const expectFmt = testing.expectFmt; | 1434 | const expectFmt = testing.expectFmt; |
| 1435 | try expectFmt("", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral(""))}); | 1435 | try expectFmt("", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral(""))}); |
| 1436 | try expectFmt("foo", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral("foo"))}); | 1436 | try expectFmt("foo", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral("foo"))}); |
| ... | @@ -1443,7 +1443,7 @@ test "fmtUtf16Le" { | ... | @@ -1443,7 +1443,7 @@ test "fmtUtf16Le" { |
| 1443 | try expectFmt("ξ", "{}", .{fmtUtf16Le(&[_]u16{mem.readInt(u16, "\x00\xe0", native_endian)})}); | 1443 | try expectFmt("ξ", "{}", .{fmtUtf16Le(&[_]u16{mem.readInt(u16, "\x00\xe0", native_endian)})}); |
| 1444 | } | 1444 | } |
| 1445 | 1445 | ||
| 1446 | test "utf8ToUtf16LeStringLiteral" { | 1446 | test utf8ToUtf16LeStringLiteral { |
| 1447 | { | 1447 | { |
| 1448 | const bytes = [_:0]u16{ | 1448 | const bytes = [_:0]u16{ |
| 1449 | mem.nativeToLittle(u16, 0x41), | 1449 | mem.nativeToLittle(u16, 0x41), |
lib/std/valgrind/memcheck.zig+2-2| ... | @@ -137,7 +137,7 @@ pub fn countLeaks() CountResult { | ... | @@ -137,7 +137,7 @@ pub fn countLeaks() CountResult { |
| 137 | return res; | 137 | return res; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | test "countLeaks" { | 140 | test countLeaks { |
| 141 | try testing.expectEqual( | 141 | try testing.expectEqual( |
| 142 | @as(CountResult, .{ | 142 | @as(CountResult, .{ |
| 143 | .leaked = 0, | 143 | .leaked = 0, |
| ... | @@ -167,7 +167,7 @@ pub fn countLeakBlocks() CountResult { | ... | @@ -167,7 +167,7 @@ pub fn countLeakBlocks() CountResult { |
| 167 | return res; | 167 | return res; |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | test "countLeakBlocks" { | 170 | test countLeakBlocks { |
| 171 | try testing.expectEqual( | 171 | try testing.expectEqual( |
| 172 | @as(CountResult, .{ | 172 | @as(CountResult, .{ |
| 173 | .leaked = 0, | 173 | .leaked = 0, |
lib/std/zig/ErrorBundle.zig+77-77| ... | @@ -642,96 +642,96 @@ pub const Wip = struct { | ... | @@ -642,96 +642,96 @@ pub const Wip = struct { |
| 642 | i += 1; | 642 | i += 1; |
| 643 | } | 643 | } |
| 644 | } | 644 | } |
| 645 | }; | ||
| 646 | 645 | ||
| 647 | test "addBundleAsRoots" { | 646 | test addBundleAsRoots { |
| 648 | var bundle = bundle: { | 647 | var bundle = bundle: { |
| 649 | var wip: ErrorBundle.Wip = undefined; | 648 | var wip: ErrorBundle.Wip = undefined; |
| 650 | try wip.init(std.testing.allocator); | 649 | try wip.init(std.testing.allocator); |
| 651 | errdefer wip.deinit(); | 650 | errdefer wip.deinit(); |
| 652 | 651 | ||
| 653 | var ref_traces: [3]ReferenceTrace = undefined; | 652 | var ref_traces: [3]ReferenceTrace = undefined; |
| 654 | for (&ref_traces, 0..) |*ref_trace, i| { | 653 | for (&ref_traces, 0..) |*ref_trace, i| { |
| 655 | if (i == ref_traces.len - 1) { | 654 | if (i == ref_traces.len - 1) { |
| 656 | // sentinel reference trace | 655 | // sentinel reference trace |
| 657 | ref_trace.* = .{ | 656 | ref_trace.* = .{ |
| 658 | .decl_name = 3, // signifies 3 hidden references | 657 | .decl_name = 3, // signifies 3 hidden references |
| 659 | .src_loc = .none, | 658 | .src_loc = .none, |
| 660 | }; | 659 | }; |
| 661 | } else { | 660 | } else { |
| 662 | ref_trace.* = .{ | 661 | ref_trace.* = .{ |
| 663 | .decl_name = try wip.addString("foo"), | 662 | .decl_name = try wip.addString("foo"), |
| 664 | .src_loc = try wip.addSourceLocation(.{ | 663 | .src_loc = try wip.addSourceLocation(.{ |
| 665 | .src_path = try wip.addString("foo"), | 664 | .src_path = try wip.addString("foo"), |
| 666 | .line = 1, | 665 | .line = 1, |
| 667 | .column = 2, | 666 | .column = 2, |
| 668 | .span_start = 3, | 667 | .span_start = 3, |
| 669 | .span_main = 4, | 668 | .span_main = 4, |
| 670 | .span_end = 5, | 669 | .span_end = 5, |
| 671 | .source_line = 0, | 670 | .source_line = 0, |
| 672 | }), | 671 | }), |
| 673 | }; | 672 | }; |
| 673 | } | ||
| 674 | } | 674 | } |
| 675 | } | ||
| 676 | 675 | ||
| 677 | const src_loc = try wip.addSourceLocation(.{ | 676 | const src_loc = try wip.addSourceLocation(.{ |
| 678 | .src_path = try wip.addString("foo"), | 677 | .src_path = try wip.addString("foo"), |
| 679 | .line = 1, | ||
| 680 | .column = 2, | ||
| 681 | .span_start = 3, | ||
| 682 | .span_main = 4, | ||
| 683 | .span_end = 5, | ||
| 684 | .source_line = try wip.addString("some source code"), | ||
| 685 | .reference_trace_len = ref_traces.len, | ||
| 686 | }); | ||
| 687 | for (&ref_traces) |ref_trace| { | ||
| 688 | try wip.addReferenceTrace(ref_trace); | ||
| 689 | } | ||
| 690 | |||
| 691 | try wip.addRootErrorMessage(ErrorMessage{ | ||
| 692 | .msg = try wip.addString("hello world"), | ||
| 693 | .src_loc = src_loc, | ||
| 694 | .notes_len = 1, | ||
| 695 | }); | ||
| 696 | const i = try wip.reserveNotes(1); | ||
| 697 | const note_index = @intFromEnum(wip.addErrorMessageAssumeCapacity(.{ | ||
| 698 | .msg = try wip.addString("this is a note"), | ||
| 699 | .src_loc = try wip.addSourceLocation(.{ | ||
| 700 | .src_path = try wip.addString("bar"), | ||
| 701 | .line = 1, | 678 | .line = 1, |
| 702 | .column = 2, | 679 | .column = 2, |
| 703 | .span_start = 3, | 680 | .span_start = 3, |
| 704 | .span_main = 4, | 681 | .span_main = 4, |
| 705 | .span_end = 5, | 682 | .span_end = 5, |
| 706 | .source_line = try wip.addString("another line of source"), | 683 | .source_line = try wip.addString("some source code"), |
| 707 | }), | 684 | .reference_trace_len = ref_traces.len, |
| 708 | })); | 685 | }); |
| 709 | wip.extra.items[i] = note_index; | 686 | for (&ref_traces) |ref_trace| { |
| 687 | try wip.addReferenceTrace(ref_trace); | ||
| 688 | } | ||
| 710 | 689 | ||
| 711 | break :bundle try wip.toOwnedBundle(""); | 690 | try wip.addRootErrorMessage(ErrorMessage{ |
| 712 | }; | 691 | .msg = try wip.addString("hello world"), |
| 713 | defer bundle.deinit(std.testing.allocator); | 692 | .src_loc = src_loc, |
| 693 | .notes_len = 1, | ||
| 694 | }); | ||
| 695 | const i = try wip.reserveNotes(1); | ||
| 696 | const note_index = @intFromEnum(wip.addErrorMessageAssumeCapacity(.{ | ||
| 697 | .msg = try wip.addString("this is a note"), | ||
| 698 | .src_loc = try wip.addSourceLocation(.{ | ||
| 699 | .src_path = try wip.addString("bar"), | ||
| 700 | .line = 1, | ||
| 701 | .column = 2, | ||
| 702 | .span_start = 3, | ||
| 703 | .span_main = 4, | ||
| 704 | .span_end = 5, | ||
| 705 | .source_line = try wip.addString("another line of source"), | ||
| 706 | }), | ||
| 707 | })); | ||
| 708 | wip.extra.items[i] = note_index; | ||
| 709 | |||
| 710 | break :bundle try wip.toOwnedBundle(""); | ||
| 711 | }; | ||
| 712 | defer bundle.deinit(std.testing.allocator); | ||
| 714 | 713 | ||
| 715 | const ttyconf: std.io.tty.Config = .no_color; | 714 | const ttyconf: std.io.tty.Config = .no_color; |
| 716 | 715 | ||
| 717 | var bundle_buf = std.ArrayList(u8).init(std.testing.allocator); | 716 | var bundle_buf = std.ArrayList(u8).init(std.testing.allocator); |
| 718 | defer bundle_buf.deinit(); | 717 | defer bundle_buf.deinit(); |
| 719 | try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_buf.writer()); | 718 | try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_buf.writer()); |
| 720 | 719 | ||
| 721 | var copy = copy: { | 720 | var copy = copy: { |
| 722 | var wip: ErrorBundle.Wip = undefined; | 721 | var wip: ErrorBundle.Wip = undefined; |
| 723 | try wip.init(std.testing.allocator); | 722 | try wip.init(std.testing.allocator); |
| 724 | errdefer wip.deinit(); | 723 | errdefer wip.deinit(); |
| 725 | 724 | ||
| 726 | try wip.addBundleAsRoots(bundle); | 725 | try wip.addBundleAsRoots(bundle); |
| 727 | 726 | ||
| 728 | break :copy try wip.toOwnedBundle(""); | 727 | break :copy try wip.toOwnedBundle(""); |
| 729 | }; | 728 | }; |
| 730 | defer copy.deinit(std.testing.allocator); | 729 | defer copy.deinit(std.testing.allocator); |
| 731 | 730 | ||
| 732 | var copy_buf = std.ArrayList(u8).init(std.testing.allocator); | 731 | var copy_buf = std.ArrayList(u8).init(std.testing.allocator); |
| 733 | defer copy_buf.deinit(); | 732 | defer copy_buf.deinit(); |
| 734 | try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_buf.writer()); | 733 | try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_buf.writer()); |
| 735 | 734 | ||
| 736 | try std.testing.expectEqualStrings(bundle_buf.items, copy_buf.items); | 735 | try std.testing.expectEqualStrings(bundle_buf.items, copy_buf.items); |
| 737 | } | 736 | } |
| 737 | }; |
lib/std/zig/primitives.zig+1-1| ... | @@ -51,7 +51,7 @@ pub fn isPrimitive(name: []const u8) bool { | ... | @@ -51,7 +51,7 @@ pub fn isPrimitive(name: []const u8) bool { |
| 51 | return true; | 51 | return true; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | test "isPrimitive" { | 54 | test isPrimitive { |
| 55 | const expect = std.testing.expect; | 55 | const expect = std.testing.expect; |
| 56 | try expect(!isPrimitive("")); | 56 | try expect(!isPrimitive("")); |
| 57 | try expect(!isPrimitive("_")); | 57 | try expect(!isPrimitive("_")); |
lib/std/zig/string_literal.zig+2-2| ... | @@ -148,7 +148,7 @@ pub fn parseEscapeSequence(slice: []const u8, offset: *usize) ParsedCharLiteral | ... | @@ -148,7 +148,7 @@ pub fn parseEscapeSequence(slice: []const u8, offset: *usize) ParsedCharLiteral |
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | test "parseCharLiteral" { | 151 | test parseCharLiteral { |
| 152 | try std.testing.expectEqual( | 152 | try std.testing.expectEqual( |
| 153 | ParsedCharLiteral{ .success = 'a' }, | 153 | ParsedCharLiteral{ .success = 'a' }, |
| 154 | parseCharLiteral("'a'"), | 154 | parseCharLiteral("'a'"), |
| ... | @@ -281,7 +281,7 @@ pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![] | ... | @@ -281,7 +281,7 @@ pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![] |
| 281 | } | 281 | } |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | test "parse" { | 284 | test parseAlloc { |
| 285 | const expect = std.testing.expect; | 285 | const expect = std.testing.expect; |
| 286 | const expectError = std.testing.expectError; | 286 | const expectError = std.testing.expectError; |
| 287 | const eql = std.mem.eql; | 287 | const eql = std.mem.eql; |