Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
63e668d2
Commit
63e668d2
authored
Oct 31, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return "<nil>" when calling String() on a nil bytes.Buffer.
R=rsc CC=go-dev
http://go/go-review/1016005
parent
aa0c8113
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
buffer.go
src/pkg/bytes/buffer.go
+5
-1
buffer_test.go
src/pkg/bytes/buffer_test.go
+8
-0
No files found.
src/pkg/bytes/buffer.go
View file @
63e668d2
...
...
@@ -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
)]);
}
...
...
src/pkg/bytes/buffer_test.go
View file @
63e668d2
...
...
@@ -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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment