-
Notifications
You must be signed in to change notification settings - Fork 0
/
base64_test.go
117 lines (97 loc) · 3.12 KB
/
base64_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package slice
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
// ------------------------------------------------- Base64Decode ------------------------------------------------------
func TestBase64Decode(t *testing.T) {
s := "Q0MxMTAwMTEwMA=="
decodeBytes := Base64Decode([]byte(s))
exceptBytes := []byte{67, 67, 49, 49, 48, 48, 49, 49, 48, 48, 0, 0}
assert.Equal(t, exceptBytes, decodeBytes)
}
func ExampleBase64Decode() {
s := "Q0MxMTAwMTEwMA=="
decode := Base64Decode([]byte(s))
fmt.Println(decode)
// Output:
// [67 67 49 49 48 48 49 49 48 48 0 0]
}
// ------------------------------------------------- Base64DecodeAsString ----------------------------------------------
func TestBase64DecodeAsString(t *testing.T) {
s := "Q0MxMTAwMTEwMA=="
decodeString := Base64DecodeAsString([]byte(s))
fmt.Println(decodeString)
}
func ExampleBase64DecodeAsString() {
s := "Q0MxMTAwMTEwMA=="
decodeString := Base64DecodeAsString([]byte(s))
fmt.Println(decodeString)
// Output:
// CC11001100
}
// ------------------------------------------------- Base64DecodeAsStringE ---------------------------------------------
func TestBase64DecodeAsStringE(t *testing.T) {
s := "1"
_, err := Base64DecodeAsStringE([]byte(s))
assert.NotNil(t, err)
}
func ExampleBase64DecodeAsStringE() {
s := "Q0MxMTAwMTEwMA=="
decodeString, err := Base64DecodeAsStringE([]byte(s))
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(decodeString)
// Output:
// CC11001100
}
// ------------------------------------------------- Base64DecodeE -----------------------------------------------------
func TestBase64DecodeE(t *testing.T) {
s := "Q0MxMTAwMTEwMA=="
decodeBytes, err := Base64DecodeE([]byte(s))
assert.Nil(t, err)
exceptBytes := []byte{67, 67, 49, 49, 48, 48, 49, 49, 48, 48, 0, 0}
assert.Equal(t, exceptBytes, decodeBytes)
}
func ExampleBase64DecodeE() {
s := "Q0MxMTAwMTEwMA=="
decodeBytes, err := Base64DecodeE([]byte(s))
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(decodeBytes)
// Output:
// [67 67 49 49 48 48 49 49 48 48 0 0]
}
// ------------------------------------------------- Base64Encode ------------------------------------------------------
func TestBase64Encode(t *testing.T) {
s := "CC11001100"
encodeBytes := Base64Encode([]byte(s))
exceptBytes := []byte{81, 48, 77, 120, 77, 84, 65, 119, 77, 84, 69, 119, 77, 65, 61, 61}
assert.Equal(t, exceptBytes, encodeBytes)
}
func ExampleBase64Encode() {
s := "CC11001100"
encodeBytes := Base64Encode([]byte(s))
fmt.Println(encodeBytes)
// Output:
// [81 48 77 120 77 84 65 119 77 84 69 119 77 65 61 61]
}
// ------------------------------------------------- Base64EncodeAsString ----------------------------------------------
func TestBase64EncodeAsString(t *testing.T) {
s := "CC11001100"
s2 := Base64EncodeAsString([]byte(s))
assert.Equal(t, "Q0MxMTAwMTEwMA==", s2)
}
func ExampleBase64EncodeAsString() {
s := "CC11001100"
s2 := Base64EncodeAsString([]byte(s))
fmt.Println(s2)
// Output:
// Q0MxMTAwMTEwMA==
}
// ------------------------------------------------- -------------------------------------------------------------------