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:
parent
f84ae1df18
commit
891b2ccd4f
@ -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),
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user