x/build/blob: check name + valid invariant
This commit is contained in:
parent
18160475c4
commit
cbb367b1df
@ -299,17 +299,6 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
||||
}
|
||||
}
|
||||
|
||||
// Complete is the same as ParseRef(s).Complete().
|
||||
//
|
||||
// Future versions may be faster than calling ParseRef(s).Complete(), so if
|
||||
// need to know if a ref is complete and don't need the ref, use this
|
||||
// function.
|
||||
func Complete(s string) bool {
|
||||
// TODO(bmizerany): fast-path this with a quick scan withput
|
||||
// allocating strings
|
||||
return ParseRef(s).Complete()
|
||||
}
|
||||
|
||||
// Valid returns true if the ref has a valid name. To know if a ref is
|
||||
// "complete", use Complete.
|
||||
func (r Ref) Valid() bool {
|
||||
|
@ -64,6 +64,12 @@ func TestParseRef(t *testing.T) {
|
||||
if ParseRef(got.String()) != got {
|
||||
t.Errorf("String() = %s; want %s", got.String(), s)
|
||||
}
|
||||
|
||||
if got.Valid() && got.Name() == "" {
|
||||
t.Errorf("Valid() = true; Name() = %q; want non-empty name", got.Name())
|
||||
} else if !got.Valid() && got.Name() != "" {
|
||||
t.Errorf("Valid() = false; Name() = %q; want empty name", got.Name())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user