std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API
make std.testing.expectFmt work at compile-time
std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.
Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
- anytype -> *std.io.Writer
- inferred error set -> error{WriteFailed}
- options -> (deleted)
* std.fmt.Formatted
- now takes context type explicitly
- no fmt string
This commit is contained in:
@@ -150,17 +150,11 @@ fn parseNum(text: []const u8) error{ InvalidVersion, Overflow }!usize {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn format(
|
||||
self: Version,
|
||||
comptime fmt: []const u8,
|
||||
options: std.fmt.FormatOptions,
|
||||
out_stream: anytype,
|
||||
) !void {
|
||||
_ = options;
|
||||
pub fn format(self: Version, w: *std.io.Writer, comptime fmt: []const u8) std.io.Writer.Error!void {
|
||||
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||
try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
||||
if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
|
||||
if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
|
||||
try w.print("{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
||||
if (self.pre) |pre| try w.print("-{s}", .{pre});
|
||||
if (self.build) |build| try w.print("+{s}", .{build});
|
||||
}
|
||||
|
||||
const expect = std.testing.expect;
|
||||
@@ -202,7 +196,7 @@ test format {
|
||||
"1.0.0+0.build.1-rc.10000aaa-kk-0.1",
|
||||
"5.4.0-1018-raspi",
|
||||
"5.7.123",
|
||||
}) |valid| try std.testing.expectFmt(valid, "{}", .{try parse(valid)});
|
||||
}) |valid| try std.testing.expectFmt(valid, "{f}", .{try parse(valid)});
|
||||
|
||||
// Invalid version strings should be rejected.
|
||||
for ([_][]const u8{
|
||||
@@ -269,12 +263,12 @@ test format {
|
||||
// Valid version string that may overflow.
|
||||
const big_valid = "99999999999999999999999.999999999999999999.99999999999999999";
|
||||
if (parse(big_valid)) |ver| {
|
||||
try std.testing.expectFmt(big_valid, "{}", .{ver});
|
||||
try std.testing.expectFmt(big_valid, "{f}", .{ver});
|
||||
} else |err| try expect(err == error.Overflow);
|
||||
|
||||
// Invalid version string that may overflow.
|
||||
const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
|
||||
if (parse(big_invalid)) |ver| std.debug.panic("expected error, found {}", .{ver}) else |_| {}
|
||||
if (parse(big_invalid)) |ver| std.debug.panic("expected error, found {f}", .{ver}) else |_| {}
|
||||
}
|
||||
|
||||
test "precedence" {
|
||||
|
||||
Reference in New Issue
Block a user