mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: add ReadRune to Reader
R=rsc CC=golang-dev https://golang.org/cl/940041
This commit is contained in:
parent
e4136fe91c
commit
d7b4851586
2 changed files with 48 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue