1
1
mirror of https://github.com/walles/moar.git synced 2024-11-27 01:05:23 +03:00

Test that scolling to the last line works

It doesn't when we're in word wrapping mode.

Not sure how to fix this, but it is broken.
This commit is contained in:
Johan Walles 2021-05-27 06:48:51 +02:00
parent 3dd20e609d
commit ecae4811de
3 changed files with 45 additions and 3 deletions

View File

@ -12,7 +12,7 @@ func tokenize(input string) []twin.Cell {
return line.HighlightedTokens(nil)
}
func toString(cellLines [][]twin.Cell) string {
func rowsToString(cellLines [][]twin.Cell) string {
returnMe := ""
for _, cellLine := range cellLines {
lineString := ""
@ -43,7 +43,7 @@ func assertWrap(t *testing.T, input string, width int, wrappedLines ...string) {
}
t.Errorf("When wrapping <%s> at width %d:\n--Expected--\n%s\n\n--Actual--\n%s",
input, width, toString(expected), toString(actual))
input, width, rowsToString(expected), rowsToString(actual))
}
func TestEnoughRoomNoWrapping(t *testing.T) {

View File

@ -501,6 +501,10 @@ func removeLastChar(s string) string {
return s[:len(s)-size]
}
func (p *Pager) _ScrollToEnd() {
p.firstLineOneBased = p.reader.GetLineCount()
}
func (p *Pager) _OnSearchKey(key twin.KeyCode) {
switch key {
case twin.KeyEscape, twin.KeyEnter:
@ -658,7 +662,7 @@ func (p *Pager) _OnRune(char rune) {
p.firstLineOneBased = 1
case '>', 'G':
p.firstLineOneBased = p.reader.GetLineCount()
p._ScrollToEnd()
case 'f', ' ':
_, height := p.screen.Size()

View File

@ -303,6 +303,44 @@ func TestFindFirstLineOneBasedAnsi(t *testing.T) {
assert.Check(t, *hitLine == 1)
}
// Converts a cell row to a plain string and removes trailing whitespace.
func rowToString(row []twin.Cell) string {
rowString := ""
for _, cell := range row {
rowString += string(cell.Rune)
}
return strings.TrimRight(rowString, " ")
}
func TestScrollToBottomWrapNextToLastLine(t *testing.T) {
reader := NewReaderFromStream("",
strings.NewReader("first line\nline two will be wrapped\nhere's the last line"))
pager := NewPager(reader)
pager.WrapLongLines = true
pager.ShowLineNumbers = false
// Wait for reader to finish reading
<-reader.done
// This is what we're testing really
pager._ScrollToEnd()
// Heigh 3 = two lines of contents + one footer
screen := twin.NewFakeScreen(10, 3)
// Exit immediately
pager.Quit()
// Get contents onto our fake screen
pager.StartPaging(screen)
pager._Redraw("")
lastVisibleRow := screen.GetRow(1)
lastVisibleRowString := rowToString(lastVisibleRow)
assert.Equal(t, lastVisibleRowString, "last line")
}
func benchmarkSearch(b *testing.B, highlighted bool) {
// Pick a go file so we get something with highlighting
_, sourceFilename, _, ok := runtime.Caller(0)