dwarf2out.c (size_of_aranges): Skip DECL_IGNORED_P functions.
[official-gcc.git] / libgo / go / io / multi_test.go
blobeb717f7bc21c7405bf1716aa100b06a21d9f22b1
1 // Copyright 2010 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 io_test
7 import (
8 "bytes"
9 "crypto/sha1"
10 "fmt"
11 . "io"
12 "strings"
13 "testing"
16 func TestMultiReader(t *testing.T) {
17 var mr Reader
18 var buf []byte
19 nread := 0
20 withFooBar := func(tests func()) {
21 r1 := strings.NewReader("foo ")
22 r2 := strings.NewReader("")
23 r3 := strings.NewReader("bar")
24 mr = MultiReader(r1, r2, r3)
25 buf = make([]byte, 20)
26 tests()
28 expectRead := func(size int, expected string, eerr error) {
29 nread++
30 n, gerr := mr.Read(buf[0:size])
31 if n != len(expected) {
32 t.Errorf("#%d, expected %d bytes; got %d",
33 nread, len(expected), n)
35 got := string(buf[0:n])
36 if got != expected {
37 t.Errorf("#%d, expected %q; got %q",
38 nread, expected, got)
40 if gerr != eerr {
41 t.Errorf("#%d, expected error %v; got %v",
42 nread, eerr, gerr)
44 buf = buf[n:]
46 withFooBar(func() {
47 expectRead(2, "fo", nil)
48 expectRead(5, "o ", nil)
49 expectRead(5, "bar", nil)
50 expectRead(5, "", EOF)
52 withFooBar(func() {
53 expectRead(4, "foo ", nil)
54 expectRead(1, "b", nil)
55 expectRead(3, "ar", nil)
56 expectRead(1, "", EOF)
58 withFooBar(func() {
59 expectRead(5, "foo ", nil)
63 func TestMultiWriter(t *testing.T) {
64 sha1 := sha1.New()
65 sink := new(bytes.Buffer)
66 mw := MultiWriter(sha1, sink)
68 sourceString := "My input text."
69 source := strings.NewReader(sourceString)
70 written, err := Copy(mw, source)
72 if written != int64(len(sourceString)) {
73 t.Errorf("short write of %d, not %d", written, len(sourceString))
76 if err != nil {
77 t.Errorf("unexpected error: %v", err)
80 sha1hex := fmt.Sprintf("%x", sha1.Sum(nil))
81 if sha1hex != "01cb303fa8c30a64123067c5aa6284ba7ec2d31b" {
82 t.Error("incorrect sha1 value")
85 if sink.String() != sourceString {
86 t.Errorf("expected %q; got %q", sourceString, sink.String())