mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2025-12-15 09:43:14 +01:00
Moved Zip and Empty unit tests to Iterator(T).zip and `Iter(T).empty
This commit is contained in:
parent
2f02e13cc3
commit
11b1678e0e
1 changed files with 16 additions and 16 deletions
32
src/root.zig
32
src/root.zig
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue