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
|
package ber
import (
"bytes"
"testing"
)
type lenTest struct {
in int
out []byte
}
var lenTestData = []lenTest{
{0, []byte{0x00}},
{23, []byte{0x17}},
{193, []byte{0x81, 0xc1}},
{240, []byte{0x81, 0xf0}},
{257, []byte{0x82, 0x01, 0x01}},
}
func TestLen(t *testing.T) {
for _, test := range lenTestData {
buf := &bytes.Buffer{}
MarshalLen(buf, test.in)
a := buf.Bytes()
if !bytes.Equal(a, test.out) {
t.Error(test.in, "expected", test.out, "got", a)
}
n := UnmarshalLen(bytes.NewBuffer(test.out))
if n != test.in {
t.Error(test.out, "expected", test.in, "got", n)
}
}
}
|