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

tests: improve coverage for go/bytes2/buffer.go #14958

Merged
merged 6 commits into from
Jan 19, 2024
Merged
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
44 changes: 28 additions & 16 deletions go/bytes2/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,39 @@ package bytes2

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestBuffer(t *testing.T) {
b := NewBuffer(nil)

// Test Write function
b.Write([]byte("ab"))
assert.Equal(t, "ab", string(b.Bytes()), "Write()")

// Test WriteString function
b.WriteString("cd")
assert.Equal(t, "abcd", string(b.Bytes()), "WriteString()")

// Test WriteByte function
b.WriteByte('e')
want := "abcde"
if got := string(b.Bytes()); got != want {
t.Errorf("b.Bytes(): %s, want %s", got, want)
}
if got := b.String(); got != want {
t.Errorf("b.String(): %s, want %s", got, want)
}
if got := b.Len(); got != 5 {
t.Errorf("b.Len(): %d, want 5", got)
}
if got := b.StringUnsafe(); got != want {
t.Errorf("b.StringUnsafe(): %s, want %s", got, want)
}
if b.Reset(); len(b.bytes) != 0 {
t.Errorf("b.Reset(): got %s, want \"\"", b.bytes)
}
assert.Equal(t, "abcde", string(b.Bytes()), "WriteByte()")

// Test Bytes function
assert.Equal(t, "abcde", string(b.Bytes()))

// Test String function
assert.Equal(t, "abcde", b.String())

// Test StringUnsafe function
assert.Equal(t, "abcde", b.StringUnsafe())

// Test Len function
assert.Equal(t, 5, b.Len())

// Test Reset function
b.Reset()
assert.Equal(t, "", string(b.Bytes()))
assert.Equal(t, 0, b.Len())
}
Loading