package editor import "testing" // TASK-004: vertical motion must not rescan + rewrap the whole document twice. // buildVisual is O(document); one keystroke should trigger at most one scan. func setupDoc(t *testing.T) *Editor { t.Helper() e := New() e.SetContent([]byte("line one\nline two\nline three\nline four")) e.SetSize(80, 24) return e } func TestMoveDownBuildsVisualOnce(t *testing.T) { e := setupDoc(t) e.buildCount = 0 e.MoveDown() if e.buildCount > 1 { t.Errorf("MoveDown built visual %d times, want <= 1", e.buildCount) } } func TestMoveUpBuildsVisualOnce(t *testing.T) { e := setupDoc(t) e.MoveDocEnd() e.buildCount = 0 e.MoveUp() if e.buildCount > 1 { t.Errorf("MoveUp built visual %d times, want <= 1", e.buildCount) } } func TestMoveToVisualBuildsVisualOnce(t *testing.T) { e := setupDoc(t) e.buildCount = 0 e.MoveToVisual(2, 1) if e.buildCount > 1 { t.Errorf("MoveToVisual built visual %d times, want <= 1", e.buildCount) } }