-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_test.go
More file actions
63 lines (57 loc) · 1.34 KB
/
encode_test.go
File metadata and controls
63 lines (57 loc) · 1.34 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
package binpack
import (
"bytes"
"testing"
)
func TestEncBuffer_WriteByte(t *testing.T) {
eb := encBuffer{}
eb.WriteByte(byte('a'))
out := eb.Bytes()
in := []byte{'a'}
if !bytes.Equal(out, in) {
t.Fatalf("encBuffer:WriteByte got %v; wanted %v", out, in)
}
}
func TestEncBuffer_WriteString(t *testing.T) {
eb := encBuffer{}
eb.WriteString("abc")
out := eb.Bytes()
in := []byte{'a', 'b', 'c'}
if !bytes.Equal(out, in) {
t.Fatalf("encBuffer:WriteString got %v; wanted %v", out, in)
}
}
func TestEncBuffer_Write(t *testing.T) {
eb := encBuffer{}
n, _ := eb.Write([]byte{'a', 'b', 'c'})
if n != 3 {
t.Fatalf("encBuffer:Write wrote %v bytes; wanted %v bytes", n, 3)
}
out := eb.Bytes()
in := []byte{'a', 'b', 'c'}
if !bytes.Equal(out, in) {
t.Fatalf("encBuffer:Write got %v; wanted %v", out, in)
}
}
func TestEncBuffer_Len(t *testing.T) {
eb := encBuffer{}
_, err := eb.Write([]byte("abc日"))
if err != nil {
t.Fatal("encBuffer:Write error", err)
}
if eb.Len() != 6 {
t.Fatalf("encBuffer:Write wrote %v bytes; wanted %v bytes", eb.Len(), 6)
}
}
func TestEncBuffer_Reset(t *testing.T) {
eb := encBuffer{}
_, err := eb.Write([]byte("abc日"))
if err != nil {
t.Fatal("encBuffer:Write error", err)
}
eb.Reset()
out := eb.Bytes()
if !bytes.Equal(out, []byte{}) {
t.Fatalf("encBuffer:Reset got %v; wanted %v", out, []byte{})
}
}