1
20 package pagination
21
22 import (
23 "fmt"
24 "testing"
25
26 "github.com/stretchr/testify/assert"
27 )
28
29 func TestIndex(t *testing.T) {
30 for k, c := range []struct {
31 s []string
32 offset int
33 limit int
34 e []string
35 }{
36 {
37 s: []string{"a", "b", "c"},
38 offset: 0,
39 limit: 100,
40 e: []string{"a", "b", "c"},
41 },
42 {
43 s: []string{"a", "b", "c"},
44 offset: 0,
45 limit: 2,
46 e: []string{"a", "b"},
47 },
48 {
49 s: []string{"a", "b", "c"},
50 offset: 1,
51 limit: 10,
52 e: []string{"b", "c"},
53 },
54 {
55 s: []string{"a", "b", "c"},
56 offset: 1,
57 limit: 2,
58 e: []string{"b", "c"},
59 },
60 {
61 s: []string{"a", "b", "c"},
62 offset: 2,
63 limit: 2,
64 e: []string{"c"},
65 },
66 {
67 s: []string{"a", "b", "c"},
68 offset: 3,
69 limit: 10,
70 e: []string{},
71 },
72 {
73 s: []string{"a", "b", "c"},
74 offset: 2,
75 limit: 10,
76 e: []string{"c"},
77 },
78 {
79 s: []string{"a", "b", "c"},
80 offset: 1,
81 limit: 10,
82 e: []string{"b", "c"},
83 },
84 } {
85 t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
86 start, end := Index(c.limit, c.offset, len(c.s))
87 assert.EqualValues(t, c.e, c.s[start:end])
88 })
89 }
90 }
91
View as plain text