Moved Zip and Empty unit tests to Iterator(T).zip and `Iter(T).empty

This commit is contained in:
Luuk Machielse 2025-10-11 09:37:16 +02:00
parent 2f02e13cc3
commit 11b1678e0e

View file

@ -23,6 +23,14 @@ pub fn Iter(comptime T: type) type {
pub fn empty() Iterator(Empty(T)) {
return .{ .inner = .{} };
}
test empty {
const testing = @import("std").testing;
var it = Iter(i32).empty();
try testing.expectEqual(null, it.next());
}
};
}
@ -157,6 +165,14 @@ pub fn Iterator(comptime Inner: type) type {
return .{ .inner = .{ .a = self.inner, .b = other.inner } };
}
test zip {
const testing = @import("std").testing;
var it = Iter(i32).once(10).zip(Iter(i32).once(20));
try testing.expectEqualDeep(struct { i32, i32 }{ 10, 20 }, it.next().?);
}
pub fn toOwnedSlice(self: Self, gpa: std.mem.Allocator) ![]const Item {
var list: std.ArrayList(Item) = .empty;
errdefer list.deinit(gpa);
@ -300,14 +316,6 @@ pub const adapters = struct {
}
};
}
test Zip {
const testing = @import("std").testing;
var it = Iter(i32).once(10).zip(Iter(i32).once(20));
try testing.expectEqualDeep(struct { i32, i32 }{ 10, 20 }, it.next().?);
}
};
pub fn Range(comptime T: type) type {
@ -402,11 +410,3 @@ pub fn Empty(comptime T: type) type {
}
};
}
test Empty {
const testing = @import("std").testing;
var it = Iter(i32).empty();
try testing.expectEqual(null, it.next());
}