package render import "testing" func TestRegistrySelect(t *testing.T) { reg := NewRegistry(New()) md := []byte("# hi\n") cases := []struct { name string file string id string force bool wantID string }{ {"empty falls back to default", "main.go", "", false, "source"}, {"unknown id falls back to default", "main.go", "nope", false, "source"}, {"eligible id selected", "README.md", "markdown", false, "markdown"}, {"ineligible id without force -> default", "main.go", "markdown", false, "source"}, {"ineligible id with force -> selected", "main.go", "markdown", true, "markdown"}, {"default id always allowed", "README.md", "source", false, "source"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { got := reg.Select(c.file, md, c.id, c.force) if got.ID != c.wantID { t.Fatalf("Select(%q, %q, force=%v) = %q, want %q", c.file, c.id, c.force, got.ID, c.wantID) } }) } } func TestRegistryEligible(t *testing.T) { reg := NewRegistry(New()) // Markdown file: both source and markdown offered. got := ids(reg.Eligible("README.md", nil)) if len(got) != 2 || got[0] != "source" || got[1] != "markdown" { t.Fatalf("eligible(README.md) = %v, want [source markdown]", got) } // Non-markdown file: only the default. got = ids(reg.Eligible("main.go", nil)) if len(got) != 1 || got[0] != "source" { t.Fatalf("eligible(main.go) = %v, want [source]", got) } } func ids(mods []Module) []string { out := make([]string, len(mods)) for i, m := range mods { out[i] = m.ID } return out }