mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
zig fmt + add U32Iterator tests
This commit is contained in:
@@ -15,19 +15,39 @@ pub const U32Iterator = struct {
|
||||
done: bool,
|
||||
};
|
||||
|
||||
pub fn _next(self: *U32Iterator) !Return {
|
||||
pub fn _next(self: *U32Iterator) Return {
|
||||
const i = self.index;
|
||||
if (i >= self.length) {
|
||||
return Return{
|
||||
return .{
|
||||
.value = 0,
|
||||
.done = true,
|
||||
};
|
||||
}
|
||||
|
||||
self.index += 1;
|
||||
return Return{
|
||||
return .{
|
||||
.value = i,
|
||||
.done = false,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const testing = std.testing;
|
||||
test "U32Iterator" {
|
||||
const Return = U32Iterator.Return;
|
||||
|
||||
{
|
||||
var it = U32Iterator{ .length = 0 };
|
||||
try testing.expectEqual(Return{ .value = 0, .done = true }, it._next());
|
||||
try testing.expectEqual(Return{ .value = 0, .done = true }, it._next());
|
||||
}
|
||||
|
||||
{
|
||||
var it = U32Iterator{ .length = 3 };
|
||||
try testing.expectEqual(Return{ .value = 0, .done = false }, it._next());
|
||||
try testing.expectEqual(Return{ .value = 1, .done = false }, it._next());
|
||||
try testing.expectEqual(Return{ .value = 2, .done = false }, it._next());
|
||||
try testing.expectEqual(Return{ .value = 0, .done = true }, it._next());
|
||||
try testing.expectEqual(Return{ .value = 0, .done = true }, it._next());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user