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

Delta Between Two Patch Sets: src/pkg/bytes/reader_test.go

Issue 77580046: code review 77580046: strings: fix Reader.UnreadRune (Closed)
Left Patch Set: diff -r 1ddce2d9ee32 https://code.google.com/p/go Created 11 years, 1 month ago
Right Patch Set: diff -r 1ddce2d9ee32 https://code.google.com/p/go Created 11 years, 1 month 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:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/bytes/reader.go ('k') | src/pkg/strings/reader.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 t.Errorf("r.Len(): got %d, want %d", got, want) 126 t.Errorf("r.Len(): got %d, want %d", got, want)
127 } 127 }
128 if n, err := r.Read(make([]byte, 1)); err != nil || n != 1 { 128 if n, err := r.Read(make([]byte, 1)); err != nil || n != 1 {
129 t.Errorf("Read failed: read %d %v", n, err) 129 t.Errorf("Read failed: read %d %v", n, err)
130 } 130 }
131 if got, want := r.Len(), 0; got != want { 131 if got, want := r.Len(), 0; got != want {
132 t.Errorf("r.Len(): got %d, want %d", got, want) 132 t.Errorf("r.Len(): got %d, want %d", got, want)
133 } 133 }
134 } 134 }
135 135
136 var UnreadRuneErrorTests = []struct {
137 name string
138 f func(*Reader)
139 }{
140 {"Read", func(r *Reader) { r.Read([]byte{}) }},
141 {"ReadAt", func(r *Reader) { r.ReadAt([]byte{}, 0) }},
142 {"ReadByte", func(r *Reader) { r.ReadByte() }},
143 {"UnreadRune", func(r *Reader) { r.UnreadRune() }},
144 {"Seek", func(r *Reader) { r.Seek(0, 1) }},
145 {"WriteTo", func(r *Reader) { r.WriteTo(&Buffer{}) }},
146 }
147
148 func TestUnreadRuneError(t *testing.T) {
149 for _, tt := range UnreadRuneErrorTests {
150 reader := NewReader([]byte("0123456789"))
151 if _, _, err := reader.ReadRune(); err != nil {
152 // should not happen
153 t.Fatal(err)
154 }
155 tt.f(reader)
156 err := reader.UnreadRune()
157 if err == nil {
158 t.Errorf("Unreading after %s: expected error", tt.name)
159 }
160 }
161 }
162
136 func TestReaderDoubleUnreadRune(t *testing.T) { 163 func TestReaderDoubleUnreadRune(t *testing.T) {
137 buf := NewBuffer([]byte("groucho")) 164 buf := NewBuffer([]byte("groucho"))
138 if _, _, err := buf.ReadRune(); err != nil { 165 if _, _, err := buf.ReadRune(); err != nil {
139 // should not happen 166 // should not happen
140 t.Fatal(err) 167 t.Fatal(err)
141 } 168 }
142 if err := buf.UnreadByte(); err != nil { 169 if err := buf.UnreadByte(); err != nil {
143 // should not happen 170 // should not happen
144 t.Fatal(err) 171 t.Fatal(err)
145 } 172 }
(...skipping 17 matching lines...) Expand all
163 } 190 }
164 discard := justWriter{ioutil.Discard} // hide ReadFrom 191 discard := justWriter{ioutil.Discard} // hide ReadFrom
165 192
166 var with, withOut nErr 193 var with, withOut nErr
167 with.n, with.err = io.Copy(discard, NewReader(nil)) 194 with.n, with.err = io.Copy(discard, NewReader(nil))
168 withOut.n, withOut.err = io.Copy(discard, justReader{NewReader(nil)}) 195 withOut.n, withOut.err = io.Copy(discard, justReader{NewReader(nil)})
169 if with != withOut { 196 if with != withOut {
170 t.Errorf("behavior differs: with = %#v; without: %#v", with, wit hOut) 197 t.Errorf("behavior differs: with = %#v; without: %#v", with, wit hOut)
171 } 198 }
172 } 199 }
LEFTRIGHT

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