1
0
mirror of https://github.com/golang/go synced 2024-10-03 07:11:21 -06:00

bufio: return nil line from ReadLine on error, as documented

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5316069
This commit is contained in:
Brad Fitzpatrick 2011-11-02 08:30:50 -07:00
parent 29a5ae657f
commit bd43eac303
2 changed files with 14 additions and 0 deletions

View File

@ -312,6 +312,9 @@ func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error) {
}
if len(line) == 0 {
if err != nil {
line = nil
}
return
}
err = nil

View File

@ -698,6 +698,17 @@ func TestLinesAfterRead(t *testing.T) {
}
}
func TestReadLineNonNilLineOrError(t *testing.T) {
r := NewReader(strings.NewReader("line 1\n"))
for i := 0; i < 2; i++ {
l, _, err := r.ReadLine()
if l != nil && err != nil {
t.Fatalf("on line %d/2; ReadLine=%#v, %v; want non-nil line or Error, but not both",
i+1, l, err)
}
}
}
type readLineResult struct {
line []byte
isPrefix bool