MCPcopy Create free account
hub / github.com/Shopify/goose / TestNext

Function TestNext

syncio/buffer_test.go:371–402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

369}
370
371func TestNext(t *testing.T) {
372 b := []byte{0, 1, 2, 3, 4}
373 tmp := make([]byte, 5)
374 for i := 0; i <= 5; i++ {
375 for j := i; j <= 5; j++ {
376 for k := 0; k <= 6; k++ {
377 // 0 <= i <= j <= 5; 0 <= k <= 6
378 // Check that if we start with a buffer
379 // of length j at offset i and ask for
380 // Next(k), we get the right bytes.
381 buf := NewBuffer(b[0:j])
382 n, _ := buf.Read(tmp[0:i])
383 if n != i {
384 t.Fatalf("Read %d returned %d", i, n)
385 }
386 bb := buf.Next(k)
387 want := k
388 if want > j-i {
389 want = j - i
390 }
391 if len(bb) != want {
392 t.Fatalf("in %d,%d: len(Next(%d)) == %d", i, j, k, len(bb))
393 }
394 for l, v := range bb {
395 if v != byte(l+i) {
396 t.Fatalf("in %d,%d: Next(%d)[%d] = %d, want %d", i, j, k, l, v, l+i)
397 }
398 }
399 }
400 }
401 }
402}
403
404var readBytesTests = []struct {
405 buffer string

Callers

nothing calls this directly

Calls 3

ReadMethod · 0.95
NextMethod · 0.95
NewBufferFunction · 0.85

Tested by

no test coverage detected