1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 21:50:43 +03:00

Make the tests compile

This commit is contained in:
Johan Walles 2024-01-09 13:52:59 +01:00
parent 1164972796
commit 8e81a04188
5 changed files with 30 additions and 14 deletions

View File

@ -462,7 +462,7 @@ func TestIsScrolledToEnd_WrappedLastLine(t *testing.T) {
pager.scrollToEnd()
assert.Equal(t, true, pager.isScrolledToEnd())
pager.onKey(twin.KeyUp)
pager.mode.onKey(twin.KeyUp)
pager.redraw("XXX")
assert.Equal(t, false, pager.isScrolledToEnd())
}

View File

@ -12,7 +12,7 @@ type PagerModeGotoLine struct {
pager *Pager
}
func (m PagerModeGotoLine) drawFooter(statusText string, spinner string) {
func (m PagerModeGotoLine) drawFooter(_ string, _ string) {
p := m.pager
_, height := p.screen.Size()

View File

@ -6,7 +6,7 @@ type PagerModeNotFound struct {
pager *Pager
}
func (m PagerModeNotFound) drawFooter(statusText string, spinner string) {
func (m PagerModeNotFound) drawFooter(_ string, _ string) {
m.pager.setFooter("Not found: " + m.pager.searchString)
}

View File

@ -13,7 +13,7 @@ type PagerModeSearch struct {
pager *Pager
}
func (m PagerModeSearch) drawFooter(statusText string, spinner string) {
func (m PagerModeSearch) drawFooter(_ string, _ string) {
width, height := m.pager.screen.Size()
pos := 0

View File

@ -7,6 +7,21 @@ import (
"gotest.tools/v3/assert"
)
func modeName(pager *Pager) string {
switch pager.mode.(type) {
case PagerModeViewing:
return "Viewing"
case PagerModeNotFound:
return "NotFound"
case PagerModeSearch:
return "Search"
case PagerModeGotoLine:
return "GotoLine"
default:
panic("Unknown pager mode")
}
}
// Create a pager with three screen lines reading from a six lines stream
func createThreeLinesPager(t *testing.T) *Pager {
reader := NewReaderFromText("", "a\nb\nc\nd\ne\nf\n")
@ -16,7 +31,7 @@ func createThreeLinesPager(t *testing.T) *Pager {
pager.screen = screen
assert.Equal(t, _Viewing, pager.mode, "Initial pager state")
assert.Equal(t, "Viewing", modeName(pager), "Initial pager state")
return pager
}
@ -33,7 +48,7 @@ func TestScrollToNextSearchHit_StartAtBottom(t *testing.T) {
// Scroll to the next search hit
pager.scrollToNextSearchHit()
assert.Equal(t, _NotFound, pager.mode)
assert.Equal(t, "NotFound", modeName(pager))
}
func TestScrollToNextSearchHit_StartAtTop(t *testing.T) {
@ -47,7 +62,7 @@ func TestScrollToNextSearchHit_StartAtTop(t *testing.T) {
// Scroll to the next search hit
pager.scrollToNextSearchHit()
assert.Equal(t, _NotFound, pager.mode)
assert.Equal(t, "NotFound", modeName(pager))
}
func TestScrollToNextSearchHit_WrapAfterNotFound(t *testing.T) {
@ -61,12 +76,12 @@ func TestScrollToNextSearchHit_WrapAfterNotFound(t *testing.T) {
// Scroll to the next search hit, this should take us into _NotFound
pager.scrollToNextSearchHit()
assert.Equal(t, _NotFound, pager.mode)
assert.Equal(t, "NotFound", modeName(pager))
// Scroll to the next search hit, this should wrap the search and take us to
// the top
pager.scrollToNextSearchHit()
assert.Equal(t, _Viewing, pager.mode)
assert.Equal(t, "Viewing", modeName(pager))
assert.Assert(t, pager.lineNumber().IsZero())
}
@ -81,12 +96,12 @@ func TestScrollToNextSearchHit_WrapAfterFound(t *testing.T) {
// Scroll to the next search hit, this should take us into _NotFound
pager.scrollToNextSearchHit()
assert.Equal(t, _NotFound, pager.mode)
assert.Equal(t, "NotFound", modeName(pager))
// Scroll to the next search hit, this should wrap the search and take us
// back to the bottom again
pager.scrollToNextSearchHit()
assert.Equal(t, _Viewing, pager.mode)
assert.Equal(t, "Viewing", modeName(pager))
assert.Equal(t, 5, pager.lineNumber().AsOneBased())
}
@ -97,14 +112,15 @@ func Test152(t *testing.T) {
screen := twin.NewFakeScreen(20, 5)
pager := NewPager(reader)
pager.screen = screen
assert.Equal(t, _Viewing, pager.mode, "Initial pager state")
assert.Equal(t, "Viewing", modeName(pager), "Initial pager state")
// Search for the first not-visible hit
pager.searchString = "abcde"
pager.mode = PagerModeSearch{pager: pager}
searchMode := PagerModeSearch{pager: pager}
pager.mode = searchMode
// Scroll to the next search hit
pager.updateSearchPattern()
searchMode.updateSearchPattern()
_, ok := pager.mode.(PagerModeSearch)
assert.Assert(t, ok, pager.mode)