MCPcopy Create free account
hub / github.com/antonmedv/gitmal / run

Method run

pkg/gitdiff/apply_test.go:171–200  ·  view source on GitHub ↗
(t *testing.T, apply func(io.Writer, io.ReaderAt, *File) error)

Source from the content-addressed store, hash-verified

169}
170
171func (at applyTest) run(t *testing.T, apply func(io.Writer, io.ReaderAt, *File) error) {
172 src, patch, out := at.Files.Load(t)
173
174 files, _, err := Parse(bytes.NewReader(patch))
175 if err != nil {
176 t.Fatalf("failed to parse patch file: %v", err)
177 }
178 if len(files) != 1 {
179 t.Fatalf("patch should contain exactly one file, but it has %d", len(files))
180 }
181
182 var dst bytes.Buffer
183 err = apply(&dst, bytes.NewReader(src), files[0])
184 if at.Err != nil {
185 assertError(t, at.Err, err, "applying fragment")
186 return
187 }
188 if err != nil {
189 var aerr *ApplyError
190 if errors.As(err, &aerr) {
191 t.Fatalf("unexpected error applying: at %d: fragment %d at %d: %v", aerr.Line, aerr.Fragment, aerr.FragmentLine, err)
192 } else {
193 t.Fatalf("unexpected error applying: %v", err)
194 }
195 }
196
197 if !bytes.Equal(out, dst.Bytes()) {
198 t.Errorf("incorrect result after apply\nexpected:\n%q\nactual:\n%q", out, dst.Bytes())
199 }
200}
201
202type applyFiles struct {
203 Src string

Callers 3

TestApplyTextFragmentFunction · 0.80
TestApplyBinaryFragmentFunction · 0.80
TestApplyFileFunction · 0.80

Calls 4

ParseFunction · 0.85
assertErrorFunction · 0.85
LoadMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected