package editor import ( "testing" "git.gophernest.net/azpect/TextEditor/internal/action" ) func TestDeleteChar(t *testing.T) { t.Run("test 'x' deletes character under cursor", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLines(t, lines) sendKeys(tm, "x") m := getFinalModel(t, tm) if m.lines[0] != "ello" { t.Errorf("lines[0] = %q, want 'ello'", m.lines[0]) } }) t.Run("test 'x' in middle of line", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLinesAndCursorPos(t, lines, action.Position{Col: 2, Line: 0}) sendKeys(tm, "x") m := getFinalModel(t, tm) if m.lines[0] != "helo" { t.Errorf("lines[0] = %q, want 'helo'", m.lines[0]) } }) t.Run("test 'x' at end of line", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLinesAndCursorPos(t, lines, action.Position{Col: 4, Line: 0}) sendKeys(tm, "x") m := getFinalModel(t, tm) if m.lines[0] != "hell" { t.Errorf("lines[0] = %q, want 'hell'", m.lines[0]) } }) t.Run("test 'xx' deletes two characters", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLines(t, lines) sendKeys(tm, "x", "x") m := getFinalModel(t, tm) if m.lines[0] != "llo" { t.Errorf("lines[0] = %q, want 'llo'", m.lines[0]) } }) } func TestDeleteCharWithCount(t *testing.T) { t.Run("test '3x' deletes three characters", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLines(t, lines) sendKeys(tm, "3", "x") m := getFinalModel(t, tm) if m.lines[0] != "lo" { t.Errorf("lines[0] = %q, want 'lo'", m.lines[0]) } }) t.Run("test '10x' with overflow", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLines(t, lines) sendKeys(tm, "1", "0", "x") m := getFinalModel(t, tm) if m.lines[0] != "" { t.Errorf("lines[0] = %q, want ''", m.lines[0]) } }) t.Run("test '2x' from middle", func(t *testing.T) { lines := []string{"hello"} tm := newTestModelWithLinesAndCursorPos(t, lines, action.Position{Col: 1, Line: 0}) sendKeys(tm, "2", "x") m := getFinalModel(t, tm) if m.lines[0] != "hlo" { t.Errorf("lines[0] = %q, want 'hlo'", m.lines[0]) } }) }