1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestPrefixSuffixSaver(t
*testing
.T
) {
25 writes
: []string{"a"},
30 writes
: []string{"abc", "d"},
35 writes
: []string{"abc", "d", "e"},
36 want
: "ab\n... omitting 1 bytes ...\nde",
40 writes
: []string{"ab______________________yz"},
41 want
: "ab\n... omitting 22 bytes ...\nyz",
45 writes
: []string{"ab_______________________y", "z"},
46 want
: "ab\n... omitting 23 bytes ...\nyz",
49 for i
, tt
:= range tests
{
50 w
:= &prefixSuffixSaver
{N
: tt
.N
}
51 for _
, s
:= range tt
.writes
{
52 n
, err
:= io
.WriteString(w
, s
)
53 if err
!= nil || n
!= len(s
) {
54 t
.Errorf("%d. WriteString(%q) = %v, %v; want %v, %v", i
, s
, n
, err
, len(s
), nil)
57 if got
:= string(w
.Bytes()); got
!= tt
.want
{
58 t
.Errorf("%d. Bytes = %q; want %q", i
, got
, tt
.want
)