authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-13 15:56:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-21 14:11:46-07:00
log12191c8a220ca5594b278b5077bff98e8fecac08
treece6552d68161c363dd18826220febbaa7f733c62
parent5ae838d10596a272644da314937b01aa1a271a73

std: promote tests to doctests

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 {
147147/// See also: `isWhitespace`
148148pub const whitespace = [_]u8{ ' ', '\t', '\n', '\r', control_code.vt, control_code.ff };
149149
150test "whitespace" {
150test whitespace {
151151 for (whitespace) |char| try std.testing.expect(isWhitespace(char));
152152
153153 var i: u8 = 0;
......@@ -278,7 +278,7 @@ pub fn lowerString(output: []u8, ascii_string: []const u8) []u8 {
278278 return output[0..ascii_string.len];
279279}
280280
281test "lowerString" {
281test lowerString {
282282 var buf: [1024]u8 = undefined;
283283 const result = lowerString(&buf, "aBcDeFgHiJkLmNOPqrst0234+πŸ’©!");
284284 try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+πŸ’©!", result);
......@@ -291,7 +291,7 @@ pub fn allocLowerString(allocator: std.mem.Allocator, ascii_string: []const u8)
291291 return lowerString(result, ascii_string);
292292}
293293
294test "allocLowerString" {
294test allocLowerString {
295295 const result = try allocLowerString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+πŸ’©!");
296296 defer std.testing.allocator.free(result);
297297 try std.testing.expectEqualStrings("abcdefghijklmnopqrst0234+πŸ’©!", result);
......@@ -307,7 +307,7 @@ pub fn upperString(output: []u8, ascii_string: []const u8) []u8 {
307307 return output[0..ascii_string.len];
308308}
309309
310test "upperString" {
310test upperString {
311311 var buf: [1024]u8 = undefined;
312312 const result = upperString(&buf, "aBcDeFgHiJkLmNOPqrst0234+πŸ’©!");
313313 try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+πŸ’©!", result);
......@@ -320,7 +320,7 @@ pub fn allocUpperString(allocator: std.mem.Allocator, ascii_string: []const u8)
320320 return upperString(result, ascii_string);
321321}
322322
323test "allocUpperString" {
323test allocUpperString {
324324 const result = try allocUpperString(std.testing.allocator, "aBcDeFgHiJkLmNOPqrst0234+πŸ’©!");
325325 defer std.testing.allocator.free(result);
326326 try std.testing.expectEqualStrings("ABCDEFGHIJKLMNOPQRST0234+πŸ’©!", result);
......@@ -335,7 +335,7 @@ pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool {
335335 return true;
336336}
337337
338test "eqlIgnoreCase" {
338test eqlIgnoreCase {
339339 try std.testing.expect(eqlIgnoreCase("HElπŸ’©Lo!", "helπŸ’©lo!"));
340340 try std.testing.expect(!eqlIgnoreCase("hElLo!", "hello! "));
341341 try std.testing.expect(!eqlIgnoreCase("hElLo!", "helro!"));
......@@ -345,7 +345,7 @@ pub fn startsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
345345 return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[0..needle.len], needle);
346346}
347347
348test "startsWithIgnoreCase" {
348test startsWithIgnoreCase {
349349 try std.testing.expect(startsWithIgnoreCase("boB", "Bo"));
350350 try std.testing.expect(!startsWithIgnoreCase("Needle in hAyStAcK", "haystack"));
351351}
......@@ -354,7 +354,7 @@ pub fn endsWithIgnoreCase(haystack: []const u8, needle: []const u8) bool {
354354 return if (needle.len > haystack.len) false else eqlIgnoreCase(haystack[haystack.len - needle.len ..], needle);
355355}
356356
357test "endsWithIgnoreCase" {
357test endsWithIgnoreCase {
358358 try std.testing.expect(endsWithIgnoreCase("Needle in HaYsTaCk", "haystack"));
359359 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
360360}
......@@ -409,7 +409,7 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz
409409 }
410410}
411411
412test "indexOfIgnoreCase" {
412test indexOfIgnoreCase {
413413 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
414414 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
415415 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 {
16481648 try testPureBitSet(Set);
16491649}
16501650
1651test "IntegerBitSet" {
1651test IntegerBitSet {
16521652 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
16531653
16541654 try testStaticBitSet(IntegerBitSet(0));
......@@ -1661,7 +1661,7 @@ test "IntegerBitSet" {
16611661 try testStaticBitSet(IntegerBitSet(127));
16621662}
16631663
1664test "ArrayBitSet" {
1664test ArrayBitSet {
16651665 inline for (.{ 0, 1, 2, 31, 32, 33, 63, 64, 65, 254, 500, 3000 }) |size| {
16661666 try testStaticBitSet(ArrayBitSet(u8, size));
16671667 try testStaticBitSet(ArrayBitSet(u16, size));
......@@ -1671,7 +1671,7 @@ test "ArrayBitSet" {
16711671 }
16721672}
16731673
1674test "DynamicBitSetUnmanaged" {
1674test DynamicBitSetUnmanaged {
16751675 const allocator = std.testing.allocator;
16761676 var a = try DynamicBitSetUnmanaged.initEmpty(allocator, 300);
16771677 try testing.expectEqual(@as(usize, 0), a.count());
......@@ -1724,7 +1724,7 @@ test "DynamicBitSetUnmanaged" {
17241724 }
17251725}
17261726
1727test "DynamicBitSet" {
1727test DynamicBitSet {
17281728 const allocator = std.testing.allocator;
17291729 var a = try DynamicBitSet.initEmpty(allocator, 300);
17301730 try testing.expectEqual(@as(usize, 0), a.count());
......@@ -1765,7 +1765,7 @@ test "DynamicBitSet" {
17651765 }
17661766}
17671767
1768test "StaticBitSet" {
1768test StaticBitSet {
17691769 try testing.expectEqual(IntegerBitSet(0), StaticBitSet(0));
17701770 try testing.expectEqual(IntegerBitSet(5), StaticBitSet(5));
17711771 try testing.expectEqual(IntegerBitSet(@bitSizeOf(usize)), StaticBitSet(@bitSizeOf(usize)));
lib/std/bounded_array.zig+1-1
......@@ -287,7 +287,7 @@ pub fn BoundedArrayAligned(
287287 };
288288}
289289
290test "BoundedArray" {
290test BoundedArray {
291291 var a = try BoundedArray(u8, 64).init(32);
292292
293293 try testing.expectEqual(a.capacity(), 64);
lib/std/child_process.zig+3-3
......@@ -1231,7 +1231,7 @@ fn windowsCreateProcessSupportsExtension(ext: []const u16) ?CreateProcessSupport
12311231 return null;
12321232}
12331233
1234test "windowsCreateProcessSupportsExtension" {
1234test windowsCreateProcessSupportsExtension {
12351235 try std.testing.expectEqual(CreateProcessSupportedExtension.exe, windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e' }).?);
12361236 try std.testing.expect(windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e', 'c' }) == null);
12371237}
......@@ -1322,7 +1322,7 @@ pub fn argvToCommandLineWindows(
13221322 return try unicode.wtf8ToWtf16LeAllocZ(allocator, buf.items);
13231323}
13241324
1325test "argvToCommandLineWindows" {
1325test argvToCommandLineWindows {
13261326 const t = testArgvToCommandLineWindows;
13271327
13281328 try t(&.{
......@@ -1556,7 +1556,7 @@ pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const EnvMap) !
15561556 return envp_buf;
15571557}
15581558
1559test "createNullDelimitedEnvMap" {
1559test createNullDelimitedEnvMap {
15601560 const testing = std.testing;
15611561 const allocator = testing.allocator;
15621562 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 {
138138 @memset(@as([]volatile T, s), 0);
139139}
140140
141test "timingSafeEql" {
141test timingSafeEql {
142142 var a: [100]u8 = undefined;
143143 var b: [100]u8 = undefined;
144144 random.bytes(a[0..]);
......@@ -162,7 +162,7 @@ test "timingSafeEql (vectors)" {
162162 try testing.expect(timingSafeEql(@Vector(100, u8), v1, v3));
163163}
164164
165test "timingSafeCompare" {
165test timingSafeCompare {
166166 var a = [_]u8{10} ** 32;
167167 var b = [_]u8{10} ** 32;
168168 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq);
......@@ -195,7 +195,7 @@ test "timingSafe{Add,Sub}" {
195195 }
196196}
197197
198test "secureZero" {
198test secureZero {
199199 var a = [_]u8{0xfe} ** 8;
200200 var b = [_]u8{0xfe} ** 8;
201201
lib/std/debug.zig+2-2
......@@ -905,7 +905,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
905905 return null;
906906}
907907
908test "machoSearchSymbols" {
908test machoSearchSymbols {
909909 const symbols = [_]MachoSymbol{
910910 .{ .addr = 100, .strx = undefined, .size = undefined, .ofile = undefined },
911911 .{ .addr = 200, .strx = undefined, .size = undefined, .ofile = undefined },
......@@ -1504,7 +1504,7 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
15041504 }
15051505}
15061506
1507test "printLineFromFileAnyOs" {
1507test printLineFromFileAnyOs {
15081508 var output = std.ArrayList(u8).init(std.testing.allocator);
15091509 defer output.deinit();
15101510 const output_stream = output.writer();
lib/std/fifo.zig+1-1
......@@ -507,7 +507,7 @@ test "LinearFifo(u8, .Dynamic)" {
507507 }
508508}
509509
510test "LinearFifo" {
510test LinearFifo {
511511 inline for ([_]type{ u1, u8, u16, u64 }) |T| {
512512 inline for ([_]LinearFifoBufferType{ LinearFifoBufferType{ .Static = 32 }, .Slice, .Dynamic }) |bt| {
513513 const FifoType = LinearFifo(T, bt);
lib/std/fmt.zig+9-9
......@@ -1303,7 +1303,7 @@ pub fn fmtDuration(ns: u64) Formatter(formatDuration) {
13031303 return .{ .data = data };
13041304}
13051305
1306test "fmtDuration" {
1306test fmtDuration {
13071307 var buf: [24]u8 = undefined;
13081308 inline for (.{
13091309 .{ .s = "0ns", .d = 0 },
......@@ -1367,7 +1367,7 @@ pub fn fmtDurationSigned(ns: i64) Formatter(formatDurationSigned) {
13671367 return .{ .data = ns };
13681368}
13691369
1370test "fmtDurationSigned" {
1370test fmtDurationSigned {
13711371 var buf: [24]u8 = undefined;
13721372 inline for (.{
13731373 .{ .s = "0ns", .d = 0 },
......@@ -1497,7 +1497,7 @@ pub fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T {
14971497 return parseWithSign(T, buf, base, .pos);
14981498}
14991499
1500test "parseInt" {
1500test parseInt {
15011501 try std.testing.expect((try parseInt(i32, "-10", 10)) == -10);
15021502 try std.testing.expect((try parseInt(i32, "+10", 10)) == 10);
15031503 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!
16391639 return parseWithSign(T, buf, base, .pos);
16401640}
16411641
1642test "parseUnsigned" {
1642test parseUnsigned {
16431643 try std.testing.expect((try parseUnsigned(u16, "050124", 10)) == 50124);
16441644 try std.testing.expect((try parseUnsigned(u16, "65535", 10)) == 65535);
16451645 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 {
17131713 return math.mul(usize, number, multiplier);
17141714}
17151715
1716test "parseIntSizeSuffix" {
1716test parseIntSizeSuffix {
17171717 try std.testing.expect(try parseIntSizeSuffix("2", 10) == 2);
17181718 try std.testing.expect(try parseIntSizeSuffix("2B", 10) == 2);
17191719 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
17961796 return result[0 .. result.len - 1 :0];
17971797}
17981798
1799test "bufPrintInt" {
1799test bufPrintIntToSlice {
18001800 var buffer: [100]u8 = undefined;
18011801 const buf = buffer[0..];
18021802
......@@ -1830,7 +1830,7 @@ pub inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [cou
18301830 }
18311831}
18321832
1833test "comptimePrint" {
1833test comptimePrint {
18341834 @setEvalBranchQuota(2000);
18351835 try std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptimePrint("{}", .{100})));
18361836 try std.testing.expectEqualSlices(u8, "100", comptimePrint("{}", .{100}));
......@@ -2445,14 +2445,14 @@ pub fn hexToBytes(out: []u8, input: []const u8) ![]u8 {
24452445 return out[0 .. in_i / 2];
24462446}
24472447
2448test "bytesToHex" {
2448test bytesToHex {
24492449 const input = "input slice";
24502450 const encoded = bytesToHex(input, .lower);
24512451 var decoded: [input.len]u8 = undefined;
24522452 try std.testing.expectEqualSlices(u8, input, try hexToBytes(&decoded, &encoded));
24532453}
24542454
2455test "hexToBytes" {
2455test hexToBytes {
24562456 var buf: [32]u8 = undefined;
24572457 try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
24582458 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
6161 }
6262}
6363
64test "getAppDataDir" {
64test getAppDataDir {
6565 if (native_os == .wasi) return error.SkipZigTest;
6666
6767 // 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
180180 try testing.expectEqualSlices(u8, expected, if (zero) actual[0 .. actual.len - 1 :0] else actual);
181181}
182182
183test "join" {
183test join {
184184 {
185185 const actual: []u8 = try join(testing.allocator, &[_][]const u8{});
186186 defer testing.allocator.free(actual);
......@@ -303,7 +303,7 @@ pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
303303 return isAbsolutePosix(mem.sliceTo(path_c, 0));
304304}
305305
306test "isAbsoluteWindows" {
306test isAbsoluteWindows {
307307 try testIsAbsoluteWindows("", false);
308308 try testIsAbsoluteWindows("/", true);
309309 try testIsAbsoluteWindows("//", true);
......@@ -326,7 +326,7 @@ test "isAbsoluteWindows" {
326326 try testIsAbsoluteWindows("/usr/local", true);
327327}
328328
329test "isAbsolutePosix" {
329test isAbsolutePosix {
330330 try testIsAbsolutePosix("", false);
331331 try testIsAbsolutePosix("/home/foo", true);
332332 try testIsAbsolutePosix("/home/foo/..", true);
......@@ -400,7 +400,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
400400 return relative_path;
401401}
402402
403test "windowsParsePath" {
403test windowsParsePath {
404404 {
405405 const parsed = windowsParsePath("//a/b");
406406 try testing.expect(parsed.is_abs);
......@@ -884,7 +884,7 @@ pub fn dirnamePosix(path: []const u8) ?[]const u8 {
884884 return path[0..end_index];
885885}
886886
887test "dirnamePosix" {
887test dirnamePosix {
888888 try testDirnamePosix("/a/b/c", "/a/b");
889889 try testDirnamePosix("/a/b/c///", "/a/b");
890890 try testDirnamePosix("/a", "/");
......@@ -898,7 +898,7 @@ test "dirnamePosix" {
898898 try testDirnamePosix("a//", null);
899899}
900900
901test "dirnameWindows" {
901test dirnameWindows {
902902 try testDirnameWindows("c:\\", null);
903903 try testDirnameWindows("c:\\foo", "c:\\");
904904 try testDirnameWindows("c:\\foo\\", "c:\\");
......@@ -1011,7 +1011,7 @@ pub fn basenameWindows(path: []const u8) []const u8 {
10111011 return path[start_index + 1 .. end_index];
10121012}
10131013
1014test "basename" {
1014test basename {
10151015 try testBasename("", "");
10161016 try testBasename("/", "");
10171017 try testBasename("/dir/basename.ext", "basename.ext");
......@@ -1186,7 +1186,7 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11861186 return [_]u8{};
11871187}
11881188
1189test "relative" {
1189test relative {
11901190 try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
11911191 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
11921192 try testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");
......@@ -1271,7 +1271,7 @@ fn testExtension(path: []const u8, expected: []const u8) !void {
12711271 try testing.expectEqualStrings(expected, extension(path));
12721272}
12731273
1274test "extension" {
1274test extension {
12751275 try testExtension("", "");
12761276 try testExtension(".", "");
12771277 try testExtension("a.", ".");
......@@ -1328,7 +1328,7 @@ fn testStem(path: []const u8, expected: []const u8) !void {
13281328 try testing.expectEqualStrings(expected, stem(path));
13291329}
13301330
1331test "stem" {
1331test stem {
13321332 try testStem("hello/world/lib.tar.gz", "lib.tar");
13331333 try testStem("hello/world/lib.tar", "lib");
13341334 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 {
421421 return data.len;
422422}
423423
424test "null_writer" {
424test null_writer {
425425 null_writer.writeAll("yay" ** 10) catch |err| switch (err) {};
426426}
427427
lib/std/math.zig+90-70
......@@ -167,28 +167,51 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool {
167167 return @abs(x - y) <= @max(@abs(x), @abs(y)) * tolerance;
168168}
169169
170test "approxEqAbs and approxEqRel" {
170test approxEqAbs {
171171 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
172172 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);
176173 const min_value = comptime floatMin(T);
177174
178175 try testing.expect(approxEqAbs(T, 0.0, 0.0, eps_value));
179176 try testing.expect(approxEqAbs(T, -0.0, -0.0, eps_value));
180177 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));
183178 try testing.expect(!approxEqAbs(T, 1.0 + 2 * eps_value, 1.0, eps_value));
184179 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
200test 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));
185210 try testing.expect(!approxEqRel(T, 1.0, nan_value, sqrt_eps_value));
186211 try testing.expect(!approxEqRel(T, nan_value, nan_value, sqrt_eps_value));
187212 try testing.expect(approxEqRel(T, inf_value, inf_value, sqrt_eps_value));
188213 try testing.expect(approxEqRel(T, min_value, min_value, sqrt_eps_value));
189214 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));
192215 }
193216
194217 comptime {
......@@ -200,13 +223,8 @@ test "approxEqAbs and approxEqRel" {
200223 const eps_value = 1e-4;
201224 const sqrt_eps_value = sqrt(eps_value);
202225
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));
206226 try testing.expect(approxEqRel(comptime_float, 1.0, 1.0, sqrt_eps_value));
207227 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));
210228 }
211229}
212230
......@@ -310,7 +328,7 @@ pub fn radiansToDegrees(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime
310328 @compileError("Input must be float or a comptime number, or a vector of floats.");
311329}
312330
313test "radiansToDegrees" {
331test radiansToDegrees {
314332 const zero: f32 = 0;
315333 const half_pi: f32 = pi / 2.0;
316334 const neg_quart_pi: f32 = -pi / 4.0;
......@@ -345,7 +363,7 @@ pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime
345363 @compileError("Input must be float or a comptime number, or a vector of floats.");
346364}
347365
348test "degreesToRadians" {
366test degreesToRadians {
349367 const ninety: f32 = 90;
350368 const neg_two_seventy: f32 = -270;
351369 const three_sixty: f32 = 360;
......@@ -506,7 +524,7 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) {
506524 },
507525 }
508526}
509test "wrap" {
527test wrap {
510528 // Within range
511529 try testing.expect(wrap(@as(i32, -75), @as(i32, 180)) == -75);
512530 try testing.expect(wrap(@as(i32, -75), @as(i32, -180)) == -75);
......@@ -543,8 +561,7 @@ test "wrap" {
543561 var i: i32 = 1;
544562 _ = &i;
545563 try testing.expect(wrap(i, 10) == 1);
546}
547test wrap {
564
548565 const limit: i32 = 180;
549566 // Within range
550567 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
569586 assert(lower <= upper);
570587 return @max(lower, @min(val, upper));
571588}
572test "clamp" {
589test clamp {
573590 // Within range
574591 try testing.expect(std.math.clamp(@as(i32, -1), @as(i32, -4), @as(i32, 7)) == -1);
575592 // Below
......@@ -650,7 +667,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
650667 return a << casted_shift_amt;
651668}
652669
653test "shl" {
670test shl {
654671 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
655672 // https://github.com/ziglang/zig/issues/12012
656673 return error.SkipZigTest;
......@@ -695,7 +712,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
695712 return a >> casted_shift_amt;
696713}
697714
698test "shr" {
715test shr {
699716 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
700717 // https://github.com/ziglang/zig/issues/12012
701718 return error.SkipZigTest;
......@@ -741,7 +758,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
741758 }
742759}
743760
744test "rotr" {
761test rotr {
745762 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
746763 // https://github.com/ziglang/zig/issues/12012
747764 return error.SkipZigTest;
......@@ -787,7 +804,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
787804 }
788805}
789806
790test "rotl" {
807test rotl {
791808 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) {
792809 // https://github.com/ziglang/zig/issues/12012
793810 return error.SkipZigTest;
......@@ -850,7 +867,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
850867 return std.meta.Int(signedness, magnitude_bits);
851868}
852869
853test "IntFittingRange" {
870test IntFittingRange {
854871 try testing.expect(IntFittingRange(0, 0) == u0);
855872 try testing.expect(IntFittingRange(0, 1) == u1);
856873 try testing.expect(IntFittingRange(0, 2) == u2);
......@@ -918,7 +935,7 @@ pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
918935 return @divTrunc(numerator, denominator);
919936}
920937
921test "divTrunc" {
938test divTrunc {
922939 try testDivTrunc();
923940 try comptime testDivTrunc();
924941}
......@@ -942,7 +959,7 @@ pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
942959 return @divFloor(numerator, denominator);
943960}
944961
945test "divFloor" {
962test divFloor {
946963 try testDivFloor();
947964 try comptime testDivFloor();
948965}
......@@ -979,7 +996,7 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
979996 }
980997}
981998
982test "divCeil" {
999test divCeil {
9831000 try testDivCeil();
9841001 try comptime testDivCeil();
9851002}
......@@ -1023,7 +1040,7 @@ pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
10231040 return result;
10241041}
10251042
1026test "divExact" {
1043test divExact {
10271044 try testDivExact();
10281045 try comptime testDivExact();
10291046}
......@@ -1049,7 +1066,7 @@ pub fn mod(comptime T: type, numerator: T, denominator: T) !T {
10491066 return @mod(numerator, denominator);
10501067}
10511068
1052test "mod" {
1069test mod {
10531070 try testMod();
10541071 try comptime testMod();
10551072}
......@@ -1075,7 +1092,7 @@ pub fn rem(comptime T: type, numerator: T, denominator: T) !T {
10751092 return @rem(numerator, denominator);
10761093}
10771094
1078test "rem" {
1095test rem {
10791096 try testRem();
10801097 try comptime testRem();
10811098}
......@@ -1104,7 +1121,7 @@ pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {
11041121 return -@as(int, @intCast(x));
11051122}
11061123
1107test "negateCast" {
1124test negateCast {
11081125 try testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
11091126 try testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
11101127
......@@ -1129,7 +1146,7 @@ pub fn cast(comptime T: type, x: anytype) ?T {
11291146 }
11301147}
11311148
1132test "cast" {
1149test cast {
11331150 try testing.expect(cast(u8, 300) == null);
11341151 try testing.expect(cast(u8, @as(u32, 300)) == null);
11351152 try testing.expect(cast(i8, -200) == null);
......@@ -1188,7 +1205,7 @@ pub fn ByteAlignedInt(comptime T: type) type {
11881205 return extended_type;
11891206}
11901207
1191test "ByteAlignedInt" {
1208test ByteAlignedInt {
11921209 try testing.expect(ByteAlignedInt(u0) == u0);
11931210 try testing.expect(ByteAlignedInt(i0) == i0);
11941211 try testing.expect(ByteAlignedInt(u3) == u8);
......@@ -1226,7 +1243,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
12261243 return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value)));
12271244}
12281245
1229test "floorPowerOfTwo" {
1246test floorPowerOfTwo {
12301247 try testFloorPowerOfTwo();
12311248 try comptime testFloorPowerOfTwo();
12321249}
......@@ -1288,7 +1305,7 @@ pub fn ceilPowerOfTwoAssert(comptime T: type, value: T) T {
12881305 return ceilPowerOfTwo(T, value) catch unreachable;
12891306}
12901307
1291test "ceilPowerOfTwoPromote" {
1308test ceilPowerOfTwoPromote {
12921309 try testCeilPowerOfTwoPromote();
12931310 try comptime testCeilPowerOfTwoPromote();
12941311}
......@@ -1305,7 +1322,7 @@ fn testCeilPowerOfTwoPromote() !void {
13051322 try testing.expectEqual(@as(u5, 16), ceilPowerOfTwoPromote(u4, 9));
13061323}
13071324
1308test "ceilPowerOfTwo" {
1325test ceilPowerOfTwo {
13091326 try testCeilPowerOfTwo();
13101327 try comptime testCeilPowerOfTwo();
13111328}
......@@ -1398,7 +1415,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T {
13981415 }
13991416}
14001417
1401test "lossyCast" {
1418test lossyCast {
14021419 try testing.expect(lossyCast(i16, 70000.0) == @as(i16, 32767));
14031420 try testing.expect(lossyCast(u32, @as(i16, -255)) == @as(u32, 0));
14041421 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) {
14171434 return @mulAdd(Type, b - a, t, a);
14181435}
14191436
1420test "lerp" {
1437test lerp {
14211438 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884
14221439 if (builtin.zig_backend == .stage2_x86_64 and
14231440 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest;
......@@ -1483,7 +1500,7 @@ pub fn minInt(comptime T: type) comptime_int {
14831500 return -(1 << (bit_count - 1));
14841501}
14851502
1486test "minInt and maxInt" {
1503test maxInt {
14871504 try testing.expect(maxInt(u0) == 0);
14881505 try testing.expect(maxInt(u1) == 1);
14891506 try testing.expect(maxInt(u8) == 255);
......@@ -1500,7 +1517,9 @@ test "minInt and maxInt" {
15001517 try testing.expect(maxInt(i63) == 4611686018427387903);
15011518 try testing.expect(maxInt(i64) == 9223372036854775807);
15021519 try testing.expect(maxInt(i128) == 170141183460469231731687303715884105727);
1520}
15031521
1522test minInt {
15041523 try testing.expect(minInt(u0) == 0);
15051524 try testing.expect(minInt(u1) == 0);
15061525 try testing.expect(minInt(u8) == 0);
......@@ -1538,7 +1557,7 @@ pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(
15381557 return @as(ResultInt, a) * @as(ResultInt, b);
15391558}
15401559
1541test "mulWide" {
1560test mulWide {
15421561 try testing.expect(mulWide(u8, 5, 5) == 25);
15431562 try testing.expect(mulWide(i8, 5, -5) == -25);
15441563 try testing.expect(mulWide(u8, 100, 100) == 10000);
......@@ -1563,6 +1582,12 @@ pub const Order = enum {
15631582 };
15641583 }
15651584
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
15661591 pub fn compare(self: Order, op: CompareOperator) bool {
15671592 return switch (self) {
15681593 .lt => switch (op) {
......@@ -1591,6 +1616,18 @@ pub const Order = enum {
15911616 },
15921617 };
15931618 }
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 }
15941631};
15951632
15961633/// Given two numbers, this function returns the order they are with respect to each other.
......@@ -1633,6 +1670,15 @@ pub const CompareOperator = enum {
16331670 .neq => .neq,
16341671 };
16351672 }
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 }
16361682};
16371683
16381684/// 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 {
16491695 };
16501696}
16511697
1652test "compare between signed and unsigned" {
1698test compare {
16531699 try testing.expect(compare(@as(i8, -1), .lt, @as(u8, 255)));
16541700 try testing.expect(compare(@as(i8, 2), .gt, @as(u8, 1)));
16551701 try testing.expect(!compare(@as(i8, -1), .gte, @as(u8, 255)));
......@@ -1669,38 +1715,12 @@ test "compare between signed and unsigned" {
16691715 try testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1)));
16701716}
16711717
1672test "order" {
1718test order {
16731719 try testing.expect(order(0, 0) == .eq);
16741720 try testing.expect(order(1, 0) == .gt);
16751721 try testing.expect(order(-1, 0) == .lt);
16761722}
16771723
1678test "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
1684test "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
1695test "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
17041724/// Returns a mask of all ones if value is true,
17051725/// and a mask of all zeroes if value is false.
17061726/// Compiles to one instruction for register sized integers.
......@@ -1722,7 +1742,7 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
17221742 return -%@as(MaskInt, @intCast(@intFromBool(value)));
17231743}
17241744
1725test "boolMask" {
1745test boolMask {
17261746 const runTest = struct {
17271747 fn runTest() !void {
17281748 try testing.expectEqual(@as(u1, 0), boolMask(u1, false));
......@@ -1870,7 +1890,7 @@ fn testSign() !void {
18701890 try std.testing.expectEqual(0.0, sign(0.0));
18711891}
18721892
1873test "sign" {
1893test sign {
18741894 if (builtin.zig_backend == .stage2_llvm) {
18751895 // https://github.com/ziglang/zig/issues/12012
18761896 return error.SkipZigTest;
lib/std/mem.zig+66-64
......@@ -306,7 +306,7 @@ pub fn zeroes(comptime T: type) T {
306306 }
307307}
308308
309test "zeroes" {
309test zeroes {
310310 const C_struct = extern struct {
311311 x: u32,
312312 y: u32 align(128),
......@@ -475,7 +475,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
475475 }
476476}
477477
478test "zeroInit" {
478test zeroInit {
479479 const I = struct {
480480 d: f64,
481481 };
......@@ -606,16 +606,19 @@ pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order
606606 return math.order(lhs[i], rhs[i]);
607607}
608608
609test "order and orderZ" {
609test order {
610610 try testing.expect(order(u8, "abcd", "bee") == .lt);
611 try testing.expect(orderZ(u8, "abcd", "bee") == .lt);
612611 try testing.expect(order(u8, "abc", "abc") == .eq);
613 try testing.expect(orderZ(u8, "abc", "abc") == .eq);
614612 try testing.expect(order(u8, "abc", "abc0") == .lt);
615 try testing.expect(orderZ(u8, "abc", "abc0") == .lt);
616613 try testing.expect(order(u8, "", "") == .eq);
617 try testing.expect(orderZ(u8, "", "") == .eq);
618614 try testing.expect(order(u8, "", "a") == .lt);
615}
616
617test 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);
619622 try testing.expect(orderZ(u8, "", "a") == .lt);
620623}
621624
......@@ -624,7 +627,7 @@ pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool {
624627 return order(T, lhs, rhs) == .lt;
625628}
626629
627test "lessThan" {
630test lessThan {
628631 try testing.expect(lessThan(u8, "abcd", "bee"));
629632 try testing.expect(!lessThan(u8, "abc", "abc"));
630633 try testing.expect(lessThan(u8, "abc", "abc0"));
......@@ -726,7 +729,7 @@ pub fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize {
726729 return if (a.len == b.len) null else shortest;
727730}
728731
729test "indexOfDiff" {
732test indexOfDiff {
730733 try testing.expectEqual(indexOfDiff(u8, "one", "one"), null);
731734 try testing.expectEqual(indexOfDiff(u8, "one two", "one"), 3);
732735 try testing.expectEqual(indexOfDiff(u8, "one", "one two"), 3);
......@@ -759,7 +762,7 @@ fn Span(comptime T: type) type {
759762 @compileError("invalid type given to std.mem.span: " ++ @typeName(T));
760763}
761764
762test "Span" {
765test Span {
763766 try testing.expect(Span([*:1]u16) == [:1]u16);
764767 try testing.expect(Span(?[*:1]u16) == ?[:1]u16);
765768 try testing.expect(Span([*:1]const u8) == [:1]const u8);
......@@ -793,7 +796,7 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
793796 }
794797}
795798
796test "span" {
799test span {
797800 var array: [5]u16 = [_]u16{ 1, 2, 3, 4, 5 };
798801 const ptr = @as([*:3]u16, array[0..2 :3]);
799802 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(
877880 }
878881}
879882
880test "sliceTo" {
883test sliceTo {
881884 try testing.expectEqualSlices(u8, "aoeu", sliceTo("aoeu", 0));
882885
883886 {
......@@ -963,7 +966,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
963966 @compileError("invalid type given to std.mem.sliceTo: " ++ @typeName(@TypeOf(ptr)));
964967}
965968
966test "lenSliceTo" {
969test lenSliceTo {
967970 try testing.expect(lenSliceTo("aoeu", 0) == 4);
968971
969972 {
......@@ -1018,7 +1021,7 @@ pub fn len(value: anytype) usize {
10181021 }
10191022}
10201023
1021test "len" {
1024test len {
10221025 var array: [5]u16 = [_]u16{ 1, 2, 0, 4, 5 };
10231026 const ptr = @as([*:4]u16, array[0..3 :4]);
10241027 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
11571160 return slice[begin..end];
11581161}
11591162
1160test "trim" {
1163test trim {
11611164 try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n"));
11621165 try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n"));
11631166 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,
12401243 return null;
12411244}
12421245
1243test "indexOfScalarPos" {
1246test indexOfScalarPos {
12441247 const Types = [_]type{ u8, u16, u32, u64 };
12451248
12461249 inline for (Types) |T| {
......@@ -1316,7 +1319,7 @@ pub fn indexOfNonePos(comptime T: type, slice: []const T, start_index: usize, va
13161319 return null;
13171320}
13181321
1319test "indexOfNone" {
1322test indexOfNone {
13201323 try testing.expect(indexOfNone(u8, "abc123", "123").? == 0);
13211324 try testing.expect(lastIndexOfNone(u8, "abc123", "123").? == 2);
13221325 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
14601463 return null;
14611464}
14621465
1463test "indexOf" {
1466test indexOf {
14641467 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
14651468 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
14661469 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 {
15331536 return found;
15341537}
15351538
1536test "count" {
1539test count {
15371540 try testing.expect(count(u8, "", "h") == 0);
15381541 try testing.expect(count(u8, "h", "h") == 1);
15391542 try testing.expect(count(u8, "hh", "h") == 2);
......@@ -1565,7 +1568,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
15651568 return false;
15661569}
15671570
1568test "containsAtLeast" {
1571test containsAtLeast {
15691572 try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
15701573 try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
15711574 try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
......@@ -1698,6 +1701,9 @@ test readInt {
16981701
16991702 try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3);
17001703 try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4);
1704
1705 try moreReadIntTests();
1706 try comptime moreReadIntTests();
17011707}
17021708
17031709fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T {
......@@ -2027,7 +2033,7 @@ pub fn byteSwapAllFields(comptime S: type, ptr: *S) void {
20272033 }
20282034}
20292035
2030test "byteSwapAllFields" {
2036test byteSwapAllFields {
20312037 const T = extern struct {
20322038 f0: u8,
20332039 f1: u16,
......@@ -2136,7 +2142,7 @@ pub fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIt
21362142 };
21372143}
21382144
2139test "tokenizeScalar" {
2145test tokenizeScalar {
21402146 var it = tokenizeScalar(u8, " abc def ghi ", ' ');
21412147 try testing.expect(eql(u8, it.next().?, "abc"));
21422148 try testing.expect(eql(u8, it.peek().?, "def"));
......@@ -2177,7 +2183,7 @@ test "tokenizeScalar" {
21772183 try testing.expect(it16.next() == null);
21782184}
21792185
2180test "tokenizeAny" {
2186test tokenizeAny {
21812187 var it = tokenizeAny(u8, "a|b,c/d e", " /,|");
21822188 try testing.expect(eql(u8, it.next().?, "a"));
21832189 try testing.expect(eql(u8, it.peek().?, "b"));
......@@ -2205,7 +2211,7 @@ test "tokenizeAny" {
22052211 try testing.expect(it16.next() == null);
22062212}
22072213
2208test "tokenizeSequence" {
2214test tokenizeSequence {
22092215 var it = tokenizeSequence(u8, "a<>b<><>c><>d><", "<>");
22102216 try testing.expectEqualStrings("a", it.next().?);
22112217 try testing.expectEqualStrings("b", it.peek().?);
......@@ -2334,7 +2340,7 @@ pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitItera
23342340 };
23352341}
23362342
2337test "splitScalar" {
2343test splitScalar {
23382344 var it = splitScalar(u8, "abc|def||ghi", '|');
23392345 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
23402346 try testing.expectEqualSlices(u8, it.first(), "abc");
......@@ -2377,7 +2383,7 @@ test "splitScalar" {
23772383 try testing.expect(it16.next() == null);
23782384}
23792385
2380test "splitSequence" {
2386test splitSequence {
23812387 var it = splitSequence(u8, "a, b ,, c, d, e", ", ");
23822388 try testing.expectEqualSlices(u8, it.first(), "a");
23832389 try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e");
......@@ -2400,7 +2406,7 @@ test "splitSequence" {
24002406 try testing.expect(it16.next() == null);
24012407}
24022408
2403test "splitAny" {
2409test splitAny {
24042410 var it = splitAny(u8, "a,b, c d e", ", ");
24052411 try testing.expectEqualSlices(u8, it.first(), "a");
24062412 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
25362542 };
25372543}
25382544
2539test "splitBackwardsScalar" {
2545test splitBackwardsScalar {
25402546 var it = splitBackwardsScalar(u8, "abc|def||ghi", '|');
25412547 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
25422548 try testing.expectEqualSlices(u8, it.first(), "ghi");
......@@ -2575,7 +2581,7 @@ test "splitBackwardsScalar" {
25752581 try testing.expect(it16.next() == null);
25762582}
25772583
2578test "splitBackwardsSequence" {
2584test splitBackwardsSequence {
25792585 var it = splitBackwardsSequence(u8, "a, b ,, c, d, e", ", ");
25802586 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e");
25812587 try testing.expectEqualSlices(u8, it.first(), "e");
......@@ -2608,7 +2614,7 @@ test "splitBackwardsSequence" {
26082614 try testing.expect(it16.next() == null);
26092615}
26102616
2611test "splitBackwardsAny" {
2617test splitBackwardsAny {
26122618 var it = splitBackwardsAny(u8, "a,b, c d e", ", ");
26132619 try testing.expectEqualSlices(u8, it.rest(), "a,b, c d e");
26142620 try testing.expectEqualSlices(u8, it.first(), "e");
......@@ -2715,7 +2721,7 @@ pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize)
27152721 };
27162722}
27172723
2718test "window" {
2724test window {
27192725 {
27202726 // moving average size 3
27212727 var it = window(u8, "abcdefg", 3, 1);
......@@ -2841,7 +2847,7 @@ pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
28412847 return if (needle.len > haystack.len) false else eql(T, haystack[0..needle.len], needle);
28422848}
28432849
2844test "startsWith" {
2850test startsWith {
28452851 try testing.expect(startsWith(u8, "Bob", "Bo"));
28462852 try testing.expect(!startsWith(u8, "Needle in haystack", "haystack"));
28472853}
......@@ -2850,7 +2856,7 @@ pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool {
28502856 return if (needle.len > haystack.len) false else eql(T, haystack[haystack.len - needle.len ..], needle);
28512857}
28522858
2853test "endsWith" {
2859test endsWith {
28542860 try testing.expect(endsWith(u8, "Needle in haystack", "haystack"));
28552861 try testing.expect(!endsWith(u8, "Bob", "Bo"));
28562862}
......@@ -3086,7 +3092,7 @@ fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []con
30863092 return buf;
30873093}
30883094
3089test "join" {
3095test join {
30903096 {
30913097 const str = try join(testing.allocator, ",", &[_][]const u8{});
30923098 defer testing.allocator.free(str);
......@@ -3109,7 +3115,7 @@ test "join" {
31093115 }
31103116}
31113117
3112test "joinZ" {
3118test joinZ {
31133119 {
31143120 const str = try joinZ(testing.allocator, ",", &[_][]const u8{});
31153121 defer testing.allocator.free(str);
......@@ -3181,7 +3187,7 @@ pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []con
31813187 return buf;
31823188}
31833189
3184test "concat" {
3190test concat {
31853191 {
31863192 const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" });
31873193 defer testing.allocator.free(str);
......@@ -3219,17 +3225,13 @@ test "concat" {
32193225 }
32203226}
32213227
3222test "testStringEquality" {
3228test eql {
32233229 try testing.expect(eql(u8, "abcd", "abcd"));
32243230 try testing.expect(!eql(u8, "abcdef", "abZdef"));
32253231 try testing.expect(!eql(u8, "abcdefg", "abcdef"));
32263232}
32273233
3228test "testReadInt" {
3229 try testReadIntImpl();
3230 try comptime testReadIntImpl();
3231}
3232fn testReadIntImpl() !void {
3234fn moreReadIntTests() !void {
32333235 {
32343236 const bytes = [_]u8{
32353237 0x12,
......@@ -3287,7 +3289,7 @@ pub fn min(comptime T: type, slice: []const T) T {
32873289 return best;
32883290}
32893291
3290test "min" {
3292test min {
32913293 try testing.expectEqual(min(u8, "abcdefg"), 'a');
32923294 try testing.expectEqual(min(u8, "bcdefga"), 'a');
32933295 try testing.expectEqual(min(u8, "a"), 'a');
......@@ -3304,7 +3306,7 @@ pub fn max(comptime T: type, slice: []const T) T {
33043306 return best;
33053307}
33063308
3307test "max" {
3309test max {
33083310 try testing.expectEqual(max(u8, "abcdefg"), 'g');
33093311 try testing.expectEqual(max(u8, "gabcdef"), 'g');
33103312 try testing.expectEqual(max(u8, "g"), 'g');
......@@ -3357,7 +3359,7 @@ pub fn indexOfMin(comptime T: type, slice: []const T) usize {
33573359 return index;
33583360}
33593361
3360test "indexOfMin" {
3362test indexOfMin {
33613363 try testing.expectEqual(indexOfMin(u8, "abcdefg"), 0);
33623364 try testing.expectEqual(indexOfMin(u8, "bcdefga"), 6);
33633365 try testing.expectEqual(indexOfMin(u8, "a"), 0);
......@@ -3378,7 +3380,7 @@ pub fn indexOfMax(comptime T: type, slice: []const T) usize {
33783380 return index;
33793381}
33803382
3381test "indexOfMax" {
3383test indexOfMax {
33823384 try testing.expectEqual(indexOfMax(u8, "abcdefg"), 6);
33833385 try testing.expectEqual(indexOfMax(u8, "gabcdef"), 0);
33843386 try testing.expectEqual(indexOfMax(u8, "a"), 0);
......@@ -3406,7 +3408,7 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { usize, usize }
34063408 return .{ minIdx, maxIdx };
34073409}
34083410
3409test "indexOfMinMax" {
3411test indexOfMinMax {
34103412 try testing.expectEqual(.{ 0, 6 }, indexOfMinMax(u8, "abcdefg"));
34113413 try testing.expectEqual(.{ 1, 0 }, indexOfMinMax(u8, "gabcdef"));
34123414 try testing.expectEqual(.{ 0, 0 }, indexOfMinMax(u8, "a"));
......@@ -3427,7 +3429,7 @@ pub fn reverse(comptime T: type, items: []T) void {
34273429 }
34283430}
34293431
3430test "reverse" {
3432test reverse {
34313433 var arr = [_]i32{ 5, 3, 1, 2, 4 };
34323434 reverse(i32, arr[0..]);
34333435
......@@ -3488,7 +3490,7 @@ pub fn reverseIterator(slice: anytype) ReverseIterator(@TypeOf(slice)) {
34883490 return .{ .ptr = slice.ptr, .index = slice.len };
34893491}
34903492
3491test "reverseIterator" {
3493test reverseIterator {
34923494 {
34933495 var it = reverseIterator("abc");
34943496 try testing.expectEqual(@as(?u8, 'c'), it.next());
......@@ -3546,7 +3548,7 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
35463548 reverse(T, items);
35473549}
35483550
3549test "rotate" {
3551test rotate {
35503552 var arr = [_]i32{ 5, 3, 1, 2, 4 };
35513553 rotate(i32, arr[0..], 2);
35523554
......@@ -3580,7 +3582,7 @@ pub fn replace(comptime T: type, input: []const T, needle: []const T, replacemen
35803582 return replacements;
35813583}
35823584
3583test "replace" {
3585test replace {
35843586 var output: [29]u8 = undefined;
35853587 var replacements = replace(u8, "All your base are belong to us", "base", "Zig", output[0..]);
35863588 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 {
36433645 defer std.testing.allocator.free(mutable);
36443646 try testing.expect(std.mem.eql(u8, collapseRepeats(u8, mutable, elem), expected));
36453647}
3646test "collapseRepeats" {
3648test collapseRepeats {
36473649 try testCollapseRepeats("", '/', "");
36483650 try testCollapseRepeats("a", '/', "a");
36493651 try testCollapseRepeats("/", '/', "/");
......@@ -3677,7 +3679,7 @@ pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, re
36773679 return size;
36783680}
36793681
3680test "replacementSize" {
3682test replacementSize {
36813683 try testing.expect(replacementSize(u8, "All your base are belong to us", "base", "Zig") == 29);
36823684 try testing.expect(replacementSize(u8, "Favor reading code over writing code.", "code", "") == 29);
36833685 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
36973699 return output;
36983700}
36993701
3700test "replaceOwned" {
3702test replaceOwned {
37013703 const gpa = std.testing.allocator;
37023704
37033705 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) {
38013803 return @alignCast(ptr + adjust_off);
38023804}
38033805
3804test "alignPointer" {
3806test alignPointer {
38053807 const S = struct {
38063808 fn checkAlign(comptime T: type, base: usize, align_to: usize, expected: usize) !void {
38073809 const ptr: T = @ptrFromInt(base);
......@@ -3850,7 +3852,7 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
38503852 return @ptrCast(@alignCast(ptr));
38513853}
38523854
3853test "asBytes" {
3855test asBytes {
38543856 const deadbeef = @as(u32, 0xDEADBEEF);
38553857 const deadbeef_bytes = switch (native_endian) {
38563858 .big => "\xDE\xAD\xBE\xEF",
......@@ -3910,7 +3912,7 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
39103912 return asBytes(&value).*;
39113913}
39123914
3913test "toBytes" {
3915test toBytes {
39143916 var my_bytes = toBytes(@as(u32, 0x12345678));
39153917 switch (native_endian) {
39163918 .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,
39343936 return @ptrCast(bytes);
39353937}
39363938
3937test "bytesAsValue" {
3939test bytesAsValue {
39383940 const deadbeef = @as(u32, 0xDEADBEEF);
39393941 const deadbeef_bytes = switch (native_endian) {
39403942 .big => "\xDE\xAD\xBE\xEF",
......@@ -3993,7 +3995,7 @@ test "bytesAsValue preserves pointer attributes" {
39933995pub fn bytesToValue(comptime T: type, bytes: anytype) T {
39943996 return bytesAsValue(T, bytes).*;
39953997}
3996test "bytesToValue" {
3998test bytesToValue {
39973999 const deadbeef_bytes = switch (native_endian) {
39984000 .big => "\xDE\xAD\xBE\xEF",
39994001 .little => "\xEF\xBE\xAD\xDE",
......@@ -4021,7 +4023,7 @@ pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T,
40214023 return @as(cast_target, @ptrCast(bytes))[0..@divExact(bytes.len, @sizeOf(T))];
40224024}
40234025
4024test "bytesAsSlice" {
4026test bytesAsSlice {
40254027 {
40264028 const bytes = [_]u8{ 0xDE, 0xAD, 0xBE, 0xEF };
40274029 const slice = bytesAsSlice(u16, bytes[0..]);
......@@ -4110,7 +4112,7 @@ pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) {
41104112 return @as(cast_target, @ptrCast(slice))[0 .. slice.len * @sizeOf(std.meta.Elem(Slice))];
41114113}
41124114
4113test "sliceAsBytes" {
4115test sliceAsBytes {
41144116 const bytes = [_]u16{ 0xDEAD, 0xBEEF };
41154117 const slice = sliceAsBytes(bytes[0..]);
41164118 try testing.expect(slice.len == 4);
......@@ -4268,7 +4270,7 @@ fn doNotOptimizeAwayC(ptr: anytype) void {
42684270 dest.* = 0;
42694271}
42704272
4271test "doNotOptimizeAway" {
4273test doNotOptimizeAway {
42724274 comptime doNotOptimizeAway("test");
42734275
42744276 doNotOptimizeAway(null);
......@@ -4293,7 +4295,7 @@ test "doNotOptimizeAway" {
42934295 doNotOptimizeAway(@as(std.builtin.Endian, .little));
42944296}
42954297
4296test "alignForward" {
4298test alignForward {
42974299 try testing.expect(alignForward(usize, 1, 1) == 1);
42984300 try testing.expect(alignForward(usize, 2, 1) == 2);
42994301 try testing.expect(alignForward(usize, 1, 2) == 2);
......@@ -4362,7 +4364,7 @@ pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
43624364 return alignBackward(T, addr, alignment) == addr;
43634365}
43644366
4365test "isAligned" {
4367test isAligned {
43664368 try testing.expect(isAligned(0, 4));
43674369 try testing.expect(isAligned(1, 1));
43684370 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 {
132132 };
133133}
134134
135test "TrailerFlags" {
135test TrailerFlags {
136136 const Flags = TrailerFlags(struct {
137137 a: i32,
138138 b: bool,
lib/std/os/windows.zig+3-3
......@@ -1379,7 +1379,7 @@ pub fn GetFinalPathNameByHandle(
13791379 }
13801380}
13811381
1382test "GetFinalPathNameByHandle" {
1382test GetFinalPathNameByHandle {
13831383 if (builtin.os.tag != .windows)
13841384 return;
13851385
......@@ -2601,7 +2601,7 @@ pub fn ntToWin32Namespace(path: []const u16) !PathSpace {
26012601 }
26022602}
26032603
2604test "ntToWin32Namespace" {
2604test ntToWin32Namespace {
26052605 const L = std.unicode.utf8ToUtf16LeStringLiteral;
26062606
26072607 try testNtToWin32Namespace(L("UNC"), L("\\??\\UNC"));
......@@ -3539,7 +3539,7 @@ pub const GUID = extern struct {
35393539 }
35403540};
35413541
3542test "GUID" {
3542test GUID {
35433543 try std.testing.expectEqual(
35443544 GUID{
35453545 .Data1 = 0x01234567,
lib/std/process.zig+3-3
......@@ -215,7 +215,7 @@ pub const EnvMap = struct {
215215 }
216216};
217217
218test "EnvMap" {
218test EnvMap {
219219 var env = EnvMap.init(testing.allocator);
220220 defer env.deinit();
221221
......@@ -377,7 +377,7 @@ pub fn getEnvMap(allocator: Allocator) GetEnvMapError!EnvMap {
377377 }
378378}
379379
380test "getEnvMap" {
380test getEnvMap {
381381 var env = try getEnvMap(testing.allocator);
382382 defer env.deinit();
383383}
......@@ -1181,7 +1181,7 @@ pub fn argsFree(allocator: Allocator, args_alloc: []const [:0]u8) void {
11811181 return allocator.free(aligned_allocated_buf);
11821182}
11831183
1184test "ArgIteratorWindows" {
1184test ArgIteratorWindows {
11851185 const t = testArgIteratorWindows;
11861186
11871187 try t(
lib/std/sort.zig+9-9
......@@ -430,7 +430,7 @@ pub fn binarySearch(
430430 return null;
431431}
432432
433test "binarySearch" {
433test binarySearch {
434434 const S = struct {
435435 fn order_u32(context: void, lhs: u32, rhs: u32) math.Order {
436436 _ = context;
......@@ -537,7 +537,7 @@ pub fn lowerBound(
537537 return left;
538538}
539539
540test "lowerBound" {
540test lowerBound {
541541 const S = struct {
542542 fn lower_u32(context: void, lhs: u32, rhs: u32) bool {
543543 _ = context;
......@@ -627,7 +627,7 @@ pub fn upperBound(
627627 return left;
628628}
629629
630test "upperBound" {
630test upperBound {
631631 const S = struct {
632632 fn lower_u32(context: void, lhs: u32, rhs: u32) bool {
633633 _ = context;
......@@ -712,7 +712,7 @@ pub fn equalRange(
712712 };
713713}
714714
715test "equalRange" {
715test equalRange {
716716 const S = struct {
717717 fn lower_u32(context: void, lhs: u32, rhs: u32) bool {
718718 _ = context;
......@@ -792,7 +792,7 @@ pub fn argMin(
792792 return smallest_index;
793793}
794794
795test "argMin" {
795test argMin {
796796 try testing.expectEqual(@as(?usize, null), argMin(i32, &[_]i32{}, {}, asc_i32));
797797 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{1}, {}, asc_i32));
798798 try testing.expectEqual(@as(?usize, 0), argMin(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
......@@ -812,7 +812,7 @@ pub fn min(
812812 return items[i];
813813}
814814
815test "min" {
815test min {
816816 try testing.expectEqual(@as(?i32, null), min(i32, &[_]i32{}, {}, asc_i32));
817817 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{1}, {}, asc_i32));
818818 try testing.expectEqual(@as(?i32, 1), min(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
......@@ -844,7 +844,7 @@ pub fn argMax(
844844 return biggest_index;
845845}
846846
847test "argMax" {
847test argMax {
848848 try testing.expectEqual(@as(?usize, null), argMax(i32, &[_]i32{}, {}, asc_i32));
849849 try testing.expectEqual(@as(?usize, 0), argMax(i32, &[_]i32{1}, {}, asc_i32));
850850 try testing.expectEqual(@as(?usize, 4), argMax(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
......@@ -864,7 +864,7 @@ pub fn max(
864864 return items[i];
865865}
866866
867test "max" {
867test max {
868868 try testing.expectEqual(@as(?i32, null), max(i32, &[_]i32{}, {}, asc_i32));
869869 try testing.expectEqual(@as(?i32, 1), max(i32, &[_]i32{1}, {}, asc_i32));
870870 try testing.expectEqual(@as(?i32, 5), max(i32, &[_]i32{ 1, 2, 3, 4, 5 }, {}, asc_i32));
......@@ -890,7 +890,7 @@ pub fn isSorted(
890890 return true;
891891}
892892
893test "isSorted" {
893test isSorted {
894894 try testing.expect(isSorted(i32, &[_]i32{}, {}, asc_i32));
895895 try testing.expect(isSorted(i32, &[_]i32{10}, {}, asc_i32));
896896 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 {
676676 return path[i..];
677677}
678678
679test "stripComponents" {
679test stripComponents {
680680 const expectEqualStrings = testing.expectEqualStrings;
681681 try expectEqualStrings("a/b/c", stripComponents("a/b/c", 0));
682682 try expectEqualStrings("b/c", stripComponents("a/b/c", 1));
......@@ -685,7 +685,7 @@ test "stripComponents" {
685685 try expectEqualStrings("", stripComponents("a/b/c", 4));
686686}
687687
688test "PaxIterator" {
688test PaxIterator {
689689 const Attr = struct {
690690 kind: PaxAttributeKind,
691691 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
242242 }
243243}
244244
245test "expectApproxEqAbs" {
245test expectApproxEqAbs {
246246 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
247247 const pos_x: T = 12.0;
248248 const pos_y: T = 12.06;
......@@ -278,7 +278,7 @@ fn expectApproxEqRelInner(comptime T: type, expected: T, actual: T, tolerance: T
278278 }
279279}
280280
281test "expectApproxEqRel" {
281test expectApproxEqRel {
282282 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
283283 const eps_value = comptime math.floatEps(T);
284284 const sqrt_eps_value = comptime @sqrt(eps_value);
lib/std/time.zig+3-3
......@@ -53,7 +53,7 @@ pub fn sleep(nanoseconds: u64) void {
5353 posix.nanosleep(s, ns);
5454}
5555
56test "sleep" {
56test sleep {
5757 sleep(1);
5858}
5959
......@@ -123,7 +123,7 @@ pub fn nanoTimestamp() i128 {
123123 }
124124}
125125
126test "timestamp" {
126test milliTimestamp {
127127 const margin = ns_per_ms * 50;
128128
129129 const time_0 = milliTimestamp();
......@@ -327,7 +327,7 @@ pub const Timer = struct {
327327 }
328328};
329329
330test "Timer + Instant" {
330test Timer {
331331 const margin = ns_per_ms * 150;
332332
333333 var timer = try Timer.start();
lib/std/time/epoch.zig+1-1
......@@ -53,7 +53,7 @@ pub fn isLeapYear(year: Year) bool {
5353 return (0 == @mod(year, 400));
5454}
5555
56test "isLeapYear" {
56test isLeapYear {
5757 try testing.expectEqual(false, isLeapYear(2095));
5858 try testing.expectEqual(true, isLeapYear(2096));
5959 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) {
907907 return .{ .data = utf8 };
908908}
909909
910test "fmtUtf8" {
910test fmtUtf8 {
911911 const expectFmt = testing.expectFmt;
912912 try expectFmt("", "{}", .{fmtUtf8("")});
913913 try expectFmt("foo", "{}", .{fmtUtf8("foo")});
......@@ -1249,7 +1249,7 @@ pub fn utf8ToUtf16LeImpl(utf16le: []u16, utf8: []const u8, comptime surrogates:
12491249 return dest_index;
12501250}
12511251
1252test "utf8ToUtf16Le" {
1252test utf8ToUtf16Le {
12531253 var utf16le: [128]u16 = undefined;
12541254 {
12551255 const length = try utf8ToUtf16Le(utf16le[0..], "𐐷");
......@@ -1430,7 +1430,7 @@ pub fn fmtUtf16Le(utf16le: []const u16) std.fmt.Formatter(formatUtf16Le) {
14301430 return .{ .data = utf16le };
14311431}
14321432
1433test "fmtUtf16Le" {
1433test fmtUtf16Le {
14341434 const expectFmt = testing.expectFmt;
14351435 try expectFmt("", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral(""))});
14361436 try expectFmt("foo", "{}", .{fmtUtf16Le(utf8ToUtf16LeStringLiteral("foo"))});
......@@ -1443,7 +1443,7 @@ test "fmtUtf16Le" {
14431443 try expectFmt("ξ€€", "{}", .{fmtUtf16Le(&[_]u16{mem.readInt(u16, "\x00\xe0", native_endian)})});
14441444}
14451445
1446test "utf8ToUtf16LeStringLiteral" {
1446test utf8ToUtf16LeStringLiteral {
14471447 {
14481448 const bytes = [_:0]u16{
14491449 mem.nativeToLittle(u16, 0x41),
lib/std/valgrind/memcheck.zig+2-2
......@@ -137,7 +137,7 @@ pub fn countLeaks() CountResult {
137137 return res;
138138}
139139
140test "countLeaks" {
140test countLeaks {
141141 try testing.expectEqual(
142142 @as(CountResult, .{
143143 .leaked = 0,
......@@ -167,7 +167,7 @@ pub fn countLeakBlocks() CountResult {
167167 return res;
168168}
169169
170test "countLeakBlocks" {
170test countLeakBlocks {
171171 try testing.expectEqual(
172172 @as(CountResult, .{
173173 .leaked = 0,
lib/std/zig/ErrorBundle.zig+77-77
......@@ -642,96 +642,96 @@ pub const Wip = struct {
642642 i += 1;
643643 }
644644 }
645};
646645
647test "addBundleAsRoots" {
648 var bundle = bundle: {
649 var wip: ErrorBundle.Wip = undefined;
650 try wip.init(std.testing.allocator);
651 errdefer wip.deinit();
652
653 var ref_traces: [3]ReferenceTrace = undefined;
654 for (&ref_traces, 0..) |*ref_trace, i| {
655 if (i == ref_traces.len - 1) {
656 // sentinel reference trace
657 ref_trace.* = .{
658 .decl_name = 3, // signifies 3 hidden references
659 .src_loc = .none,
660 };
661 } else {
662 ref_trace.* = .{
663 .decl_name = try wip.addString("foo"),
664 .src_loc = try wip.addSourceLocation(.{
665 .src_path = try wip.addString("foo"),
666 .line = 1,
667 .column = 2,
668 .span_start = 3,
669 .span_main = 4,
670 .span_end = 5,
671 .source_line = 0,
672 }),
673 };
646 test addBundleAsRoots {
647 var bundle = bundle: {
648 var wip: ErrorBundle.Wip = undefined;
649 try wip.init(std.testing.allocator);
650 errdefer wip.deinit();
651
652 var ref_traces: [3]ReferenceTrace = undefined;
653 for (&ref_traces, 0..) |*ref_trace, i| {
654 if (i == ref_traces.len - 1) {
655 // sentinel reference trace
656 ref_trace.* = .{
657 .decl_name = 3, // signifies 3 hidden references
658 .src_loc = .none,
659 };
660 } else {
661 ref_trace.* = .{
662 .decl_name = try wip.addString("foo"),
663 .src_loc = try wip.addSourceLocation(.{
664 .src_path = try wip.addString("foo"),
665 .line = 1,
666 .column = 2,
667 .span_start = 3,
668 .span_main = 4,
669 .span_end = 5,
670 .source_line = 0,
671 }),
672 };
673 }
674674 }
675 }
676675
677 const src_loc = try wip.addSourceLocation(.{
678 .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"),
676 const src_loc = try wip.addSourceLocation(.{
677 .src_path = try wip.addString("foo"),
701678 .line = 1,
702679 .column = 2,
703680 .span_start = 3,
704681 .span_main = 4,
705682 .span_end = 5,
706 .source_line = try wip.addString("another line of source"),
707 }),
708 }));
709 wip.extra.items[i] = note_index;
683 .source_line = try wip.addString("some source code"),
684 .reference_trace_len = ref_traces.len,
685 });
686 for (&ref_traces) |ref_trace| {
687 try wip.addReferenceTrace(ref_trace);
688 }
710689
711 break :bundle try wip.toOwnedBundle("");
712 };
713 defer bundle.deinit(std.testing.allocator);
690 try wip.addRootErrorMessage(ErrorMessage{
691 .msg = try wip.addString("hello world"),
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);
714713
715 const ttyconf: std.io.tty.Config = .no_color;
714 const ttyconf: std.io.tty.Config = .no_color;
716715
717 var bundle_buf = std.ArrayList(u8).init(std.testing.allocator);
718 defer bundle_buf.deinit();
719 try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_buf.writer());
716 var bundle_buf = std.ArrayList(u8).init(std.testing.allocator);
717 defer bundle_buf.deinit();
718 try bundle.renderToWriter(.{ .ttyconf = ttyconf }, bundle_buf.writer());
720719
721 var copy = copy: {
722 var wip: ErrorBundle.Wip = undefined;
723 try wip.init(std.testing.allocator);
724 errdefer wip.deinit();
720 var copy = copy: {
721 var wip: ErrorBundle.Wip = undefined;
722 try wip.init(std.testing.allocator);
723 errdefer wip.deinit();
725724
726 try wip.addBundleAsRoots(bundle);
725 try wip.addBundleAsRoots(bundle);
727726
728 break :copy try wip.toOwnedBundle("");
729 };
730 defer copy.deinit(std.testing.allocator);
727 break :copy try wip.toOwnedBundle("");
728 };
729 defer copy.deinit(std.testing.allocator);
731730
732 var copy_buf = std.ArrayList(u8).init(std.testing.allocator);
733 defer copy_buf.deinit();
734 try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_buf.writer());
731 var copy_buf = std.ArrayList(u8).init(std.testing.allocator);
732 defer copy_buf.deinit();
733 try copy.renderToWriter(.{ .ttyconf = ttyconf }, copy_buf.writer());
735734
736 try std.testing.expectEqualStrings(bundle_buf.items, copy_buf.items);
737}
735 try std.testing.expectEqualStrings(bundle_buf.items, copy_buf.items);
736 }
737};
lib/std/zig/primitives.zig+1-1
......@@ -51,7 +51,7 @@ pub fn isPrimitive(name: []const u8) bool {
5151 return true;
5252}
5353
54test "isPrimitive" {
54test isPrimitive {
5555 const expect = std.testing.expect;
5656 try expect(!isPrimitive(""));
5757 try expect(!isPrimitive("_"));
lib/std/zig/string_literal.zig+2-2
......@@ -148,7 +148,7 @@ pub fn parseEscapeSequence(slice: []const u8, offset: *usize) ParsedCharLiteral
148148 }
149149}
150150
151test "parseCharLiteral" {
151test parseCharLiteral {
152152 try std.testing.expectEqual(
153153 ParsedCharLiteral{ .success = 'a' },
154154 parseCharLiteral("'a'"),
......@@ -281,7 +281,7 @@ pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]
281281 }
282282}
283283
284test "parse" {
284test parseAlloc {
285285 const expect = std.testing.expect;
286286 const expectError = std.testing.expectError;
287287 const eql = std.mem.eql;