OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [exp/] [norm/] [readwriter_test.go] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package norm
6
 
7
import (
8
        "bytes"
9
        "fmt"
10
        "strings"
11
        "testing"
12
)
13
 
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"},
19
}
20
 
21
var bufSizes = []int{1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 102, 103, 4000, 4001, 4002, 4003}
22
 
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]...)
32
                }
33
                return result
34
        }
35
}
36
 
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)
43
        }
44
}
45
 
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])
55
                }
56
                w.Close()
57
                return result.Bytes()
58
        }
59
}
60
 
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)
67
        }
68
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.