Commit e439345d authored by Rob Pike's avatar Rob Pike

bufio.UnreadRune: fix bug at EOF

Fixes #1132.

R=rsc
CC=golang-dev
https://golang.org/cl/2215045
parent 099d7b4d
......@@ -207,6 +207,7 @@ func (b *Reader) ReadRune() (rune int, size int, err os.Error) {
for b.r+utf8.UTFMax > b.w && !utf8.FullRune(b.buf[b.r:b.w]) && b.err == nil {
b.fill()
}
b.lastRuneSize = -1
if b.r == b.w {
return 0, 0, b.err
}
......
......@@ -319,6 +319,20 @@ func TestUnreadRuneError(t *testing.T) {
}
}
func TestUnreadRuneAtEOF(t *testing.T) {
// UnreadRune/ReadRune should error at EOF (was a bug; used to panic)
r := NewReader(strings.NewReader("x"))
r.ReadRune()
r.ReadRune()
r.UnreadRune()
_, _, err := r.ReadRune()
if err == nil {
t.Error("expected error at EOF")
} else if err != os.EOF {
t.Error("expected EOF; got", err)
}
}
func TestReadWriteRune(t *testing.T) {
const NRune = 1000
byteBuf := new(bytes.Buffer)
......
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