diff options
Diffstat (limited to 'src/pkg/strings/reader_test.go')
-rw-r--r-- | src/pkg/strings/reader_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/pkg/strings/reader_test.go b/src/pkg/strings/reader_test.go index a99ae2a0e..4fdddcdb5 100644 --- a/src/pkg/strings/reader_test.go +++ b/src/pkg/strings/reader_test.go @@ -5,6 +5,7 @@ package strings_test import ( + "bytes" "fmt" "io" "os" @@ -86,3 +87,25 @@ func TestReaderAt(t *testing.T) { } } } + +func TestWriteTo(t *testing.T) { + const str = "0123456789" + for i := 0; i <= len(str); i++ { + s := str[i:] + r := strings.NewReader(s) + var b bytes.Buffer + n, err := r.WriteTo(&b) + if expect := int64(len(s)); n != expect { + t.Errorf("got %v; want %v", n, expect) + } + if err != nil { + t.Errorf("for length %d: got error = %v; want nil", len(s), err) + } + if b.String() != s { + t.Errorf("got string %q; want %q", b.String(), s) + } + if r.Len() != 0 { + t.Errorf("reader contains %v bytes; want 0", r.Len()) + } + } +} |