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

Function TestCopyFrom

pkg/gitdiff/io_test.go:171–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestCopyFrom(t *testing.T) {
172 tests := map[string]struct {
173 Bytes int64
174 Offset int64
175 }{
176 "copyAll": {
177 Bytes: byteBufferSize / 2,
178 },
179 "copyPartial": {
180 Bytes: byteBufferSize / 2,
181 Offset: byteBufferSize / 4,
182 },
183 "copyLarge": {
184 Bytes: 8 * byteBufferSize,
185 },
186 }
187
188 for name, test := range tests {
189 t.Run(name, func(t *testing.T) {
190 data := make([]byte, test.Bytes)
191 rand.Read(data)
192
193 var dst bytes.Buffer
194 n, err := copyFrom(&dst, bytes.NewReader(data), test.Offset)
195 if err != nil {
196 t.Fatalf("unexpected error copying data: %v", err)
197 }
198 if n != test.Bytes-test.Offset {
199 t.Fatalf("incorrect number of bytes copied: expected %d, actual %d", test.Bytes-test.Offset, n)
200 }
201
202 expected := data[test.Offset:]
203 if !bytes.Equal(expected, dst.Bytes()) {
204 t.Fatalf("incorrect data copied:\nexpected: %v\nactual: %v", expected, dst.Bytes())
205 }
206 })
207 }
208}
209
210func TestCopyLinesFrom(t *testing.T) {
211 tests := map[string]struct {

Callers

nothing calls this directly

Calls 1

copyFromFunction · 0.85

Tested by

no test coverage detected