-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
executable file
·63 lines (56 loc) · 1.25 KB
/
reader_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
61
62
63
package iabtcf
import (
"encoding/base64"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestReader(t *testing.T) {
type TestCase struct {
Base64 string
}
values := map[string]*TestCase{
"101": {
Base64: "oA",
},
"00000001": {
Base64: "AQ",
},
"00000101": {
Base64: "BQ",
},
"10000101": {
Base64: "hQ",
},
"00000001 00000101": {
Base64: "AQU",
},
"00000001 101": {
Base64: "AaA",
},
"00000001 00000000": {
Base64: "AQA",
},
"00000001 00000000 1": {
Base64: "AQCA",
},
"00000001 0000001": {
Base64: "AQI",
},
}
for bitString, tc := range values {
t.Run(bitString, func(t *testing.T) {
t.Helper()
fmt.Printf("\n[test] ---------- %s ---------- \n", bitString)
wantBytes, err := base64.RawURLEncoding.DecodeString(tc.Base64)
fmt.Printf("[test] base64: %s >>> bytes: %v \n", tc.Base64, wantBytes)
require.NoError(t, err, "unexpected base64 error")
length := len(strings.ReplaceAll(bitString, " ", ""))
reader := NewReader(wantBytes)
gotBits, err := reader.ReadBitField(length)
require.NoError(t, err, "unexpected reader error")
fmt.Printf("[test] %s (%d) >>> bytes: %v >>> bitfield: %s \n", bitString, length, gotBits, gotBits.ToBitString())
})
}
}