zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4780cc50cf7e42f6af3eb71ef3897f4b341215b4 (tree)
parent e43617e686f62af55d6663b695ec725e21bff210
Author: Marc Tiehuis <marc@tiehu.is>
Date:   Sun, 20 Jul 2025 13:57:31 +1200

std.Io.Writer: support alignment for `{t}` specifier

Diffstat:
Mlib/std/Io/Writer.zig | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig @@ -1123,8 +1123,8 @@ pub fn printValue( else => invalidFmtError(fmt, value), }, 't' => switch (@typeInfo(T)) { - .error_set => return w.writeAll(@errorName(value)), - .@"enum", .@"union" => return w.writeAll(@tagName(value)), + .error_set => return w.alignBufferOptions(@errorName(value), options), + .@"enum", .@"union" => return w.alignBufferOptions(@tagName(value), options), else => invalidFmtError(fmt, value), }, else => {}, @@ -2134,6 +2134,14 @@ test "bytes.hex" { 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 { { var buf: [255]u8 = undefined;