MCPcopy Index your code
hub / github.com/golang/groupcache / TestByteView

Function TestByteView

byteview_test.go:27–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestByteView(t *testing.T) {
28 for _, s := range []string{"", "x", "yy"} {
29 for _, v := range []ByteView{of([]byte(s)), of(s)} {
30 name := fmt.Sprintf("string %q, view %+v", s, v)
31 if v.Len() != len(s) {
32 t.Errorf("%s: Len = %d; want %d", name, v.Len(), len(s))
33 }
34 if v.String() != s {
35 t.Errorf("%s: String = %q; want %q", name, v.String(), s)
36 }
37 var longDest [3]byte
38 if n := v.Copy(longDest[:]); n != len(s) {
39 t.Errorf("%s: long Copy = %d; want %d", name, n, len(s))
40 }
41 var shortDest [1]byte
42 if n := v.Copy(shortDest[:]); n != min(len(s), 1) {
43 t.Errorf("%s: short Copy = %d; want %d", name, n, min(len(s), 1))
44 }
45 if got, err := ioutil.ReadAll(v.Reader()); err != nil || string(got) != s {
46 t.Errorf("%s: Reader = %q, %v; want %q", name, got, err, s)
47 }
48 if got, err := ioutil.ReadAll(io.NewSectionReader(v, 0, int64(len(s)))); err != nil || string(got) != s {
49 t.Errorf("%s: SectionReader of ReaderAt = %q, %v; want %q", name, got, err, s)
50 }
51 var dest bytes.Buffer
52 if _, err := v.WriteTo(&dest); err != nil || !bytes.Equal(dest.Bytes(), []byte(s)) {
53 t.Errorf("%s: WriteTo = %q, %v; want %q", name, dest.Bytes(), err, s)
54 }
55 }
56 }
57}
58
59// of returns a byte view of the []byte or string in x.
60func of(x interface{}) ByteView {

Callers

nothing calls this directly

Calls 8

ofFunction · 0.85
minFunction · 0.85
CopyMethod · 0.80
ReaderMethod · 0.80
WriteToMethod · 0.80
EqualMethod · 0.80
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…