@@ -30,86 +30,32 @@ import (
3030)
3131
3232func TestBufferWrites (t * testing.T ) {
33- t . Parallel ()
33+ buf := NewPool (). Get ()
3434
3535 tests := []struct {
3636 desc string
37- f func (* Buffer )
37+ f func ()
3838 want string
3939 }{
40- {
41- desc : "AppendByte" ,
42- f : func (buf * Buffer ) { buf .AppendByte ('v' ) },
43- want : "v" ,
44- },
45- {
46- desc : "AppendString" ,
47- f : func (buf * Buffer ) { buf .AppendString ("foo" ) },
48- want : "foo" ,
49- },
50- {
51- desc : "AppendIntPositive" ,
52- f : func (buf * Buffer ) { buf .AppendInt (42 ) },
53- want : "42" ,
54- },
55- {
56- desc : "AppendIntNegative" ,
57- f : func (buf * Buffer ) { buf .AppendInt (- 42 ) },
58- want : "-42" ,
59- },
60- {
61- desc : "AppendUint" ,
62- f : func (buf * Buffer ) { buf .AppendUint (42 ) },
63- want : "42" ,
64- },
65- {
66- desc : "AppendBool" ,
67- f : func (buf * Buffer ) { buf .AppendBool (true ) },
68- want : "true" ,
69- },
70- {
71- desc : "AppendFloat64" ,
72- f : func (buf * Buffer ) { buf .AppendFloat (3.14 , 64 ) },
73- want : "3.14" ,
74- },
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" },
7547 // Intentionally introduce some floating-point error.
76- {
77- desc : "AppendFloat32" ,
78- f : func (buf * Buffer ) { buf .AppendFloat (float64 (float32 (3.14 )), 32 ) },
79- want : "3.14" ,
80- },
81- {
82- desc : "AppendWrite" ,
83- f : func (buf * Buffer ) { buf .Write ([]byte ("foo" )) },
84- want : "foo" ,
85- },
86- {
87- desc : "AppendTime" ,
88- f : func (buf * Buffer ) { buf .AppendTime (time .Date (2000 , 1 , 2 , 3 , 4 , 5 , 6 , time .UTC ), time .RFC3339 ) },
89- want : "2000-01-02T03:04:05Z" ,
90- },
91- {
92- desc : "WriteByte" ,
93- f : func (buf * Buffer ) { buf .WriteByte ('v' ) },
94- want : "v" ,
95- },
96- {
97- desc : "WriteString" ,
98- f : func (buf * Buffer ) { buf .WriteString ("foo" ) },
99- want : "foo" ,
100- },
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" },
10153 }
10254
103- pool := NewPool ()
10455 for _ , tt := range tests {
105- tt := tt
10656 t .Run (tt .desc , func (t * testing.T ) {
107- t .Parallel ()
108-
109- buf := pool .Get ()
110- defer buf .Free ()
111-
112- tt .f (buf )
57+ buf .Reset ()
58+ tt .f ()
11359 assert .Equal (t , tt .want , buf .String (), "Unexpected buffer.String()." )
11460 assert .Equal (t , tt .want , string (buf .Bytes ()), "Unexpected string(buffer.Bytes())." )
11561 assert .Equal (t , len (tt .want ), buf .Len (), "Unexpected buffer length." )
0 commit comments