From 4baeb07cb7affeb1d1ad0d7804594e22c5eb6b2a Mon Sep 17 00:00:00 2001 From: Jon Lundy Date: Sun, 20 Nov 2022 10:17:15 -0700 Subject: [PATCH] fix: start position when first > 1 --- pkg/math/math.go | 6 +++++- pkg/math/math_test.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/math/math.go b/pkg/math/math.go index 56ff8d0..117b63f 100644 --- a/pkg/math/math.go +++ b/pkg/math/math.go @@ -43,7 +43,11 @@ func PagerBox(first, last uint64, pos, count int64) (uint64, int64) { var start uint64 if pos >= 0 { - start = first + uint64(pos) + if int64(first) > pos { + start = first + } else { + start = uint64(pos) + 1 + } } else { start = uint64(int64(last) + pos + 1) } diff --git a/pkg/math/math_test.go b/pkg/math/math_test.go index 2ae1d90..106951c 100644 --- a/pkg/math/math_test.go +++ b/pkg/math/math_test.go @@ -76,6 +76,8 @@ func TestPagerBox(t *testing.T) { {1, 10, 10, 10, 0, 0}, {1, 10, 0, es.AllEvents, 1, 10}, {1, 10, -1, -es.AllEvents, 10, -10}, + + {5, 10, 0, 1, 5, 1}, } for _, tt := range tests {