-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
limit_test.go
74 lines (70 loc) · 1.25 KB
/
limit_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
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package pagination
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIndex(t *testing.T) {
for k, c := range []struct {
s []string
offset int
limit int
e []string
}{
{
s: []string{"a", "b", "c"},
offset: 0,
limit: 100,
e: []string{"a", "b", "c"},
},
{
s: []string{"a", "b", "c"},
offset: 0,
limit: 2,
e: []string{"a", "b"},
},
{
s: []string{"a", "b", "c"},
offset: 1,
limit: 10,
e: []string{"b", "c"},
},
{
s: []string{"a", "b", "c"},
offset: 1,
limit: 2,
e: []string{"b", "c"},
},
{
s: []string{"a", "b", "c"},
offset: 2,
limit: 2,
e: []string{"c"},
},
{
s: []string{"a", "b", "c"},
offset: 3,
limit: 10,
e: []string{},
},
{
s: []string{"a", "b", "c"},
offset: 2,
limit: 10,
e: []string{"c"},
},
{
s: []string{"a", "b", "c"},
offset: 1,
limit: 10,
e: []string{"b", "c"},
},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
start, end := Index(c.limit, c.offset, len(c.s))
assert.EqualValues(t, c.e, c.s[start:end])
})
}
}