-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination_test.go
107 lines (103 loc) · 1.79 KB
/
pagination_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package pagination
import (
"fmt"
"reflect"
"testing"
)
func TestNewPager(t *testing.T) {
for _, tc := range []struct {
currentPage int
perPage int
total int
exp *Pager
}{
{
currentPage: 1,
perPage: 1,
total: 10,
exp: &Pager{
Total: 10,
PerPage: 1,
CurrentPage: 1,
LastPage: 10,
NextPage: intPtr(2),
PrevPage: nil,
},
},
{
currentPage: 10,
perPage: 1,
total: 10,
exp: &Pager{
Total: 10,
PerPage: 1,
CurrentPage: 10,
LastPage: 10,
NextPage: nil,
PrevPage: intPtr(9),
},
},
{
currentPage: 1,
perPage: 10,
total: 10,
exp: &Pager{
Total: 10,
PerPage: 10,
CurrentPage: 1,
LastPage: 1,
NextPage: nil,
PrevPage: nil,
},
},
{
currentPage: 1,
perPage: 1,
total: 0,
exp: &Pager{
Total: 0,
PerPage: 1,
CurrentPage: 1,
LastPage: 0,
NextPage: nil,
PrevPage: nil,
},
},
{
currentPage: 2,
perPage: 33,
total: 100,
exp: &Pager{
Total: 100,
PerPage: 33,
CurrentPage: 2,
LastPage: 4,
NextPage: intPtr(3),
PrevPage: intPtr(1),
},
},
{
currentPage: 99,
perPage: 1,
total: 10,
exp: &Pager{
Total: 10,
PerPage: 1,
CurrentPage: 99,
LastPage: 10,
NextPage: nil,
PrevPage: intPtr(98),
},
},
} {
t.Run(fmt.Sprintf("NewPager(%d,%d,%d)", tc.currentPage, tc.perPage, tc.total), func(t *testing.T) {
p := NewPager(tc.currentPage, tc.perPage, tc.total)
if !reflect.DeepEqual(p, tc.exp) {
t.Errorf("got %#v, want %#v", p, tc.exp)
}
})
}
}
func intPtr(i int) *int {
return &i
}