const std = @import("std");
const print = std.debug.print;
const Person = struct {
name: []const u8,
birth_year: i32,
death_year: ?i32,
pub fn format(
self: Person,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = fmt;
_ = options;
try writer.print("{s} ({d}-", .{ self.name, self.birth_year });
try writer.writeAll(")");
}
};
test "custom printing" {
const j = Person{
.name = "John",
.birth_year = 1987,
.death_year = undefined,
};
print("j: {s}", .{j});
print("TEST", .{});
}
Even the last print is not shown, so I suspect it has to do with the way I invoke zig test or something relevant, but the goal is to see the custom format of the Person struct on the screen.