package picker import ( "os" "path/filepath" "testing" "glint/internal/theme" ) func TestGoWalkSearchFindsLineMatches(t *testing.T) { root := t.TempDir() os.WriteFile(filepath.Join(root, "a.md"), []byte("alpha\nfind me here\nbeta"), 0o644) os.WriteFile(filepath.Join(root, "b.md"), []byte("nothing relevant"), 0o644) hits := goWalkSearch(root, "find me") if len(hits) != 1 { t.Fatalf("got %d hits, want 1: %+v", len(hits), hits) } h := hits[0] if h.Path != filepath.Join(root, "a.md") { t.Errorf("path = %q, want a.md", h.Path) } if h.Line != 2 { t.Errorf("line = %d, want 2", h.Line) } if h.Text != "find me here" { t.Errorf("text = %q, want %q", h.Text, "find me here") } } func TestGoWalkSearchCaseInsensitive(t *testing.T) { root := t.TempDir() os.WriteFile(filepath.Join(root, "a.md"), []byte("The Quick Brown Fox"), 0o644) hits := goWalkSearch(root, "quick brown") if len(hits) != 1 { t.Fatalf("case-insensitive search should find 1 hit, got %d", len(hits)) } } func TestParseRgOutput(t *testing.T) { out := "/v/a.md:2:find me here\n/v/sub/b.md:10:another match\nmalformed line\n" hits := parseRgOutput(out) if len(hits) != 2 { t.Fatalf("got %d hits, want 2 (malformed skipped): %+v", len(hits), hits) } if hits[0].Path != "/v/a.md" || hits[0].Line != 2 || hits[0].Text != "find me here" { t.Errorf("hit0 = %+v", hits[0]) } if hits[1].Line != 10 { t.Errorf("hit1 line = %d, want 10", hits[1].Line) } } func TestContentSearchEmptyQuery(t *testing.T) { if hits := contentSearch(t.TempDir(), " "); hits != nil { t.Errorf("blank query should yield no hits, got %+v", hits) } } func TestPickerSlashPrefixContentSearch(t *testing.T) { root := t.TempDir() os.WriteFile(filepath.Join(root, "note.md"), []byte("intro\nthe needle line\noutro"), 0o644) m, err := New(root, theme.FlexokiDark(), "", "dark") if err != nil { t.Fatal(err) } m.input.SetValue("/needle") m.recompute() if got := m.Selected(); got != filepath.Join(root, "note.md") { t.Errorf("Selected() = %q, want note.md", got) } if got := m.SelectedLine(); got != 2 { t.Errorf("SelectedLine() = %d, want 2", got) } } func TestPickerFilenameModeHasNoLine(t *testing.T) { root := t.TempDir() os.WriteFile(filepath.Join(root, "note.md"), []byte("body"), 0o644) m, err := New(root, theme.FlexokiDark(), "", "dark") if err != nil { t.Fatal(err) } m.input.SetValue("note") m.recompute() if m.SelectedLine() != 0 { t.Errorf("filename match should have line 0, got %d", m.SelectedLine()) } }