diff options
| author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-13 05:11:45 +0000 |
|---|---|---|
| committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-01-13 05:11:45 +0000 |
| commit | 86240434eb153c149dbc3d77f4fedf9cffcbfc53 (patch) | |
| tree | eb5eccc07097c5fcf940967f33ab84a7d47c96fe /libgo/go/bytes | |
| parent | 9599f526f8b241e01ca4d54b5bff9c2e6f6dd75a (diff) | |
| download | ppe42-gcc-86240434eb153c149dbc3d77f4fedf9cffcbfc53.tar.gz ppe42-gcc-86240434eb153c149dbc3d77f4fedf9cffcbfc53.zip | |
libgo: Update to weekly.2011-12-22.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183150 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/bytes')
| -rw-r--r-- | libgo/go/bytes/buffer_test.go | 1 | ||||
| -rw-r--r-- | libgo/go/bytes/bytes_test.go | 17 | ||||
| -rw-r--r-- | libgo/go/bytes/example_test.go | 24 |
3 files changed, 30 insertions, 12 deletions
diff --git a/libgo/go/bytes/buffer_test.go b/libgo/go/bytes/buffer_test.go index 52359700322..adb93302a54 100644 --- a/libgo/go/bytes/buffer_test.go +++ b/libgo/go/bytes/buffer_test.go @@ -16,7 +16,6 @@ const N = 10000 // make this bigger for a larger (and slower) test var data string // test data for write tests var bytes []byte // test data; same as data but as a slice. - func init() { bytes = make([]byte, N) for i := 0; i < N; i++ { diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go index a2a08c20db0..2a1d41b910e 100644 --- a/libgo/go/bytes/bytes_test.go +++ b/libgo/go/bytes/bytes_test.go @@ -289,8 +289,7 @@ func bmIndexByte(b *testing.B, index func([]byte, byte) int, n int) { for i := 0; i < b.N; i++ { j := index(buf, 'x') if j != n-1 { - println("bad index", j) - panic("bad index") + b.Fatal("bad index", j) } } buf[n-1] = '\x00' @@ -317,7 +316,7 @@ func bmEqual(b *testing.B, equal func([]byte, []byte) bool, n int) { for i := 0; i < b.N; i++ { eq := equal(buf1, buf2) if !eq { - panic("bad equal") + b.Fatal("bad equal") } } buf1[n-1] = '\x00' @@ -339,8 +338,7 @@ func bmIndex(b *testing.B, index func([]byte, []byte) int, n int) { for i := 0; i < b.N; i++ { j := index(buf, buf[n-7:]) if j != n-7 { - println("bad index", j) - panic("bad index") + b.Fatal("bad index", j) } } buf[n-1] = '\x00' @@ -362,8 +360,7 @@ func bmIndexEasy(b *testing.B, index func([]byte, []byte) int, n int) { for i := 0; i < b.N; i++ { j := index(buf, buf[n-7:]) if j != n-7 { - println("bad index", j) - panic("bad index") + b.Fatal("bad index", j) } } buf[n-1] = '\x00' @@ -385,8 +382,7 @@ func bmCount(b *testing.B, count func([]byte, []byte) int, n int) { for i := 0; i < b.N; i++ { j := count(buf, buf[n-7:]) if j != 1 { - println("bad count", j) - panic("bad count") + b.Fatal("bad count", j) } } buf[n-1] = '\x00' @@ -408,8 +404,7 @@ func bmCountEasy(b *testing.B, count func([]byte, []byte) int, n int) { for i := 0; i < b.N; i++ { j := count(buf, buf[n-7:]) if j != 1 { - println("bad count", j) - panic("bad count") + b.Fatal("bad count", j) } } buf[n-1] = '\x00' diff --git a/libgo/go/bytes/example_test.go b/libgo/go/bytes/example_test.go new file mode 100644 index 00000000000..02da1ac082b --- /dev/null +++ b/libgo/go/bytes/example_test.go @@ -0,0 +1,24 @@ +package bytes_test + +import ( + . "bytes" + "encoding/base64" + "io" + "os" +) + +// Hello world! +func ExampleBuffer() { + var b Buffer // A Buffer needs no initialization. + b.Write([]byte("Hello ")) + b.Write([]byte("world!")) + b.WriteTo(os.Stdout) +} + +// Gophers rule! +func ExampleBuffer_reader() { + // A Buffer can turn a string or a []byte into an io.Reader. + buf := NewBufferString("R29waGVycyBydWxlIQ==") + dec := base64.NewDecoder(base64.StdEncoding, buf) + io.Copy(os.Stdout, dec) +} |

