mirror of
https://github.com/golang/go
synced 2024-11-20 05:54:43 -07: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:
parent
29a5ae657f
commit
bd43eac303
@ -312,6 +312,9 @@ func (b *Reader) ReadLine() (line []byte, isPrefix bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
|
if err != nil {
|
||||||
|
line = nil
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -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 {
|
type readLineResult struct {
|
||||||
line []byte
|
line []byte
|
||||||
isPrefix bool
|
isPrefix bool
|
||||||
|
Loading…
Reference in New Issue
Block a user