| ... | @@ -147,6 +147,10 @@ pub const Buffer = struct { | ... | @@ -147,6 +147,10 @@ pub const Buffer = struct { |
| 147 | try self.resize(m.len); | 147 | try self.resize(m.len); |
| 148 | mem.copy(u8, self.list.toSlice(), m); | 148 | mem.copy(u8, self.list.toSlice(), m); |
| 149 | } | 149 | } |
| | 150 | |
| | 151 | pub fn print(self: *Buffer, comptime fmt: []const u8, args: var) !void { |
| | 152 | return std.fmt.format(self, error{OutOfMemory}, Buffer.append, fmt, args); |
| | 153 | } |
| 150 | }; | 154 | }; |
| 151 | | 155 | |
| 152 | test "simple Buffer" { | 156 | test "simple Buffer" { |
| ... | @@ -190,3 +194,11 @@ test "Buffer.initCapacity" { | ... | @@ -190,3 +194,11 @@ test "Buffer.initCapacity" { |
| 190 | testing.expect(buf.capacity() == old_cap); | 194 | testing.expect(buf.capacity() == old_cap); |
| 191 | testing.expect(mem.eql(u8, buf.toSliceConst(), "hello")); | 195 | testing.expect(mem.eql(u8, buf.toSliceConst(), "hello")); |
| 192 | } | 196 | } |
| | 197 | |
| | 198 | test "Buffer.print" { |
| | 199 | var buf = try Buffer.init(testing.allocator, ""); |
| | 200 | defer buf.deinit(); |
| | 201 | |
| | 202 | try buf.print("Hello {} the {}", .{ 2, "world" }); |
| | 203 | testing.expect(buf.eql("Hello 2 the world")); |
| | 204 | } |