mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
fix: normalize yoffset
This commit is contained in:
+14
-13
@@ -99,7 +99,7 @@ func TestMoveLeft(t *testing.T) {
|
||||
t.Errorf("default indent should be %d, got %d", zeroPosition, m.xOffset)
|
||||
}
|
||||
|
||||
m.MoveLeft(m.horizontalStep)
|
||||
m.ScrollLeft(m.horizontalStep)
|
||||
if m.xOffset != zeroPosition {
|
||||
t.Errorf("indent should be %d, got %d", zeroPosition, m.xOffset)
|
||||
}
|
||||
@@ -108,12 +108,13 @@ func TestMoveLeft(t *testing.T) {
|
||||
t.Run("move", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := New(WithHeight(10), WithWidth(10))
|
||||
m.longestLineWidth = 100
|
||||
if m.xOffset != zeroPosition {
|
||||
t.Errorf("default indent should be %d, got %d", zeroPosition, m.xOffset)
|
||||
}
|
||||
|
||||
m.xOffset = defaultHorizontalStep * 2
|
||||
m.MoveLeft(m.horizontalStep)
|
||||
m.ScrollLeft(m.horizontalStep)
|
||||
newIndent := defaultHorizontalStep
|
||||
if m.xOffset != newIndent {
|
||||
t.Errorf("indent should be %d, got %d", newIndent, m.xOffset)
|
||||
@@ -135,7 +136,7 @@ func TestMoveRight(t *testing.T) {
|
||||
t.Errorf("default indent should be %d, got %d", zeroPosition, m.xOffset)
|
||||
}
|
||||
|
||||
m.MoveRight(m.horizontalStep)
|
||||
m.ScrollRight(m.horizontalStep)
|
||||
newIndent := defaultHorizontalStep
|
||||
if m.xOffset != newIndent {
|
||||
t.Errorf("indent should be %d, got %d", newIndent, m.xOffset)
|
||||
@@ -154,7 +155,7 @@ func TestResetIndent(t *testing.T) {
|
||||
m := New(WithHeight(10), WithWidth(10))
|
||||
m.xOffset = 500
|
||||
|
||||
m.ResetIndent()
|
||||
m.SetXOffset(0)
|
||||
if m.xOffset != zeroPosition {
|
||||
t.Errorf("indent should be %d, got %d", zeroPosition, m.xOffset)
|
||||
}
|
||||
@@ -233,7 +234,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
|
||||
m := New(WithHeight(numberOfLines), WithWidth(10))
|
||||
m.SetContent(strings.Join(defaultList, "\n"))
|
||||
m.YOffset = 5
|
||||
m.SetYOffset(5)
|
||||
|
||||
list := m.visibleLines()
|
||||
if len(list) != numberOfLines {
|
||||
@@ -246,7 +247,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
|
||||
lastItemIdx := numberOfLines - 1
|
||||
// we trim line if it doesn't fit to width of the viewport
|
||||
shouldGet := defaultList[m.YOffset+lastItemIdx][:m.Width()]
|
||||
shouldGet := defaultList[m.YOffset()+lastItemIdx][:m.Width()]
|
||||
if list[lastItemIdx] != shouldGet {
|
||||
t.Errorf(`%dth list item should be '%s', got '%s'`, lastItemIdx, shouldGet, list[lastItemIdx])
|
||||
}
|
||||
@@ -258,7 +259,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
|
||||
m := New(WithHeight(numberOfLines), WithWidth(10))
|
||||
m.lines = defaultList
|
||||
m.YOffset = 7
|
||||
m.SetYOffset(7)
|
||||
|
||||
// default list
|
||||
list := m.visibleLines()
|
||||
@@ -278,7 +279,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
}
|
||||
|
||||
// move right
|
||||
m.MoveRight(m.horizontalStep)
|
||||
m.ScrollRight(m.horizontalStep)
|
||||
list = m.visibleLines()
|
||||
|
||||
newPrefix := perceptPrefix[m.xOffset:]
|
||||
@@ -291,7 +292,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
}
|
||||
|
||||
// move left
|
||||
m.MoveLeft(m.horizontalStep)
|
||||
m.ScrollLeft(m.horizontalStep)
|
||||
list = m.visibleLines()
|
||||
if !strings.HasPrefix(list[0], perceptPrefix) {
|
||||
t.Errorf("first list item has to have prefix %s", perceptPrefix)
|
||||
@@ -333,7 +334,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
}
|
||||
|
||||
// move right
|
||||
m.MoveRight(horizontalStep)
|
||||
m.ScrollRight(horizontalStep)
|
||||
list = m.visibleLines()
|
||||
|
||||
for i := range list {
|
||||
@@ -344,7 +345,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
}
|
||||
|
||||
// move left
|
||||
m.MoveLeft(horizontalStep)
|
||||
m.ScrollLeft(horizontalStep)
|
||||
list = m.visibleLines()
|
||||
for i := range list {
|
||||
if list[i] != initList[i] {
|
||||
@@ -354,7 +355,7 @@ func TestVisibleLines(t *testing.T) {
|
||||
|
||||
// move left second times do not change lites if indent == 0
|
||||
m.xOffset = 0
|
||||
m.MoveLeft(horizontalStep)
|
||||
m.ScrollLeft(horizontalStep)
|
||||
list = m.visibleLines()
|
||||
for i := range list {
|
||||
if list[i] != initList[i] {
|
||||
@@ -374,7 +375,7 @@ func TestRightOverscroll(t *testing.T) {
|
||||
m.SetContent(content)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
m.MoveRight(m.horizontalStep)
|
||||
m.ScrollRight(m.horizontalStep)
|
||||
}
|
||||
|
||||
visibleLines := m.visibleLines()
|
||||
|
||||
Reference in New Issue
Block a user