1
1
mirror of https://github.com/walles/moar.git synced 2024-11-30 02:34:13 +03:00

Add more cropping tests

This commit is contained in:
Johan Walles 2021-05-30 10:07:10 +02:00
parent f84ae1df18
commit 891b2ccd4f
2 changed files with 20 additions and 17 deletions

View File

@ -103,7 +103,7 @@ func (sl *ScreenLines) createScreenLine(lineNumberToShow *int, numberPrefixLengt
}
// Add scroll right indicator
if len(contents)+numberPrefixLength > sl.width {
if len(contents)+numberPrefixLength-sl.leftColumnZeroBased > sl.width {
newLine[sl.width-1] = twin.Cell{
Rune: '>',
Style: twin.StyleDefault.WithAttr(twin.AttrReverse),

View File

@ -6,30 +6,33 @@ import (
"gotest.tools/assert"
)
func TestCreateScreenLine(t *testing.T) {
screenLines := ScreenLines{width: 10}
lineContents := NewLine("abc").HighlightedTokens(nil)
func testCropping(t *testing.T, contents string, firstIndex int, lastIndex int, expected string) {
screenLines := ScreenLines{width: 1 + lastIndex - firstIndex, leftColumnZeroBased: firstIndex}
lineContents := NewLine(contents).HighlightedTokens(nil)
screenLine := screenLines.createScreenLine(nil, 0, lineContents)
assert.Equal(t, rowToString(screenLine), "abc")
assert.Equal(t, rowToString(screenLine), expected)
}
func TestCreateScreenLine(t *testing.T) {
testCropping(t, "abc", 0, 10, "abc")
}
func TestCreateScreenLineCanScrollLeft(t *testing.T) {
screenLines := ScreenLines{width: 10, leftColumnZeroBased: 1}
lineContents := NewLine("abc").HighlightedTokens(nil)
screenLine := screenLines.createScreenLine(nil, 0, lineContents)
assert.Equal(t, rowToString(screenLine), "<c")
testCropping(t, "abc", 1, 10, "<c")
}
func TestCreateScreenLineCanScrollRight(t *testing.T) {
screenLines := ScreenLines{width: 2}
lineContents := NewLine("abc").HighlightedTokens(nil)
screenLine := screenLines.createScreenLine(nil, 0, lineContents)
assert.Equal(t, rowToString(screenLine), "a>")
testCropping(t, "abc", 0, 1, "a>")
}
func TestCreateScreenLineCanAlmostScrollRight(t *testing.T) {
screenLines := ScreenLines{width: 3}
lineContents := NewLine("abc").HighlightedTokens(nil)
screenLine := screenLines.createScreenLine(nil, 0, lineContents)
assert.Equal(t, rowToString(screenLine), "abc")
testCropping(t, "abc", 0, 2, "abc")
}
func TestCreateScreenLineCanScrollBoth(t *testing.T) {
testCropping(t, "abcde", 1, 3, "<c>")
}
func TestCreateScreenLineCanAlmostScrollBoth(t *testing.T) {
testCropping(t, "abcd", 1, 3, "<cd")
}