snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
39
modules/util/paginate_test.go
Normal file
39
modules/util/paginate_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPaginateSlice(t *testing.T) {
|
||||
stringSlice := []string{"a", "b", "c", "d", "e"}
|
||||
result := PaginateSlice(stringSlice, 1, 2)
|
||||
assert.Equal(t, []string{"a", "b"}, result)
|
||||
|
||||
result = PaginateSlice(stringSlice, 100, 2)
|
||||
assert.Equal(t, []string{}, result)
|
||||
|
||||
result = PaginateSlice(stringSlice, 3, 2)
|
||||
assert.Equal(t, []string{"e"}, result)
|
||||
|
||||
result = PaginateSlice(stringSlice, 1, 0)
|
||||
assert.Equal(t, []string{"a", "b", "c", "d", "e"}, result)
|
||||
|
||||
result = PaginateSlice(stringSlice, 1, -1)
|
||||
assert.Equal(t, []string{"a", "b", "c", "d", "e"}, result)
|
||||
|
||||
type Test struct {
|
||||
Val int
|
||||
}
|
||||
|
||||
testVar := []*Test{{Val: 2}, {Val: 3}, {Val: 4}}
|
||||
testVar = PaginateSlice(testVar, 1, 50)
|
||||
assert.Equal(t, []*Test{{Val: 2}, {Val: 3}, {Val: 4}}, testVar)
|
||||
|
||||
testVar = PaginateSlice(testVar, 2, 2)
|
||||
assert.Equal(t, []*Test{{Val: 4}}, testVar)
|
||||
}
|
||||
Reference in New Issue
Block a user