mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Io.Writer: support alignment for {t} specifier
This commit is contained in:
parent
e43617e686
commit
4780cc50cf
1 changed files with 10 additions and 2 deletions
|
|
@ -1123,8 +1123,8 @@ pub fn printValue(
|
||||||
else => invalidFmtError(fmt, value),
|
else => invalidFmtError(fmt, value),
|
||||||
},
|
},
|
||||||
't' => switch (@typeInfo(T)) {
|
't' => switch (@typeInfo(T)) {
|
||||||
.error_set => return w.writeAll(@errorName(value)),
|
.error_set => return w.alignBufferOptions(@errorName(value), options),
|
||||||
.@"enum", .@"union" => return w.writeAll(@tagName(value)),
|
.@"enum", .@"union" => return w.alignBufferOptions(@tagName(value), options),
|
||||||
else => invalidFmtError(fmt, value),
|
else => invalidFmtError(fmt, value),
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
|
|
@ -2134,6 +2134,14 @@ test "bytes.hex" {
|
||||||
try testing.expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
|
try testing.expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "padding" {
|
||||||
|
const foo: enum { foo } = .foo;
|
||||||
|
try testing.expectFmt("tag: |foo |\n", "tag: |{t:<4}|\n", .{foo});
|
||||||
|
|
||||||
|
const bar: error{bar} = error.bar;
|
||||||
|
try testing.expectFmt("error: |bar |\n", "error: |{t:<4}|\n", .{bar});
|
||||||
|
}
|
||||||
|
|
||||||
test fixed {
|
test fixed {
|
||||||
{
|
{
|
||||||
var buf: [255]u8 = undefined;
|
var buf: [255]u8 = undefined;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue