-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_encoding_writer_test.go
More file actions
executable file
·71 lines (66 loc) · 1.32 KB
/
binary_encoding_writer_test.go
File metadata and controls
executable file
·71 lines (66 loc) · 1.32 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
64
65
66
67
68
69
70
71
package wax_test
import (
"bytes"
"reflect"
"testing"
"github.com/bearmini/wax"
)
func TestBinaryEncodingWriterVarintN(t *testing.T) {
testData := []struct {
Name string
Value int64
Expected []byte
}{
{
Name: "pattern 1",
Value: 1,
Expected: []byte{0x01},
},
{
Name: "pattern 2",
Value: -1,
Expected: []byte{0x7F},
},
{
Name: "pattern 3",
Value: -2,
Expected: []byte{0x7E},
},
{
Name: "pattern 5",
Value: -624485,
Expected: []byte{0x9B, 0xF1, 0x59},
},
/*
{
Name: "pattern 4",
Bytes: []byte{0xFE, 0xFF, 0x7F},
Consumed: []byte{0xFE, 0xFF, 0x7F},
N: 16,
Expected: -2,
},
{
Name: "pattern 6",
Bytes: []byte{0x80, 0x88, 0x80, 0x80, 0x00},
Consumed: []byte{0x80, 0x88, 0x80, 0x80, 0x00},
N: 32,
Expected: 0x400,
},
*/
}
for _, data := range testData {
data := data // capture
t.Run(data.Name, func(t *testing.T) {
//t.Parallel()
buf := bytes.NewBuffer([]byte{})
bew := wax.NewBinaryEncodingWriter(buf)
err := bew.WriteVarint(data.Value)
if err != nil {
t.Fatalf("unexpected error: %+v", err)
}
if !reflect.DeepEqual(data.Expected, buf.Bytes()) {
t.Fatalf("\nExpected: %+v\nActual: %+v", data.Expected, buf.Bytes())
}
})
}
}