diff options
| author | Andrew Gerrand <adg@golang.org> | 2012-02-16 11:50:28 +1100 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2012-02-16 11:50:28 +1100 |
| commit | 11e113db573369e1fd5f92844269d31ae3815c25 (patch) | |
| tree | c043d6cc2b47330b42d8bc5384af16fe2c0e1407 /src/pkg/encoding/binary | |
| parent | fa0100cf26336053f9c072c3cb1081a09df41449 (diff) | |
| download | go-11e113db573369e1fd5f92844269d31ae3815c25.tar.xz | |
godoc: make example code more readable with new comment convention
go/doc: move Examples to go/ast
cmd/go: use go/doc to read examples
src/pkg: update examples to use new convention
This is to make whole file examples more readable. When presented as a
complete function, preceding an Example with its output is confusing.
The new convention is to put the expected output in the final comment
of the example, preceded by the string "output:" (case insensitive).
An idiomatic example looks like this:
// This example demonstrates Foo by doing bar and quux.
func ExampleFoo() {
// example body that does bar and quux
// Output:
// example output
}
R=rsc, gri
CC=golang-dev
https://golang.org/cl/5673053
Diffstat (limited to 'src/pkg/encoding/binary')
| -rw-r--r-- | src/pkg/encoding/binary/example_test.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/pkg/encoding/binary/example_test.go b/src/pkg/encoding/binary/example_test.go index 297d6c1ae3..405ea67891 100644 --- a/src/pkg/encoding/binary/example_test.go +++ b/src/pkg/encoding/binary/example_test.go @@ -11,7 +11,6 @@ import ( "math" ) -// 18 2d 44 54 fb 21 09 40 func ExampleWrite() { buf := new(bytes.Buffer) var pi float64 = math.Pi @@ -20,9 +19,9 @@ func ExampleWrite() { fmt.Println("binary.Write failed:", err) } fmt.Printf("% x", buf.Bytes()) + // Output: 18 2d 44 54 fb 21 09 40 } -// cafebabe func ExampleWrite_multi() { buf := new(bytes.Buffer) var data = []interface{}{ @@ -37,9 +36,9 @@ func ExampleWrite_multi() { } } fmt.Printf("%x", buf.Bytes()) + // Output: cafebabe } -// 3.141592653589793 func ExampleRead() { var pi float64 b := []byte{0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40} @@ -49,4 +48,5 @@ func ExampleRead() { fmt.Println("binary.Read failed:", err) } fmt.Print(pi) + // Output: 3.141592653589793 } |
