-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_test.go
44 lines (40 loc) · 1.02 KB
/
map_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
package bucket_test
import (
"bytes"
"reflect"
"strings"
"testing"
"github.com/niaow/bucket"
)
func TestMapEncodeSimple(t *testing.T) {
var buf bytes.Buffer
n, err := bucket.Map{"hello world": "xyzzy"}.WriteTo(&buf)
if err != nil {
t.Errorf("failed to encode: %s", err.Error())
return
}
expect := "\x2C\x14hello worldxyzzy\x00"
if n != int64(len(expect)) {
t.Errorf("expected %d bytes written but reported %d (actually wrote %d)", len(expect), n, buf.Len())
}
got := buf.String()
if got != expect {
t.Errorf("expected encoding %q but got %q", expect, got)
}
}
func TestMapDecodeSimple(t *testing.T) {
m := make(bucket.Map)
raw := "\x2C\x14hello worldxyzzy\x00"
n, err := m.ReadFrom(strings.NewReader(raw))
if err != nil {
t.Errorf("failed to decode: %s", err.Error())
return
}
if n != int64(len(raw)) {
t.Errorf("expected %d bytes read but reported %d", len(raw), n)
}
expect := bucket.Map{"hello world": "xyzzy"}
if !reflect.DeepEqual(m, expect) {
t.Errorf("expected %v but got %v", expect, m)
}
}