-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencoding_test.go
68 lines (56 loc) · 1.32 KB
/
encoding_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
60
61
62
63
64
65
66
67
68
package main
import (
"math"
"testing"
)
func TestEncode(t *testing.T) {
slug, err := EncodeId(12)
if err != nil {
t.Error("12 is a valid id")
}
if slug != "DAA" {
t.Error("slug should be DAA, got", slug)
}
}
func TestEncodeIdReturnsErrorOnNegativeInput(t *testing.T) {
_, err := EncodeId(-1)
if err == nil {
t.Error("EncodeId should return error on negative input")
}
}
func TestEncodeIdReturnsShortSlugOnInt8(t *testing.T) {
slug, err := EncodeId(math.MaxInt8)
if err != nil {
t.Error("127 is an allowed value")
}
if slug != "fwA" {
t.Error("MaxInt8 should map to fwA. got", slug)
}
}
func TestEncodeIdReturnsShortSlugOnInt16(t *testing.T) {
slug, err := EncodeId(math.MaxInt16)
if err != nil {
t.Error("32767 is an allowed value")
}
if slug != "_38" {
t.Error("MaxInt16 should map to _38. got", slug)
}
}
func TestEncodeIdReturnsShortSlugOnInt32(t *testing.T) {
slug, err := EncodeId(math.MaxInt32)
if err != nil {
t.Error("2147483647 is an allowed value")
}
if slug != "____fw" {
t.Error("MaxInt32 should map to ____fw. got", slug)
}
}
func TestEncodeIdReturnsShortSlugOnInt64(t *testing.T) {
slug, err := EncodeId(math.MaxInt64)
if err != nil {
t.Error("9223372036854775807 is an allowed value")
}
if slug != "_________38" {
t.Error("MaxInt64 should map to _________38. got", slug)
}
}