-
Notifications
You must be signed in to change notification settings - Fork 14
/
blocklist_test.go
39 lines (34 loc) · 1.06 KB
/
blocklist_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
package sqids
import (
"reflect"
"testing"
)
func TestBlocklist(t *testing.T) {
numbers := []uint64{1, 2, 3}
id := "TM0x1Mxz"
s, err := NewSqids(Options{
Alphabet: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
MinLength: 0,
Blocklist: &[]string{
"8QRLaD", // normal result of 1st encoding, let's block that word on purpose
"7T1cd0dL", // result of 2nd encoding
"UeIe", // result of 3rd encoding is `RA8UeIe7`, let's block a substring
"imhw", // result of 4th encoding is `WM3Limhw`, let's block the postfix
"LfUQ", // result of 4th encoding is `LfUQh4HN`, let's block the prefix
},
})
if err != nil {
t.Fatal(err)
}
generatedID, err := s.Encode(numbers)
if err != nil {
t.Fatal(err)
}
if id != generatedID {
t.Errorf("Encoding `%v` should produce `%v`, but instead produced `%v`", numbers, id, generatedID)
}
decodedNumbers := s.Decode(id)
if !reflect.DeepEqual(numbers, decodedNumbers) {
t.Errorf("Decoding `%v` should produce `%v`, but instead produced `%v`", id, numbers, decodedNumbers)
}
}