package app import ( "os" "path/filepath" "testing" "glint/internal/editor" tea "github.com/charmbracelet/bubbletea" ) func TestGotoLineJumps(t *testing.T) { a := statusApp() a.editor.SetContent([]byte("one\ntwo\nthree\nfour")) a.Update(tea.KeyMsg{Type: tea.KeyCtrlL}) if a.mode != ModeGotoLine { t.Fatalf("Ctrl+L did not open go-to-line: mode = %v", a.mode) } a.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("3")}) a.Update(tea.KeyMsg{Type: tea.KeyEnter}) if a.mode != ModeEditor { t.Errorf("after Enter mode = %v, want ModeEditor", a.mode) } if a.editor.Cursor.Row != 2 { t.Errorf("cursor row = %d, want 2 (line 3)", a.editor.Cursor.Row) } } func TestGotoLineEscCloses(t *testing.T) { a := statusApp() a.Update(tea.KeyMsg{Type: tea.KeyCtrlL}) a.Update(tea.KeyMsg{Type: tea.KeyEsc}) if a.mode != ModeEditor { t.Errorf("Esc did not close go-to-line: mode = %v", a.mode) } } func TestPerFileCursorMemory(t *testing.T) { dir := t.TempDir() pa := filepath.Join(dir, "a.md") pb := filepath.Join(dir, "b.md") os.WriteFile(pa, []byte("a1\na2\na3"), 0o644) os.WriteFile(pb, []byte("b1\nb2"), 0o644) a := statusApp() a.Load(pa) a.editor.SetCursor(editor.Position{Row: 2, Col: 1}) // remember this in a.md a.Load(pb) // switch away a.Load(pa) // return if got := (a.editor.Cursor); got.Row != 2 { t.Errorf("returning to a.md cursor = %+v, want row 2 restored", got) } } func TestPasteURLOverSelectionMakesLink(t *testing.T) { a := statusApp() a.editor.SetContent([]byte("click here")) a.editor.SetCursor(editor.Position{Row: 0, Col: 0}) // select "click" for i := 0; i < 5; i++ { a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyShiftRight}) } a.pasteText("https://example.com") if got := a.editor.Lines[0]; got != "[click](https://example.com) here" { t.Errorf("line = %q, want [click](https://example.com) here", got) } } func TestPasteNonURLOverSelectionReplaces(t *testing.T) { a := statusApp() a.editor.SetContent([]byte("click here")) a.editor.SetCursor(editor.Position{Row: 0, Col: 0}) for i := 0; i < 5; i++ { a.editor.HandleKey(tea.KeyMsg{Type: tea.KeyShiftRight}) } a.pasteText("tap") if got := a.editor.Lines[0]; got != "tap here" { t.Errorf("line = %q, want tap here", got) } } func TestPasteURLNoSelectionInsertsLiterally(t *testing.T) { a := statusApp() a.editor.SetContent([]byte("")) a.pasteText("https://example.com") if got := a.editor.Lines[0]; got != "https://example.com" { t.Errorf("line = %q, want literal URL", got) } }