From cbb367b1df721592423419a7a1138855eb3b1571 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Thu, 4 Apr 2024 13:39:15 -0700 Subject: [PATCH] x/build/blob: check name + valid invariant --- x/build/blob/ref.go | 11 ----------- x/build/blob/ref_test.go | 6 ++++++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/x/build/blob/ref.go b/x/build/blob/ref.go index 63129d59..74fd1da7 100644 --- a/x/build/blob/ref.go +++ b/x/build/blob/ref.go @@ -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 { diff --git a/x/build/blob/ref_test.go b/x/build/blob/ref_test.go index 33b741b8..dcf938e5 100644 --- a/x/build/blob/ref_test.go +++ b/x/build/blob/ref_test.go @@ -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()) + } }) } }