-
Notifications
You must be signed in to change notification settings - Fork 4
/
enc_b64_test.go
67 lines (62 loc) · 1.17 KB
/
enc_b64_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
64
65
66
67
package jx
import (
"bytes"
"fmt"
"testing"
)
func TestEncoder_Base64(t *testing.T) {
t.Run("Values", func(t *testing.T) {
for i, s := range [][]byte{
[]byte(`1`),
[]byte(`12`),
[]byte(`2345`),
{1, 2, 3, 4, 5, 6},
bytes.Repeat([]byte{1}, encoderBufSize-1),
bytes.Repeat([]byte{1}, encoderBufSize),
bytes.Repeat([]byte{1}, encoderBufSize+1),
} {
s := s
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
requireCompat(t, func(e *Encoder) {
e.Base64(s)
}, s)
})
}
})
t.Run("Zeroes", func(t *testing.T) {
t.Run("Nil", func(t *testing.T) {
s := []byte(nil)
requireCompat(t, func(e *Encoder) {
e.Base64(s)
}, s)
})
t.Run("ZeroLen", func(t *testing.T) {
s := make([]byte, 0)
requireCompat(t, func(e *Encoder) {
e.Base64(s)
}, s)
})
})
}
func BenchmarkEncoder_Base64(b *testing.B) {
for _, n := range []int{
128,
256,
512,
1024,
} {
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
var v []byte
for i := 0; i < n; i++ {
v = append(v, byte(i%256))
}
b.ReportAllocs()
b.SetBytes(int64(n))
var e Encoder
for i := 0; i < b.N; i++ {
e.Base64(v)
e.Reset()
}
})
}
}