-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathhashids_custom_alphabet_test.go
46 lines (37 loc) · 1.12 KB
/
hashids_custom_alphabet_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
package hashids
import (
"reflect"
"testing"
)
func testAlphabet(alphabet string, t *testing.T) {
numbers := []int{1, 2, 3}
hdata := NewData()
hdata.Alphabet = alphabet
h, _ := NewWithData(hdata)
e, err := h.Encode(numbers)
decodedNumbers := h.Decode(e)
if err != nil {
t.Errorf("Expected no error but got `%s`", err)
}
if !reflect.DeepEqual(decodedNumbers, numbers) {
t.Errorf("Decoded numbers `%v` did not match with original `%v`", decodedNumbers, numbers)
}
}
func TestShouldWorkWithWorst(t *testing.T) {
testAlphabet("cCsSfFhHuUiItT01", t)
}
func TestShouldWorkWithHalfSeparators(t *testing.T) {
testAlphabet("abdegjklCFHISTUc", t)
}
func TestShouldWorkWithTwoSeparators(t *testing.T) {
testAlphabet("abdegjklmnopqrSF", t)
}
func TestShouldWorkWithNoSeparators(t *testing.T) {
testAlphabet("abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890", t)
}
func TestShouldWorkWithSuperlong(t *testing.T) {
testAlphabet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+\\|'\";:/?.>,<{[}]", t)
}
func TestShouldWorkWithWeird(t *testing.T) {
testAlphabet("`~!@#$%^&*()-_=+\\|'\";:/?.>,<{[}]", t)
}