Daily bump.
[official-gcc.git] / libgo / go / exp / norm / readwriter_test.go
blob3b49eb0a2f08631adb454bb3c1e65da093a82fd8
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 package norm
7 import (
8 "bytes"
9 "fmt"
10 "strings"
11 "testing"
14 var ioTests = []AppendTest{
15 {"", strings.Repeat("a\u0316\u0300", 6), strings.Repeat("\u00E0\u0316", 6)},
16 {"", strings.Repeat("a\u0300\u0316", 4000), strings.Repeat("\u00E0\u0316", 4000)},
17 {"", strings.Repeat("\x80\x80", 4000), strings.Repeat("\x80\x80", 4000)},
18 {"", "\u0041\u0307\u0304", "\u01E0"},
21 var bufSizes = []int{1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 102, 103, 4000, 4001, 4002, 4003}
23 func readFunc(size int) appendFunc {
24 return func(f Form, out []byte, s string) []byte {
25 out = append(out, s...)
26 r := f.Reader(bytes.NewBuffer(out))
27 buf := make([]byte, size)
28 result := []byte{}
29 for n, err := 0, error(nil); err == nil; {
30 n, err = r.Read(buf)
31 result = append(result, buf[:n]...)
33 return result
37 func TestReader(t *testing.T) {
38 for _, s := range bufSizes {
39 name := fmt.Sprintf("TestReader%da", s)
40 runAppendTests(t, name, NFKC, readFunc(s), appendTests)
41 name = fmt.Sprintf("TestReader%db", s)
42 runAppendTests(t, name, NFKC, readFunc(s), ioTests)
46 func writeFunc(size int) appendFunc {
47 return func(f Form, out []byte, s string) []byte {
48 in := append(out, s...)
49 result := new(bytes.Buffer)
50 w := f.Writer(result)
51 buf := make([]byte, size)
52 for n := 0; len(in) > 0; in = in[n:] {
53 n = copy(buf, in)
54 _, _ = w.Write(buf[:n])
56 w.Close()
57 return result.Bytes()
61 func TestWriter(t *testing.T) {
62 for _, s := range bufSizes {
63 name := fmt.Sprintf("TestWriter%da", s)
64 runAppendTests(t, name, NFKC, writeFunc(s), appendTests)
65 name = fmt.Sprintf("TestWriter%db", s)
66 runAppendTests(t, name, NFKC, writeFunc(s), ioTests)