mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 13:50:39 +00:00
Some checks failed
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Integration tests for the release process / release-simulation (push) Has been cancelled
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
// 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, ok := PaginateSlice(stringSlice, 1, 2).([]string)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []string{"a", "b"}, result)
|
|
|
|
result, ok = PaginateSlice(stringSlice, 100, 2).([]string)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []string{}, result)
|
|
|
|
result, ok = PaginateSlice(stringSlice, 3, 2).([]string)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []string{"e"}, result)
|
|
|
|
result, ok = PaginateSlice(stringSlice, 1, 0).([]string)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []string{"a", "b", "c", "d", "e"}, result)
|
|
|
|
result, ok = PaginateSlice(stringSlice, 1, -1).([]string)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []string{"a", "b", "c", "d", "e"}, result)
|
|
|
|
type Test struct {
|
|
Val int
|
|
}
|
|
|
|
testVar := []*Test{{Val: 2}, {Val: 3}, {Val: 4}}
|
|
testVar, ok = PaginateSlice(testVar, 1, 50).([]*Test)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []*Test{{Val: 2}, {Val: 3}, {Val: 4}}, testVar)
|
|
|
|
testVar, ok = PaginateSlice(testVar, 2, 2).([]*Test)
|
|
assert.True(t, ok)
|
|
assert.Equal(t, []*Test{{Val: 4}}, testVar)
|
|
}
|