Commit 63e668d2 authored by Rob Pike's avatar Rob Pike

return "<nil>" when calling String() on a nil bytes.Buffer.

R=rsc
CC=go-dev
http://go/go-review/1016005
parent aa0c8113
......@@ -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());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment