mirror of
https://github.com/golang/go
synced 2024-11-25 15:08:02 -07:00
bufio.UnreadRune: fix bug at EOF
Fixes #1132. R=rsc CC=golang-dev https://golang.org/cl/2215045
This commit is contained in:
parent
099d7b4d1d
commit
e439345dfd
@ -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 {
|
for b.r+utf8.UTFMax > b.w && !utf8.FullRune(b.buf[b.r:b.w]) && b.err == nil {
|
||||||
b.fill()
|
b.fill()
|
||||||
}
|
}
|
||||||
|
b.lastRuneSize = -1
|
||||||
if b.r == b.w {
|
if b.r == b.w {
|
||||||
return 0, 0, b.err
|
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) {
|
func TestReadWriteRune(t *testing.T) {
|
||||||
const NRune = 1000
|
const NRune = 1000
|
||||||
byteBuf := new(bytes.Buffer)
|
byteBuf := new(bytes.Buffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user