1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This code is a duplicate of ../chunked_test.go with these edits:
6 // s/newChunked/NewChunked/g
7 // s/package http/package httputil/
8 // Please make any changes in both files.
18 func TestChunk(t *testing.T) {
21 w := NewChunkedWriter(&b)
22 const chunk1 = "hello, "
23 const chunk2 = "world! 0123456789abcdef"
24 w.Write([]byte(chunk1))
25 w.Write([]byte(chunk2))
28 if g, e := b.String(), "7\r\nhello, \r\n17\r\nworld! 0123456789abcdef\r\n0\r\n"; g != e {
29 t.Fatalf("chunk writer wrote %q; want %q", g, e)
32 r := NewChunkedReader(&b)
33 data, err := ioutil.ReadAll(r)
35 t.Logf(`data: "%s"`, data)
36 t.Fatalf("ReadAll from reader: %v", err)
38 if g, e := string(data), chunk1+chunk2; g != e {
39 t.Errorf("chunk reader read %q; want %q", g, e)