39
42
t.Errorf("chunk reader read %q; want %q", g, e)
46
func TestChunkReaderAllocs(t *testing.T) {
47
// temporarily set GOMAXPROCS to 1 as we are testing memory allocations
48
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
50
w := NewChunkedWriter(&buf)
51
a, b, c := []byte("aaaaaa"), []byte("bbbbbbbbbbbb"), []byte("cccccccccccccccccccccccc")
57
r := NewChunkedReader(&buf)
58
readBuf := make([]byte, len(a)+len(b)+len(c)+1)
60
var ms runtime.MemStats
61
runtime.ReadMemStats(&ms)
64
n, err := io.ReadFull(r, readBuf)
66
runtime.ReadMemStats(&ms)
67
mallocs := ms.Mallocs - m0
69
t.Errorf("%d mallocs; want <= 1", mallocs)
72
if n != len(readBuf)-1 {
73
t.Errorf("read %d bytes; want %d", n, len(readBuf)-1)
75
if err != io.ErrUnexpectedEOF {
76
t.Errorf("read error = %v; want ErrUnexpectedEOF", err)
80
func TestParseHexUint(t *testing.T) {
81
for i := uint64(0); i <= 1234; i++ {
82
line := []byte(fmt.Sprintf("%x", i))
83
got, err := parseHexUint(line)
85
t.Fatalf("on %d: %v", i, err)
88
t.Errorf("for input %q = %d; want %d", line, got, i)
91
_, err := parseHexUint([]byte("bogus"))
93
t.Error("expected error on bogus input")