Refactor test to not redeclare std.testing namespace

This commit is contained in:
Luuk Machielse 2025-12-06 18:26:04 +01:00
parent abaade4cdc
commit 2c091d9d22

View file

@ -13,15 +13,15 @@ pub fn iter(comptime T: type) type {
}
test fromSliceOwned {
const testing = @import("std").testing;
const expectEqual = std.testing.expectEqual;
var it = iter(i32).fromSliceOwned(&.{ 1, 3, 2, 4 });
try testing.expectEqual(1, it.next());
try testing.expectEqual(3, it.next());
try testing.expectEqual(2, it.next());
try testing.expectEqual(4, it.next());
try testing.expectEqual(null, it.next());
try expectEqual(1, it.next());
try expectEqual(3, it.next());
try expectEqual(2, it.next());
try expectEqual(4, it.next());
try expectEqual(null, it.next());
}
pub fn range(start: T, end: T) Iterator(Range(T)) {
@ -39,19 +39,15 @@ pub fn iter(comptime T: type) type {
pub const empty: Iterator(Empty(T)) = .{ .inner = .{} };
test empty {
const testing = @import("std").testing;
var it = iter(i32).empty;
try testing.expectEqual(null, it.next());
try std.testing.expectEqual(null, it.next());
}
};
}
test iter {
const testing = @import("std").testing;
const allocator = testing.allocator;
const allocator = std.testing.allocator;
const arith = struct {
fn is_square(x: i32) bool {
@ -73,7 +69,7 @@ test iter {
defer allocator.free(items);
try testing.expectEqualSlices(
try std.testing.expectEqualSlices(
i32,
&[_]i32{ -100, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
items,
@ -180,15 +176,15 @@ pub fn Iterator(comptime Inner: type) type {
}
test zip {
const testing = @import("std").testing;
const expectEqualDeep = std.testing.expectEqualDeep;
var it = iter(i32).fromSliceOwned(&.{ 1, 2, 3 })
.zip(iter(i32).fromSliceOwned(&.{ 4, 5, 6 }));
try testing.expectEqualDeep(.{ 1, 4 }, it.next());
try testing.expectEqualDeep(.{ 2, 5 }, it.next());
try testing.expectEqualDeep(.{ 3, 6 }, it.next());
try testing.expectEqualDeep(null, it.next());
try expectEqualDeep(.{ 1, 4 }, it.next());
try expectEqualDeep(.{ 2, 5 }, it.next());
try expectEqualDeep(.{ 3, 6 }, it.next());
try expectEqualDeep(null, it.next());
}
pub fn toOwnedSlice(self: Self, allocator: std.mem.Allocator) ![]const Item {