Skip to content

Commit 6a79c2f

Browse files
committed
test: codecov: hash+Duration format
1 parent 7219996 commit 6a79c2f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/core/hash.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,14 @@ test "hello and world hash correctly" {
589589
);
590590
// sig fmt: on
591591
}
592+
593+
test "Hash format" {
594+
const d: Hash = .init("hello world");
595+
var buf: [100]u8 = undefined;
596+
var w: std.io.Writer = .fixed(&buf);
597+
try d.format(&w);
598+
try std.testing.expectEqualStrings(
599+
"DULfJyE3WQqNxy3ymuhAChyNR3yufT88pmqvAazKFMG4",
600+
buf[0..w.end],
601+
);
602+
}

src/time/time.zig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,11 @@ pub const Duration = struct {
599599
return .{ .ns = self.ns * factor };
600600
}
601601

602-
pub fn format(self: @This(), writer: *std.io.Writer) std.io.Writer.Error!void {
603-
return writer.print("{D}", .{self.ns});
602+
pub fn format(self: Duration, writer: *std.io.Writer) std.io.Writer.Error!void {
603+
return self.formatDuration(writer);
604604
}
605605

606-
pub fn formatDuration(self: @This(), writer: *std.io.Writer) std.io.Writer.Error!void {
606+
pub fn formatDuration(self: Duration, writer: *std.io.Writer) std.io.Writer.Error!void {
607607
return writer.print("{D}", .{self.ns});
608608
}
609609
};
@@ -673,3 +673,11 @@ pub const Timer = struct {
673673
return self.inner.sample();
674674
}
675675
};
676+
677+
test "Duration format" {
678+
const d: Duration = .fromMillis(1500);
679+
var buf: [100]u8 = undefined;
680+
var w: std.io.Writer = .fixed(&buf);
681+
try d.format(&w);
682+
try std.testing.expectEqualStrings("1.5s", buf[0..w.end]);
683+
}

0 commit comments

Comments
 (0)