aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/bytes
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-01-13 05:11:45 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-01-13 05:11:45 +0000
commitdf4aa89a5e7acb315655f193e7f549e8d32367e2 (patch)
treeeb5eccc07097c5fcf940967f33ab84a7d47c96fe /libgo/go/bytes
parentf83fa0bf8f411697ec908cfa86ee6faf4cd9c476 (diff)
downloadgcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.zip
gcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.tar.gz
gcc-df4aa89a5e7acb315655f193e7f549e8d32367e2.tar.bz2
libgo: Update to weekly.2011-12-22.
From-SVN: r183150
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r--libgo/go/bytes/buffer_test.go1
-rw-r--r--libgo/go/bytes/bytes_test.go17
-rw-r--r--libgo/go/bytes/example_test.go24
3 files changed, 30 insertions, 12 deletions
diff --git a/libgo/go/bytes/buffer_test.go b/libgo/go/bytes/buffer_test.go
index 5235970..adb9330 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 a2a08c2..2a1d41b 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 0000000..02da1ac
--- /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)
+}