-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
binary_test.go
50 lines (41 loc) · 1.02 KB
/
binary_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 httpsfv
import (
"bytes"
"strings"
"testing"
)
func TestBinary(t *testing.T) {
t.Parallel()
var bd strings.Builder
_ = marshalBinary(&bd, []byte{4, 2})
if bd.String() != ":BAI=:" {
t.Error("marshalBinary(): invalid")
}
}
func TestParseBinary(t *testing.T) {
t.Parallel()
data := []struct {
in string
out []byte
err bool
}{
{":YWJj:", []byte("abc"), false},
{":YW55IGNhcm5hbCBwbGVhc3VyZQ==:", []byte("any carnal pleasure"), false},
{":YW55IGNhcm5hbCBwbGVhc3Vy:", []byte("any carnal pleasur"), false},
{"", []byte{}, false},
{":", []byte{}, false},
{":YW55IGNhcm5hbCBwbGVhc3Vy", []byte{}, false},
{":YW55IGNhcm5hbCBwbGVhc3Vy~", []byte{}, false},
{":YW55IGNhcm5hbCBwbGVhc3VyZQ=:", []byte{}, false},
}
for _, d := range data {
s := &scanner{data: d.in}
i, err := parseBinary(s)
if d.err && err == nil {
t.Errorf("parseBinary(%s): error expected", d.in)
}
if !d.err && !bytes.Equal(d.out, i) {
t.Errorf("parseBinary(%s) = %v, %v; %v, <nil> expected", d.in, i, err, d.out)
}
}
}