strings: add ReadRune to Reader

R=rsc
CC=golang-dev
https://golang.org/cl/940041
This commit is contained in:
Kyle Consalus 2010-04-20 22:18:26 -07:00 committed by Russ Cox
parent e4136fe91c
commit d7b4851586
2 changed files with 48 additions and 2 deletions

View file

@ -5,6 +5,7 @@
package strings_test
import (
"os"
. "strings"
"testing"
"unicode"
@ -576,3 +577,25 @@ func TestRunes(t *testing.T) {
}
}
}
func TestReadRune(t *testing.T) {
testStrings := []string{"", abcd, faces, commas}
for _, s := range testStrings {
reader := NewReader(s)
res := ""
for {
r, _, e := reader.ReadRune()
if e == os.EOF {
break
}
if e != nil {
t.Errorf("Reading %q: %s", s, e)
break
}
res += string(r)
}
if res != s {
t.Errorf("Reader(%q).ReadRune() produced %q", s, res)
}
}
}