diff options
| author | Andrew Gerrand <adg@golang.org> | 2011-12-16 09:43:58 +1100 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2011-12-16 09:43:58 +1100 |
| commit | 9834a25d338c957e24f0f19236b8bf56addb2e9c (patch) | |
| tree | 8d2f449a2ef877432053bfa4ff5a2e928b5a02e4 /src/pkg/bytes | |
| parent | a369004e2318ad0f139f967c764918bd939980ce (diff) | |
| download | go-9834a25d338c957e24f0f19236b8bf56addb2e9c.tar.xz | |
testing: trim spaces before comparing example output
bytes: add two Buffer examples
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5490048
Diffstat (limited to 'src/pkg/bytes')
| -rw-r--r-- | src/pkg/bytes/example_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pkg/bytes/example_test.go b/src/pkg/bytes/example_test.go new file mode 100644 index 0000000000..02da1ac082 --- /dev/null +++ b/src/pkg/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) +} |
