1package lineedit23import (4 "testing"56 tea "charm.land/bubbletea/v2"7)89func TestEditing(t *testing.T) {10 var l Line11 l.Set("=SUM(A1")12 l.Key(tea.KeyPressMsg{Code: tea.KeyLeft})13 l.Key(tea.KeyPressMsg{Code: tea.KeyBackspace})14 l.Insert("B\tC")15 if got := l.Text(); got != "=SUM(B C1" {16 t.Fatalf("text %q", got)17 }18 if l.Head() != "=SUM(B C" || l.Tail() != "1" {19 t.Errorf("head %q tail %q", l.Head(), l.Tail())20 }21 if !l.IsFormula() {22 t.Error("not a formula")23 }24 l.Key(tea.KeyPressMsg{Code: 'a', Mod: tea.ModCtrl})25 if l.Pos != 0 || l.CanPoint() {26 t.Errorf("home: pos %d", l.Pos)27 }28 l.SetCaret(5)29 if !l.CanPoint() {30 t.Errorf("after ( a reference may follow: pos %d", l.Pos)31 }32 l.Clear()33 if l.Text() != "" || l.Pos != 0 {34 t.Errorf("clear left %q", l.Text())35 }36}3738func TestTyped(t *testing.T) {39 if Typed(tea.KeyPressMsg{Code: 'x', Text: "x", Mod: tea.ModCtrl}) != "" {40 t.Error("ctrl+x typed text")41 }42 if Typed(tea.KeyPressMsg{Code: 'x', Text: "x"}) != "x" {43 t.Error("x typed nothing")44 }45}