forked from speps/go-hashids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashids_bad_input_test.go
52 lines (46 loc) · 1.37 KB
/
hashids_bad_input_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 hashids
import (
"testing"
)
func TestSmallAlphabet(t *testing.T) {
hdata := NewData()
hdata.Alphabet = "1234567890"
_, err := NewWithData(hdata)
expected := "alphabet must contain at least 16 characters"
if err == nil || err.Error() != expected {
t.Errorf("Expected error `%s` but got `%s`", expected, err)
}
}
func TestSpacesInAlphabet(t *testing.T) {
hdata := NewData()
hdata.Alphabet = "a cdefghijklmnopqrstuvwxyz"
_, err := NewWithData(hdata)
expected := "alphabet may not contain spaces"
if err == nil || err.Error() != expected {
t.Errorf("Expected error `%s` but got `%s`", expected, err)
}
}
func TestNilWithEncode(t *testing.T) {
h, _ := New()
_, err := h.Encode(nil)
expected := "encoding empty array of numbers makes no sense"
if err == nil || err.Error() != expected {
t.Errorf("Expected error `%s` but got `%s`", expected, err)
}
}
func TestEmptySliceWithEncode(t *testing.T) {
h, _ := New()
_, err := h.Encode([]int{})
expected := "encoding empty array of numbers makes no sense"
if err == nil || err.Error() != expected {
t.Errorf("Expected error `%s` but got `%s`", expected, err)
}
}
func TestNegativeNumberWithEncode(t *testing.T) {
h, _ := New()
_, err := h.Encode([]int{-1})
expected := "negative number not supported"
if err == nil || err.Error() != expected {
t.Errorf("Expected error `%s` but got `%s`", expected, err)
}
}