-
Notifications
You must be signed in to change notification settings - Fork 0
/
base32flex_test.go
59 lines (53 loc) · 1.4 KB
/
base32flex_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
package base32flex
import (
"encoding/base32"
"reflect"
"strings"
"testing"
)
func Test_base32flex(t *testing.T) {
tests := []struct {
name string
data string
}{
{"", "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
originalBytes, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(tt.data)
if err != nil {
t.Fatal(err)
}
// LowerEncoding
lowerString := LowerEncoding.EncodeToString(originalBytes)
if strings.ContainsAny(lowerString, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") {
t.Fatal("LowerEncoding has problem.")
}
if strings.ContainsAny(lowerString, "01lo") {
t.Fatal("LowerEncoding has problem.")
}
lowerBytes, err := LowerEncoding.DecodeString(lowerString)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(originalBytes, lowerBytes) {
t.Fatal("LowerEncoding has problem.")
}
// UpperEncoding
upperString := UpperEncoding.EncodeToString(originalBytes)
if strings.ContainsAny(upperString, "abcdefghijklmnopqrstuvwxyz") {
t.Fatal("UpperEncoding has problem.")
}
if strings.ContainsAny(upperString, "01IO") {
t.Fatal("UpperEncoding has problem.")
}
upperBytes, err := UpperEncoding.DecodeString(upperString)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(originalBytes, upperBytes) {
t.Fatal("UpperEncoding has problem.")
}
})
}
}