Parcourir la source

x/build/blob: check name + valid invariant

Blake Mizerany il y a 1 an
Parent
commit
cbb367b1df
2 fichiers modifiés avec 6 ajouts et 11 suppressions
  1. 0 11
      x/build/blob/ref.go
  2. 6 0
      x/build/blob/ref_test.go

+ 0 - 11
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 {

+ 6 - 0
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())
+				}
 			})
 		}
 	}