Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1329)

Side by Side Diff: src/pkg/bytes/reader_test.go

Issue 13651044: code review 13651044: bytes: additional test coverage (Closed)
Patch Set: diff -r 77a4d225cc7e https://code.google.com/p/go Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« src/pkg/bytes/bytes_test.go ('K') | « src/pkg/bytes/bytes_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package bytes_test 5 package bytes_test
6 6
7 import ( 7 import (
8 . "bytes" 8 . "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 if b.String() != s { 107 if b.String() != s {
108 t.Errorf("got string %q; want %q", b.String(), s) 108 t.Errorf("got string %q; want %q", b.String(), s)
109 } 109 }
110 if r.Len() != 0 { 110 if r.Len() != 0 {
111 t.Errorf("reader contains %v bytes; want 0", r.Len()) 111 t.Errorf("reader contains %v bytes; want 0", r.Len())
112 } 112 }
113 } 113 }
114 } 114 }
115 115
116 func TestReaderLen(t *testing.T) {
117 const data = "hello world"
118 r := NewReader([]byte(data))
119 if actual, expected := r.Len(), 11; actual != expected {
120 t.Errorf("r.Len(): expected %d bytes, got %v", expected, actual)
121 }
122 if n, err := r.Read(make([]byte, 10)); err != nil || n != 10 {
123 t.Errorf("Read failed: read %d %v", n, err)
124 }
125 if actual, expected := r.Len(), 1; actual != expected {
bradfitz 2013/09/11 10:51:20 a/actual, expected/got, want/
dave_cheney.net 2013/09/11 11:06:20 Done.
126 t.Errorf("r.Len(): expected %d bytes, got %v", expected, actual)
bradfitz 2013/09/11 10:51:20 got first, then want: "Len = %d; want %d", got, w
dave_cheney.net 2013/09/11 11:06:20 Done.
127 }
128 if n, err := r.Read(make([]byte, 1)); err != nil || n != 1 {
129 t.Errorf("Read failed: read %d %v", n, err)
130 }
131 if actual, expected := r.Len(), 0; actual != expected {
bradfitz 2013/09/11 10:51:20 etc
dave_cheney.net 2013/09/11 11:06:20 Done.
132 t.Errorf("r.Len(): expected %d bytes, got %v", expected, actual)
133 }
134 }
135
136 func TestReaderDoubleUnreadRune(t *testing.T) {
137 buf := NewBuffer([]byte("groucho"))
138 if _, _, err := buf.ReadRune(); err != nil {
139 // should not happen
140 t.Fatal(err)
141 }
142 if err := buf.UnreadByte(); err != nil {
143 // should not happen
144 t.Fatal(err)
145 }
146 if err := buf.UnreadByte(); err == nil {
147 t.Fatal("UnreadByte: expected error, got nil")
148 }
149 }
150
116 // verify that copying from an empty reader always has the same results, 151 // verify that copying from an empty reader always has the same results,
117 // regardless of the presence of a WriteTo method. 152 // regardless of the presence of a WriteTo method.
118 func TestReaderCopyNothing(t *testing.T) { 153 func TestReaderCopyNothing(t *testing.T) {
119 type nErr struct { 154 type nErr struct {
120 n int64 155 n int64
121 err error 156 err error
122 } 157 }
123 type justReader struct { 158 type justReader struct {
124 io.Reader 159 io.Reader
125 } 160 }
126 type justWriter struct { 161 type justWriter struct {
127 io.Writer 162 io.Writer
128 } 163 }
129 discard := justWriter{ioutil.Discard} // hide ReadFrom 164 discard := justWriter{ioutil.Discard} // hide ReadFrom
130 165
131 var with, withOut nErr 166 var with, withOut nErr
132 with.n, with.err = io.Copy(discard, NewReader(nil)) 167 with.n, with.err = io.Copy(discard, NewReader(nil))
133 withOut.n, withOut.err = io.Copy(discard, justReader{NewReader(nil)}) 168 withOut.n, withOut.err = io.Copy(discard, justReader{NewReader(nil)})
134 if with != withOut { 169 if with != withOut {
135 t.Errorf("behavior differs: with = %#v; without: %#v", with, wit hOut) 170 t.Errorf("behavior differs: with = %#v; without: %#v", with, wit hOut)
136 } 171 }
137 } 172 }
OLDNEW
« src/pkg/bytes/bytes_test.go ('K') | « src/pkg/bytes/bytes_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b