diff --git a/lib/go/camli/blobref/blobref.go b/lib/go/camli/blobref/blobref.go index 674518f40..f5f8980fa 100644 --- a/lib/go/camli/blobref/blobref.go +++ b/lib/go/camli/blobref/blobref.go @@ -66,8 +66,8 @@ func (sb *SizedBlobRef) Equal(o SizedBlobRef) bool { return sb.Size == o.Size && sb.BlobRef.String() == o.BlobRef.String() } -func (sb *SizedBlobRef) String() string { - return fmt.Sprintf("[%s %d bytes]", sb.BlobRef.String(), sb.Size) +func (sb SizedBlobRef) String() string { + return fmt.Sprintf("[%s; %d bytes]", sb.BlobRef.String(), sb.Size) } type ReadSeekCloser interface { diff --git a/lib/go/camli/blobref/blobref_test.go b/lib/go/camli/blobref/blobref_test.go index 529e71e57..76c922596 100644 --- a/lib/go/camli/blobref/blobref_test.go +++ b/lib/go/camli/blobref/blobref_test.go @@ -18,9 +18,11 @@ package blobref import ( "bytes" + "fmt" "gob" "json" "testing" + . "camli/test/asserts" ) @@ -120,3 +122,32 @@ func TestGobbing(t *testing.T) { t.Errorf("got = %q, want %q", &got, br) } } + +func TestBlobRefString(t *testing.T) { + bp := MustParse("abc-123") + e := "abc-123" + if g := bp.String(); g != e { + t.Errorf("(&BlobRef).String() = %q, want %q", g, e) + } + if g := fmt.Sprintf("%s", bp); g != e { + t.Errorf("fmt %%s &BlobRef = %q, want %q", g, e) + } +} + +func TestSizedBlobRefString(t *testing.T) { + sbv := SizedBlobRef{BlobRef: MustParse("abc-123"), Size: 456} + sbp := &sbv + e := "[abc-123; 456 bytes]" + if g := sbv.String(); g != e { + t.Errorf("SizedBlobRef.String() = %q, want %q", g, e) + } + if g := sbp.String(); g != e { + t.Errorf("(&SizedBlobRef).String() = %q, want %q", g, e) + } + if g := fmt.Sprintf("%s", sbv); g != e { + t.Errorf("fmt %%s SizedBlobRef = %q, want %q", g, e) + } + if g := fmt.Sprintf("%s", sbp); g != e { + t.Errorf("fmt %%s &SizedBlobRef = %q, want %q", g, e) + } +}