package app import ( "strings" "testing" "glint/internal/editor" tea "github.com/charmbracelet/bubbletea" ) // altSemicolon is the Alt+; key event that opens the spell popup. var altSemicolon = tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(";"), Alt: true} func editorPos(row, col int) editor.Position { return editor.Position{Row: row, Col: col} } func TestAltSemicolonOpensPopupOnMisspelling(t *testing.T) { a := newApp() a.setSize(100, 24) a.editor.SetContent([]byte("a recieve here")) a.editor.SetCursor(editorPos(0, 4)) // inside "recieve" a.handleKey(altSemicolon) if a.mode != ModeSpell { t.Fatalf("mode = %d, want ModeSpell", a.mode) } if a.spell.word != "recieve" { t.Errorf("popup word = %q, want recieve", a.spell.word) } if len(a.spell.options) < 3 { t.Errorf("want suggestions + add + ignore, got %d options", len(a.spell.options)) } } func TestAltSemicolonNoMisspellingShowsStatus(t *testing.T) { a := newApp() a.setSize(100, 24) a.editor.SetContent([]byte("all correct words")) a.editor.SetCursor(editorPos(0, 1)) a.handleKey(altSemicolon) if a.mode == ModeSpell { t.Error("popup opened with no misspelling under the cursor") } } func TestSpellPopupNumberKeyReplaces(t *testing.T) { a := newApp() a.setSize(100, 24) a.editor.SetContent([]byte("a recieve here")) a.editor.SetCursor(editorPos(0, 4)) a.handleKey(altSemicolon) // The first suggestion for "recieve" is "receive"; press "1" to apply it. if a.spell.options[0].value != "receive" { t.Fatalf("first suggestion = %q, want receive", a.spell.options[0].value) } a.handleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("1")}) if a.mode != ModeEditor { t.Errorf("popup did not close after applying; mode = %d", a.mode) } if got := a.editor.Lines[0]; got != "a receive here" { t.Errorf("line after replace = %q, want \"a receive here\"", got) } } func TestSpellPopupAddKey(t *testing.T) { a := newApp() a.setSize(100, 24) a.editor.SetContent([]byte("my zzplonk word")) a.editor.SetCursor(editorPos(0, 4)) a.handleKey(altSemicolon) if a.mode != ModeSpell { t.Fatalf("popup did not open on zzplonk") } a.handleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("i")}) // ignore for session if a.mode != ModeEditor { t.Errorf("popup did not close after ignore") } if strings.Contains(a.status, "failed") { t.Errorf("ignore reported failure: %q", a.status) } }