Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytes: clean up a test #29996

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/bytes/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,17 @@ func TestBasicOperations(t *testing.T) {
check(t, "TestBasicOperations (3)", &buf, "")

n, err := buf.Write(testBytes[0:1])
if n != 1 {
t.Errorf("wrote 1 byte, but n == %d", n)
}
if err != nil {
t.Errorf("err should always be nil, but err == %s", err)
if want := 1; err != nil || n != want {
t.Errorf("Write: got (%d, %v), want (%d, %v)", n, err, want, nil)
}
check(t, "TestBasicOperations (4)", &buf, "a")

buf.WriteByte(testString[1])
check(t, "TestBasicOperations (5)", &buf, "ab")

n, err = buf.Write(testBytes[2:26])
if n != 24 {
t.Errorf("wrote 24 bytes, but n == %d", n)
if want := 24; err != nil || n != want {
t.Errorf("Write: got (%d, %v), want (%d, %v)", n, err, want, nil)
}
check(t, "TestBasicOperations (6)", &buf, testString[0:26])

Expand All @@ -159,15 +156,12 @@ func TestBasicOperations(t *testing.T) {

buf.WriteByte(testString[1])
c, err := buf.ReadByte()
if err != nil {
t.Error("ReadByte unexpected eof")
}
if c != testString[1] {
t.Errorf("ReadByte wrong value c=%v", c)
if want := testString[1]; err != nil || c != want {
t.Errorf("ReadByte: got (%q, %v), want (%q, %v)", c, err, want, nil)
}
c, err = buf.ReadByte()
if err == nil {
t.Error("ReadByte unexpected not eof")
if err != io.EOF {
t.Errorf("ReadByte: got (%q, %v), want (%q, %v)", c, err, byte(0), io.EOF)
}
}
}
Expand Down