forked from libgox/buffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer_str_test.go
50 lines (38 loc) · 1.22 KB
/
buffer_str_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package buffer
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWriteString(t *testing.T) {
b := NewBuffer(1024)
str := "hello world"
err := b.WriteString(str)
assert.NoError(t, err, "expected no error during WriteString")
assert.Equal(t, len(str), b.ReadableSize(), "expected size to be the string length")
}
func TestReadString(t *testing.T) {
b := NewBuffer(1024)
str := "hello world"
// Write the string
err := b.WriteString(str)
assert.NoError(t, err, "expected no error during WriteString")
// Reset read cursor for reading
b.readCursor = 0
// Read the string
readStr, err := b.ReadString(len(str))
assert.NoError(t, err, "expected no error during ReadString")
assert.Equal(t, str, readStr, "expected read string to match written string")
}
func TestWriteAndReadString(t *testing.T) {
b := NewBuffer(1024)
str := "test string"
// Write the string
err := b.WriteString(str)
assert.NoError(t, err, "expected no error during WriteString")
// Reset read cursor for reading
b.readCursor = 0
// Read the string
readStr, err := b.ReadString(len(str))
assert.NoError(t, err, "expected no error during ReadString")
assert.Equal(t, str, readStr, "expected read string to match written string")
}