generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytes_test.go
60 lines (50 loc) · 1.1 KB
/
bytes_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
51
52
53
54
55
56
57
58
59
60
package qcodec
import (
"reflect"
"testing"
)
func TestBytes(t *testing.T) {
var x Codec = Bytes{}
_ = x
cases := []struct {
input []byte
want int
}{
{[]byte(""), 0},
{[]byte("a"), 1},
{[]byte("abc"), 3},
}
for i, c := range cases {
m := Bytes{size: c.want}
l := m.Size(c.input)
if l != c.want {
t.Fatalf("%d-th: Size: input: %v; want: %v; actual: %v",
i+1, c.input, c.want, l)
}
rst := m.Encode(c.input)
if len(rst) != c.want {
t.Fatalf("%d-th: encoded len: input: %v; want: %v; actual: %v",
i+1, c.input, c.want, len(rst))
}
l = m.EncodedSize(rst)
if l != c.want {
t.Fatalf("%d-th: encoded size: input: %v; want: %v; actual: %v",
i+1, c.input, c.want, l)
}
n, s := m.Decode(rst)
if c.want != n {
t.Fatalf("%d-th: decoded size: input: %v; want: %v; actual: %v",
i+1, c.input, c.want, n)
}
if !reflect.DeepEqual(c.input, s) {
t.Fatalf("%d-th: decode: input: %v; want: %v; actual: %v",
i+1, c.input, c.input, s)
}
if len(rst) > 0 {
rst[0] = 'x'
if s.([]byte)[0] != 'x' {
t.Fatalf("should be not be copied.")
}
}
}
}