MCPcopy
hub / github.com/uber-go/zap / TestBufferWrites

Function TestBufferWrites

buffer/buffer_test.go:32–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestBufferWrites(t *testing.T) {
33 buf := NewPool().Get()
34
35 tests := []struct {
36 desc string
37 f func()
38 want string
39 }{
40 {"AppendByte", func() { buf.AppendByte('v') }, "v"},
41 {"AppendString", func() { buf.AppendString("foo") }, "foo"},
42 {"AppendIntPositive", func() { buf.AppendInt(42) }, "42"},
43 {"AppendIntNegative", func() { buf.AppendInt(-42) }, "-42"},
44 {"AppendUint", func() { buf.AppendUint(42) }, "42"},
45 {"AppendBool", func() { buf.AppendBool(true) }, "true"},
46 {"AppendFloat64", func() { buf.AppendFloat(3.14, 64) }, "3.14"},
47 // Intentionally introduce some floating-point error.
48 {"AppendFloat32", func() { buf.AppendFloat(float64(float32(3.14)), 32) }, "3.14"},
49 {"AppendWrite", func() { buf.Write([]byte("foo")) }, "foo"},
50 {"AppendTime", func() { buf.AppendTime(time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC), time.RFC3339) }, "2000-01-02T03:04:05Z"},
51 {"WriteByte", func() { buf.WriteByte('v') }, "v"},
52 {"WriteString", func() { buf.WriteString("foo") }, "foo"},
53 }
54
55 for _, tt := range tests {
56 t.Run(tt.desc, func(t *testing.T) {
57 buf.Reset()
58 tt.f()
59 assert.Equal(t, tt.want, buf.String(), "Unexpected buffer.String().")
60 assert.Equal(t, tt.want, string(buf.Bytes()), "Unexpected string(buffer.Bytes()).")
61 assert.Equal(t, len(tt.want), buf.Len(), "Unexpected buffer length.")
62 // We're not writing more than a kibibyte in tests.
63 assert.Equal(t, _size, buf.Cap(), "Expected buffer capacity to remain constant.")
64 })
65 }
66}
67
68func BenchmarkBuffers(b *testing.B) {
69 // Because we use the strconv.AppendFoo functions so liberally, we can't

Callers

nothing calls this directly

Calls 15

NewPoolFunction · 0.85
AppendByteMethod · 0.80
AppendFloatMethod · 0.80
WriteByteMethod · 0.80
WriteStringMethod · 0.80
ResetMethod · 0.80
BytesMethod · 0.80
CapMethod · 0.80
AppendStringMethod · 0.65
AppendIntMethod · 0.65
AppendUintMethod · 0.65
AppendBoolMethod · 0.65

Tested by

no test coverage detected