package main
import (
"strings"
"testing"
"git.neuromancer.ovh/bastien-mrq/gitfed/internal/store"
)
func TestMatchesSearch(t *testing.T) {
repo := store.Repo{
Name: "alice/gitfed",
Description: "A self-hosted federated git server",
Topics: []string{"go", "git"},
}
cases := []struct {
name string
needle string
want bool
}{
{"matches name", "gitfed", true},
{"matches name case-insensitively", "GITFED", true},
{"matches description", "federated", true},
{"matches description case-insensitively", "FEDERATED", true},
{"matches topic", "go", true},
{"no match", "wordpress", false},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := matchesSearch(repo, strings.ToLower(c.needle)); got != c.want {
t.Errorf("matchesSearch(%q) = %v, want %v", c.needle, got, c.want)
}
})
}
}
func TestMatchesSearchEmptyDescription(t *testing.T) {
repo := store.Repo{Name: "alice/tool"}
// An empty needle would match everything via strings.Contains — not a
// real scenario (handleSearch only calls matchesSearch when q != ""),
// but confirms an empty Description never itself causes a false match.
if matchesSearch(repo, "something") {
t.Error("expected no match against an empty description")
}
}