Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
dc71ace2
Commit
dc71ace2
authored
Mar 21, 2013
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bufio: add some tests
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/7927044
parent
5060dded
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
3 deletions
+44
-3
src/pkg/bufio/bufio_test.go
src/pkg/bufio/bufio_test.go
+44
-3
No files found.
src/pkg/bufio/bufio_test.go
View file @
dc71ace2
...
...
@@ -7,6 +7,7 @@ package bufio_test
import
(
.
"bufio"
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
...
...
@@ -434,9 +435,12 @@ func TestWriteErrors(t *testing.T) {
t
.
Errorf
(
"Write hello to %v: %v"
,
w
,
e
)
continue
}
// Two flushes, to verify the error is sticky.
for
i
:=
0
;
i
<
2
;
i
++
{
e
=
buf
.
Flush
()
if
e
!=
w
.
expect
{
t
.
Errorf
(
"Flush %v: got %v, wanted %v"
,
w
,
e
,
w
.
expect
)
t
.
Errorf
(
"Flush %d/2 %v: got %v, wanted %v"
,
i
+
1
,
w
,
e
,
w
.
expect
)
}
}
}
}
...
...
@@ -962,6 +966,43 @@ func TestNegativeRead(t *testing.T) {
b
.
Read
(
make
([]
byte
,
100
))
}
var
errFake
=
errors
.
New
(
"fake error"
)
type
errorThenGoodReader
struct
{
didErr
bool
nread
int
}
func
(
r
*
errorThenGoodReader
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
r
.
nread
++
if
!
r
.
didErr
{
r
.
didErr
=
true
return
0
,
errFake
}
return
len
(
p
),
nil
}
func
TestReaderClearError
(
t
*
testing
.
T
)
{
r
:=
&
errorThenGoodReader
{}
b
:=
NewReader
(
r
)
buf
:=
make
([]
byte
,
1
)
if
_
,
err
:=
b
.
Read
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"1st nil Read = %v; want nil"
,
err
)
}
if
_
,
err
:=
b
.
Read
(
buf
);
err
!=
errFake
{
t
.
Fatalf
(
"1st Read = %v; want errFake"
,
err
)
}
if
_
,
err
:=
b
.
Read
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"2nd nil Read = %v; want nil"
,
err
)
}
if
_
,
err
:=
b
.
Read
(
buf
);
err
!=
nil
{
t
.
Fatalf
(
"3rd Read with buffer = %v; want nil"
,
err
)
}
if
r
.
nread
!=
2
{
t
.
Errorf
(
"num reads = %d; want 2"
,
r
.
nread
)
}
}
// An onlyReader only implements io.Reader, no matter what other methods the underlying implementation may have.
type
onlyReader
struct
{
r
io
.
Reader
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment