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.
13 var bufSizes = []int{1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 102, 103, 4000, 4001, 4002, 4003}
15 func readFunc(size int) appendFunc {
16 return func(f Form, out []byte, s string) []byte {
17 out = append(out, s...)
18 r := f.Reader(bytes.NewBuffer(out))
19 buf := make([]byte, size)
21 for n, err := 0, error(nil); err == nil; {
23 result = append(result, buf[:n]...)
29 func TestReader(t *testing.T) {
30 for _, s := range bufSizes {
31 name := fmt.Sprintf("TestReader%d", s)
32 runNormTests(t, name, readFunc(s))
36 func writeFunc(size int) appendFunc {
37 return func(f Form, out []byte, s string) []byte {
38 in := append(out, s...)
39 result := new(bytes.Buffer)
41 buf := make([]byte, size)
42 for n := 0; len(in) > 0; in = in[n:] {
44 _, _ = w.Write(buf[:n])
51 func TestWriter(t *testing.T) {
52 for _, s := range bufSizes {
53 name := fmt.Sprintf("TestWriter%d", s)
54 runNormTests(t, name, writeFunc(s))