Gim/internal/editor/integration_motion_basic_test.go
Hayden Hargreaves ccb061989a refactor: huge refactor, this looks amazing.
Lots of comments from the AI. Some tests are not passing though
2026-03-04 21:45:47 -07:00

278 lines
7.2 KiB
Go

package editor
import (
"testing"
"git.gophernest.net/azpect/TextEditor/internal/core"
)
func TestMoveDown(t *testing.T) {
t.Run("test 'j'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 1 {
t.Errorf("cursor.y = %d, want 1", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test 'jjjj'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "j", "j", "j", "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 4 {
t.Errorf("cursor.y = %d, want 4", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test 'jjjjjjjjj's with overflow", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "j", "j", "j", "j", "j", "j", "j", "j", "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 5 {
t.Errorf("cursor.y = %d, want 5", m.ActiveWindow().Cursor.Line)
}
})
}
func TestMoveDownWithCount(t *testing.T) {
t.Run("test '3j'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "3", "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 3 {
t.Errorf("cursor.y = %d, want 3", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test '10j' with overflow", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "1", "0", "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 5 {
t.Errorf("cursor.y = %d, want 5", m.ActiveWindow().Cursor.Line)
}
})
}
func TestMoveDownWithOverflow(t *testing.T) {
lines := []string{"long line", "small"}
t.Run("test 'j' with overflow", func(t *testing.T) {
tm := newTestModelWithLinesAndCursorPos(t, lines, core.Position{Col: 8, Line: 0})
sendKeys(tm, "j")
m := getFinalModel(t, tm)
want := len(lines[1])
if m.ActiveWindow().Cursor.Col != want {
t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want)
}
})
t.Run("test 'j' without overflow", func(t *testing.T) {
tm := newTestModelWithLinesAndCursorPos(t, lines, core.Position{Col: 3, Line: 0})
sendKeys(tm, "j")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 3 {
t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col)
}
})
}
func TestMoveUp(t *testing.T) {
t.Run("test 'k'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 0, Line: 2})
sendKeys(tm, "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 1 {
t.Errorf("cursor.y = %d, want 1", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test 'kkkk'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 0, Line: 4})
sendKeys(tm, "k", "k", "k", "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 0 {
t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test 'k' at top (no movement)", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "k", "k", "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 0 {
t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line)
}
})
}
func TestMoveUpWithCount(t *testing.T) {
t.Run("test '3k'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 0, Line: 5})
sendKeys(tm, "3", "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 2 {
t.Errorf("cursor.y = %d, want 2", m.ActiveWindow().Cursor.Line)
}
})
t.Run("test '10k' with overflow", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 0, Line: 3})
sendKeys(tm, "1", "0", "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Line != 0 {
t.Errorf("cursor.y = %d, want 0", m.ActiveWindow().Cursor.Line)
}
})
}
func TestMoveUpWithOverflow(t *testing.T) {
lines := []string{"small", "long line"}
t.Run("test 'k' with overflow", func(t *testing.T) {
tm := newTestModelWithLinesAndCursorPos(t, lines, core.Position{Col: 10, Line: 1})
sendKeys(tm, "k")
m := getFinalModel(t, tm)
want := len(lines[0])
if m.ActiveWindow().Cursor.Col != want {
t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want)
}
})
t.Run("test 'k' without overflow", func(t *testing.T) {
tm := newTestModelWithLinesAndCursorPos(t, lines, core.Position{Col: 3, Line: 1})
sendKeys(tm, "k")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 3 {
t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col)
}
})
}
func TestMoveRight(t *testing.T) {
t.Run("test 'l'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "l")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 1 {
t.Errorf("cursor.x = %d, want 1", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test 'llll'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "l", "l", "l", "l")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 4 {
t.Errorf("cursor.x = %d, want 4", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test 'l' at end of line (no movement past end)", func(t *testing.T) {
lines := []string{"abc"}
tm := newTestModelWithLines(t, lines)
sendKeys(tm, "l", "l", "l", "l", "l", "l")
m := getFinalModel(t, tm)
want := len(lines[0])
if m.ActiveWindow().Cursor.Col != want {
t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want)
}
})
}
func TestMoveRightWithCount(t *testing.T) {
t.Run("test '3l'", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "3", "l")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 3 {
t.Errorf("cursor.x = %d, want 3", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test '10l' with overflow", func(t *testing.T) {
lines := []string{"short"}
tm := newTestModelWithLines(t, lines)
sendKeys(tm, "1", "0", "l")
m := getFinalModel(t, tm)
want := len(lines[0])
if m.ActiveWindow().Cursor.Col != want {
t.Errorf("cursor.x = %d, want %d", m.ActiveWindow().Cursor.Col, want)
}
})
}
func TestMoveLeft(t *testing.T) {
t.Run("test 'h'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 3, Line: 0})
sendKeys(tm, "h")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 2 {
t.Errorf("cursor.x = %d, want 2", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test 'hhhh'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 4, Line: 0})
sendKeys(tm, "h", "h", "h", "h")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 0 {
t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test 'h' at start (no movement)", func(t *testing.T) {
tm := newTestModel(t)
sendKeys(tm, "h", "h", "h")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 0 {
t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col)
}
})
}
func TestMoveLeftWithCount(t *testing.T) {
t.Run("test '3h'", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 5, Line: 0})
sendKeys(tm, "3", "h")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 2 {
t.Errorf("cursor.x = %d, want 2", m.ActiveWindow().Cursor.Col)
}
})
t.Run("test '10h' with overflow", func(t *testing.T) {
tm := newTestModelWithCursorPos(t, core.Position{Col: 3, Line: 0})
sendKeys(tm, "1", "0", "h")
m := getFinalModel(t, tm)
if m.ActiveWindow().Cursor.Col != 0 {
t.Errorf("cursor.x = %d, want 0", m.ActiveWindow().Cursor.Col)
}
})
}