2023-12-01 08:57:08 +03:00
|
|
|
package m
|
|
|
|
|
|
|
|
import (
|
2023-12-02 13:19:22 +03:00
|
|
|
"fmt"
|
2023-12-01 08:57:08 +03:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/walles/moar/twin"
|
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
)
|
|
|
|
|
2023-12-02 13:19:22 +03:00
|
|
|
const screenHeight = 60
|
|
|
|
|
2023-12-01 10:33:47 +03:00
|
|
|
// 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) {
|
2023-12-01 08:57:08 +03:00
|
|
|
pager := Pager{}
|
2023-12-02 13:19:22 +03:00
|
|
|
pager.screen = twin.NewFakeScreen(100, screenHeight)
|
2023-12-01 08:57:08 +03:00
|
|
|
pager.reader = NewReaderFromText("test", strings.Repeat("a\n", 2000))
|
|
|
|
pager.ShowLineNumbers = true
|
2023-12-02 13:19:22 +03:00
|
|
|
pager.ShowStatusBar = withStatusBar
|
2023-12-01 10:33:47 +03:00
|
|
|
pager.scrollPosition = scrollPosition{
|
2023-12-01 08:57:08 +03:00
|
|
|
internalDontTouch: scrollPositionInternal{
|
2023-12-02 13:19:22 +03:00
|
|
|
lineNumberOneBased: currentStartLine,
|
2023-12-01 08:57:08 +03:00
|
|
|
deltaScreenLines: 0,
|
2023-12-01 11:06:26 +03:00
|
|
|
name: "findFirstHit",
|
2023-12-01 08:57:08 +03:00
|
|
|
canonicalizing: false,
|
|
|
|
},
|
|
|
|
}
|
2023-12-01 11:06:26 +03:00
|
|
|
|
|
|
|
lastVisiblePosition := scrollPosition{
|
|
|
|
internalDontTouch: scrollPositionInternal{
|
2023-12-02 13:19:22 +03:00
|
|
|
lineNumberOneBased: lastVisibleLine,
|
2023-12-01 11:06:26 +03:00
|
|
|
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-01 08:57:08 +03:00
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
2023-12-01 08:57:08 +03:00
|
|
|
}
|