(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func 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. |
| 60 | func of(x interface{}) ByteView { |
nothing calls this directly
no test coverage detected
searching dependent graphs…