mirror of
https://github.com/golang/go
synced 2024-11-24 15:10:02 -07:00
encoding/line: fix line returned after EOF
Fixes #1509. R=r CC=golang-dev https://golang.org/cl/4167045
This commit is contained in:
parent
e6ee0d2492
commit
5311d915f4
@ -105,6 +105,9 @@ func (l *Reader) ReadLine() (line []byte, isPrefix bool, err os.Error) {
|
|||||||
l.buf = l.buf[:oldLen+n]
|
l.buf = l.buf[:oldLen+n]
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
l.err = readErr
|
l.err = readErr
|
||||||
|
if len(l.buf) == 0 {
|
||||||
|
return nil, false, readErr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
|
@ -7,6 +7,7 @@ package line
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -108,3 +109,25 @@ func TestReadAfterLines(t *testing.T) {
|
|||||||
t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData)
|
t.Errorf("bad result for Read: got %q; expected %q", outbuf.String(), restData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadEmptyBuffer(t *testing.T) {
|
||||||
|
l := NewReader(bytes.NewBuffer(nil), 10)
|
||||||
|
line, isPrefix, err := l.ReadLine()
|
||||||
|
if err != os.EOF {
|
||||||
|
t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLinesAfterRead(t *testing.T) {
|
||||||
|
l := NewReader(bytes.NewBuffer([]byte("foo")), 10)
|
||||||
|
_, err := ioutil.ReadAll(l)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
line, isPrefix, err := l.ReadLine()
|
||||||
|
if err != os.EOF {
|
||||||
|
t.Errorf("expected EOF from ReadLine, got '%s' %t %s", line, isPrefix, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user