mirror of
https://github.com/golang/go
synced 2024-11-22 00:44:39 -07:00
return "<nil>" when calling String() on a nil bytes.Buffer.
R=rsc CC=go-dev http://go/go-review/1016005
This commit is contained in:
parent
aa0c811317
commit
63e668d2ad
@ -42,8 +42,12 @@ func (b *Buffer) Bytes() []byte {
|
||||
}
|
||||
|
||||
// String returns the contents of the unread portion of the buffer
|
||||
// as a string.
|
||||
// as a string. If the Buffer is a nil pointer, it returns "<nil>".
|
||||
func (b *Buffer) String() string {
|
||||
if b == nil {
|
||||
// Special case, useful in debugging.
|
||||
return "<nil>"
|
||||
}
|
||||
return string(b.buf[b.off : len(b.buf)]);
|
||||
}
|
||||
|
||||
|
@ -232,3 +232,11 @@ func TestMixedReadsAndWrites(t *testing.T) {
|
||||
}
|
||||
empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len()));
|
||||
}
|
||||
|
||||
|
||||
func TestNil(t *testing.T) {
|
||||
var b *Buffer;
|
||||
if b.String() != "<nil>" {
|
||||
t.Error("expcted <nil>; got %q", b.String());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user