-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinteger_test.go
59 lines (49 loc) · 1.15 KB
/
integer_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
package base62
import (
"bytes"
"math"
"testing"
)
func Test_FormatUint_ParseUint(t *testing.T) {
x := uint64(math.MaxUint64)
dst := FormatUint(x)
got, err := ParseUint(dst)
if err != nil {
t.Fatalf("failed parse uint, err = %v", err)
}
if got != x {
t.Fatalf("failed parse uint, got = %v, want = %v", got, x)
}
}
func Test_FormatUint_ParseInt(t *testing.T) {
x := int64(math.MaxInt64)
dst := FormatInt(x)
got, err := ParseInt(dst)
if err != nil {
t.Fatalf("failed parse int, err = %v", err)
}
if got != x {
t.Fatalf("failed parse int, got = %v, want = %v", got, x)
}
}
func Test_AppendInt_AppendUint(t *testing.T) {
x := int64(math.MaxInt64)
dst1 := AppendInt(nil, x)
dst2 := AppendUint(nil, uint64(x))
if !bytes.Equal(dst1, dst2) {
t.Fatal("integer append result not equal")
}
}
func Test_FormatInt_Zero(t *testing.T) {
dst := FormatInt(0)
if len(dst) != 1 || dst[0] != encodeStd[0] {
t.Fatalf("failed format zero int, got = %v", string(dst))
}
got, err := ParseInt(dst)
if err != nil {
t.Fatalf("failed parse zero int, err = %v", err)
}
if got != 0 {
t.Fatalf("failed parse zero int, got = %v, want = 0", got)
}
}