Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Jan 7, 2025
1 parent df9d85e commit 6c51891
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions internal/viewport/viewport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4028,7 +4028,7 @@ func TestViewport_SelectionOn_WrapOn_StickyTop(t *testing.T) {
}

func TestViewport_SelectionOn_WrapOn_StickyBottom(t *testing.T) {
w, h := 10, 4
w, h := 10, 6
vp := newViewport(w, h)
vp.SetHeader([]string{"header"})
vp.SetWrapText(true)
Expand All @@ -4043,7 +4043,6 @@ func TestViewport_SelectionOn_WrapOn_StickyBottom(t *testing.T) {
"header",
"\x1b[38;2;0;0;255mthe first \x1b[m",
"\x1b[38;2;0;0;255mline\x1b[m",
"100% (1/1)",
})
util.CmpStr(t, expectedView, vp.View())

Expand All @@ -4054,33 +4053,56 @@ func TestViewport_SelectionOn_WrapOn_StickyBottom(t *testing.T) {
})
expectedView = pad(vp.width, vp.height, []string{
"header",
"the second",
" line",
"\x1b[38;2;0;0;255mthe first \x1b[m",
"\x1b[38;2;0;0;255mline\x1b[m",
"100% (2/2)",
})
util.CmpStr(t, expectedView, vp.View())

// add longer content at bottom
vp.SetContent([]RenderableString{
{Content: "the second line"},
{Content: "the first line"},
{Content: "a very long line that wraps a lot"},
})
expectedView = pad(vp.width, vp.height, []string{
"header",
"\x1b[38;2;0;0;255ma very lon\x1b[m",
"\x1b[38;2;0;0;255mg line tha\x1b[m",
"\x1b[38;2;0;0;255mt wraps a \x1b[m",
"\x1b[38;2;0;0;255mlot\x1b[m",
"100% (3/3)",
})
util.CmpStr(t, expectedView, vp.View())

// de-activate by moving selection up
vp, _ = vp.Update(upKeyMsg)
expectedView = pad(vp.width, vp.height, []string{
"header",
"\x1b[38;2;0;0;255mthe second\x1b[m",
"\x1b[38;2;0;0;255m line\x1b[m",
"50% (1/2)",
"\x1b[38;2;0;0;255mthe first \x1b[m",
"\x1b[38;2;0;0;255mline\x1b[m",
"a very lon",
"g line tha",
"66% (2/3)",
})
util.CmpStr(t, expectedView, vp.View())

// add content
vp.SetContent([]RenderableString{
{Content: "the second line"},
{Content: "the first line"},
{Content: "a very long line that wraps a lot"},
{Content: "the third line"},
})
expectedView = pad(vp.width, vp.height, []string{
"header",
"\x1b[38;2;0;0;255mthe second\x1b[m",
"\x1b[38;2;0;0;255m line\x1b[m",
"33% (1/3)",
"\x1b[38;2;0;0;255mthe first \x1b[m",
"\x1b[38;2;0;0;255mline\x1b[m",
"a very lon",
"g line tha",
"50% (2/4)",
})
util.CmpStr(t, expectedView, vp.View())
}
Expand Down

0 comments on commit 6c51891

Please sign in to comment.