-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbytes_test.go
50 lines (44 loc) · 923 Bytes
/
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
package bip32
import (
"bytes"
"testing"
)
func TestReverseCopy(t *testing.T) {
testCases := []struct {
dst, src []byte
expect []byte
}{
{
make([]byte, 4),
[]byte{0x12, 0x34},
[]byte{0x00, 0x00, 0x12, 0x34},
},
{
make([]byte, 2),
[]byte{0x12, 0x34, 0x56},
[]byte{0x34, 0x56},
},
}
for i, c := range testCases {
ReverseCopy(c.dst, c.src)
if !bytes.Equal(c.dst, c.expect) {
t.Fatalf("#%d failed: got %x, expect %x", i, c.dst, c.expect)
}
}
}
func TestPaddedAppend(t *testing.T) {
testCases := []struct {
size uint
dst, src []byte
expect []byte
}{
{2, nil, []byte{0x12}, []byte{0x00, 0x12}},
{1, nil, []byte{0x12}, []byte{0x12}},
{0, nil, []byte{0x12}, []byte{0x12}},
}
for i, c := range testCases {
if got := paddedAppend(c.size, c.dst, c.src); !bytes.Equal(got, c.expect) {
t.Fatalf("#%d failed: got %x, expect %x", i, got, c.expect)
}
}
}