1
1
mirror of https://github.com/walles/moar.git synced 2024-11-30 12:42:26 +03:00
moar/m/scrollPosition_test.go

56 lines
1.5 KiB
Go
Raw Normal View History

package m
import (
2023-12-02 13:19:22 +03:00
"fmt"
"strings"
"testing"
"github.com/walles/moar/twin"
"gotest.tools/v3/assert"
)
2023-12-02 13:19:22 +03:00
const screenHeight = 60
// Repro for: https://github.com/walles/moar/issues/166
2023-12-02 13:19:22 +03:00
func testCanonicalize1000(t *testing.T, withStatusBar bool, currentStartLine int, lastVisibleLine int) {
pager := Pager{}
2023-12-02 13:19:22 +03:00
pager.screen = twin.NewFakeScreen(100, screenHeight)
pager.reader = NewReaderFromText("test", strings.Repeat("a\n", 2000))
pager.ShowLineNumbers = true
2023-12-02 13:19:22 +03:00
pager.ShowStatusBar = withStatusBar
pager.scrollPosition = scrollPosition{
internalDontTouch: scrollPositionInternal{
2023-12-02 13:19:22 +03:00
lineNumberOneBased: currentStartLine,
deltaScreenLines: 0,
name: "findFirstHit",
canonicalizing: false,
},
}
lastVisiblePosition := scrollPosition{
internalDontTouch: scrollPositionInternal{
2023-12-02 13:19:22 +03:00
lineNumberOneBased: lastVisibleLine,
deltaScreenLines: 0,
name: "Last Visible Position",
},
}
2023-12-02 13:19:22 +03:00
assert.Equal(t, lastVisiblePosition.lineNumberOneBased(&pager), lastVisibleLine)
}
func TestCanonicalize1000WithStatusBar(t *testing.T) {
for startLine := 0; startLine < 1500; startLine++ {
t.Run(fmt.Sprint("startLine=", startLine), func(t *testing.T) {
testCanonicalize1000(t, true, startLine, startLine+screenHeight-2)
})
}
}
2023-12-02 13:19:22 +03:00
func TestCanonicalize1000WithoutStatusBar(t *testing.T) {
for startLine := 0; startLine < 1500; startLine++ {
t.Run(fmt.Sprint("startLine=", startLine), func(t *testing.T) {
testCanonicalize1000(t, false, startLine, startLine+screenHeight-1)
})
}
}