From 9c0bc5c7da2d60d7fe17bb7206cd523df8a9c958 Mon Sep 17 00:00:00 2001 From: Roman Suvorov Date: Wed, 18 Dec 2024 22:35:57 +0100 Subject: [PATCH] add test for preventing right overscroll --- viewport/viewport_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/viewport/viewport_test.go b/viewport/viewport_test.go index fd1ee1d..b618ac9 100644 --- a/viewport/viewport_test.go +++ b/viewport/viewport_test.go @@ -14,7 +14,7 @@ func TestNew(t *testing.T) { m := New(10, 10) if !m.initialized { - t.Errorf("on create by New Model should be initialized") + t.Errorf("on create by New, Model should be initialized") } if m.horizontalStep != defaultHorizontalStep { @@ -357,3 +357,25 @@ func TestVisibleLines(t *testing.T) { } }) } + +func TestRightOverscroll(t *testing.T) { + t.Parallel() + + t.Run("prevent right overscroll", func(t *testing.T) { + t.Parallel() + content := "Content is short" + m := New(len(content)+1, 5) + m.SetContent(content) + + for i := 0; i < 10; i++ { + m.MoveRight() + } + + visibleLines := m.visibleLines() + visibleLine := visibleLines[0] + + if visibleLine != content { + t.Error("visible line should stay the same as content") + } + }) +}