aboutsummaryrefslogtreecommitdiff
path: root/src/strings/reader_test.go
diff options
context:
space:
mode:
authorTim Cooper <tim.cooper@layeh.com>2018-10-26 16:34:27 -0500
committerBrad Fitzpatrick <bradfitz@golang.org>2018-10-29 20:07:25 +0000
commit5fc4604aa8b593d8d9e93c98a1380114633b7c6a (patch)
treebb9eeeeec7bcce7b36273d3ed417c9ae827e4bf4 /src/strings/reader_test.go
parent70dd90c4a93d26215a3514d975c2692724d05ac6 (diff)
downloadgo-5fc4604aa8b593d8d9e93c98a1380114633b7c6a.tar.xz
bytes, strings: fix Reader.UnreadRune returning without error on a zero Reader
Fixes #28269 Change-Id: I878dff43c0b6bdb98702d8e73f2ecd984fb2350f Reviewed-on: https://go-review.googlesource.com/c/145098 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/strings/reader_test.go')
-rw-r--r--src/strings/reader_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/strings/reader_test.go b/src/strings/reader_test.go
index bf40eb1a31..a4c211d699 100644
--- a/src/strings/reader_test.go
+++ b/src/strings/reader_test.go
@@ -190,3 +190,45 @@ func TestReaderReset(t *testing.T) {
t.Errorf("ReadAll: got %q, want %q", got, want)
}
}
+
+func TestReaderZero(t *testing.T) {
+ if l := (&strings.Reader{}).Len(); l != 0 {
+ t.Errorf("Len: got %d, want 0", l)
+ }
+
+ if n, err := (&strings.Reader{}).Read(nil); n != 0 || err != io.EOF {
+ t.Errorf("Read: got %d, %v; want 0, io.EOF", n, err)
+ }
+
+ if n, err := (&strings.Reader{}).ReadAt(nil, 11); n != 0 || err != io.EOF {
+ t.Errorf("ReadAt: got %d, %v; want 0, io.EOF", n, err)
+ }
+
+ if b, err := (&strings.Reader{}).ReadByte(); b != 0 || err != io.EOF {
+ t.Errorf("ReadByte: got %d, %v; want 0, io.EOF", b, err)
+ }
+
+ if ch, size, err := (&strings.Reader{}).ReadRune(); ch != 0 || size != 0 || err != io.EOF {
+ t.Errorf("ReadRune: got %d, %d, %v; want 0, 0, io.EOF", ch, size, err)
+ }
+
+ if offset, err := (&strings.Reader{}).Seek(11, io.SeekStart); offset != 11 || err != nil {
+ t.Errorf("Seek: got %d, %v; want 11, nil", offset, err)
+ }
+
+ if s := (&strings.Reader{}).Size(); s != 0 {
+ t.Errorf("Size: got %d, want 0", s)
+ }
+
+ if (&strings.Reader{}).UnreadByte() == nil {
+ t.Errorf("UnreadByte: got nil, want error")
+ }
+
+ if (&strings.Reader{}).UnreadRune() == nil {
+ t.Errorf("UnreadRune: got nil, want error")
+ }
+
+ if n, err := (&strings.Reader{}).WriteTo(ioutil.Discard); n != 0 || err != nil {
+ t.Errorf("WriteTo: got %d, %v; want 0, nil", n, err)
+ }
+}