-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
alphabet_test.go
52 lines (46 loc) · 1.05 KB
/
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
47
48
49
50
51
52
package shortuuid
import (
"strings"
"testing"
)
func TestDedupe(t *testing.T) {
tests := []struct {
in, out string
}{
{"01010101010101", "01"},
{"abcabcfoo", "abcfo"},
}
for _, test := range tests {
in := strings.Join(dedupe(strings.Split(test.in, "")), "")
if in != test.out {
t.Errorf("expected %q, got %q", in, test.out)
}
}
}
func TestAlphabetIndex(t *testing.T) {
abc := newAlphabet(DefaultAlphabet)
idx, err := abc.Index('z')
if err != nil {
t.Errorf("expected index 56, got an error trying to get it %v", err)
}
if idx != 56 {
t.Errorf("expected index 56, got %d", idx)
}
}
func TestAlphabetIndexZero(t *testing.T) {
abc := newAlphabet(DefaultAlphabet)
idx, err := abc.Index('2')
if err != nil {
t.Errorf("expected index 0, got an error trying to get it %v", err)
}
if idx != 0 {
t.Errorf("expected index 0, got %d", idx)
}
}
func TestAlphabetIndexError(t *testing.T) {
abc := newAlphabet(DefaultAlphabet)
idx, err := abc.Index('l')
if err == nil {
t.Errorf("expected an error, got a valid index %d", idx)
}
}