MCPcopy
hub / github.com/perkeep/perkeep / TestParse

Function TestParse

pkg/blob/ref_test.go:59–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestParse(t *testing.T) {
60 for _, tt := range parseTests {
61 fn := tt.fn
62 if fn == "" {
63 fn = "Parse"
64 }
65 r, ok := parseFn[fn](tt.in)
66 if r.Valid() != ok {
67 t.Errorf("Valid != ok for %q", tt.in)
68 }
69 if ok && tt.bad {
70 t.Errorf("%s(%q) didn't fail. It should've.", fn, tt.in)
71 continue
72 }
73 if !ok {
74 if !tt.bad {
75 t.Errorf("%s(%q) failed to parse", fn, tt.in)
76 continue
77 }
78 continue
79 }
80 if !tt.skipBytes {
81 r2, ok := ParseBytes([]byte(tt.in))
82 if r != r2 {
83 t.Errorf("ParseBytes(%q) = %v, %v; want %v", tt.in, r2, ok, r)
84 }
85 }
86 str := r.String()
87 if str != tt.in {
88 t.Errorf("Parsed %q but String() value differs: %q", tt.in, str)
89 }
90 wantDig := str[strings.Index(str, "-")+1:]
91 if dig := r.Digest(); dig != wantDig {
92 t.Errorf("Digest(%q) = %q; want %q", tt.in, dig, wantDig)
93 }
94 _ = r == r // test that concrete type of r supports equality
95 }
96}
97
98func TestEquality(t *testing.T) {
99 in := "sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"

Callers

nothing calls this directly

Calls 5

ParseBytesFunction · 0.85
IndexMethod · 0.80
DigestMethod · 0.80
ValidMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected