x/model: add CompleteNoBuild

This commit is contained in:
Blake Mizerany 2024-04-05 22:41:22 -07:00
parent f2c17682b0
commit 6e464ebef8
2 changed files with 13 additions and 4 deletions

View File

@ -286,6 +286,12 @@ func (r Name) Complete() bool {
return !slices.Contains(r.Parts(), "") return !slices.Contains(r.Parts(), "")
} }
// CompleteNoBuild reports whether the Name is fully qualified without the
// build part.
func (r Name) CompleteNoBuild() bool {
return !slices.Contains(r.Parts()[:4], "")
}
// EqualFold reports whether r and o are equivalent model names, ignoring // EqualFold reports whether r and o are equivalent model names, ignoring
// case. // case.
func (r Name) EqualFold(o Name) bool { func (r Name) EqualFold(o Name) bool {

View File

@ -138,11 +138,11 @@ func TestParseName(t *testing.T) {
} }
} }
func TestComplete(t *testing.T) { func TestCompleteWithAndWithoutBuild(t *testing.T) {
cases := []struct { cases := []struct {
in string in string
complete bool complete bool
completeWithoutBuild bool completeNoBuild bool
}{ }{
{"", false, false}, {"", false, false},
{"incomplete/mistral:7b+x", false, false}, {"incomplete/mistral:7b+x", false, false},
@ -159,6 +159,9 @@ func TestComplete(t *testing.T) {
if g := p.Complete(); g != tt.complete { if g := p.Complete(); g != tt.complete {
t.Errorf("Complete(%q) = %v; want %v", tt.in, g, tt.complete) t.Errorf("Complete(%q) = %v; want %v", tt.in, g, tt.complete)
} }
if g := p.CompleteNoBuild(); g != tt.completeNoBuild {
t.Errorf("CompleteNoBuild(%q) = %v; want %v", tt.in, g, tt.completeNoBuild)
}
}) })
} }