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
diff --git a/src/pkg/math/big/example_test.go b/src/pkg/math/big/example_test.go
index ba676ec..078be47 100644
--- a/src/pkg/math/big/example_test.go
+++ b/src/pkg/math/big/example_test.go
@@ -10,21 +10,20 @@
"math/big"
)
-// 3.142
func ExampleRat_SetString() {
r := new(big.Rat)
r.SetString("355/113")
fmt.Println(r.FloatString(3))
+ // Output: 3.142
}
-// 420
func ExampleInt_SetString() {
i := new(big.Int)
i.SetString("644", 8) // octal
fmt.Println(i)
+ // Output: 420
}
-// 3/2
func ExampleRat_Scan() {
// The Scan function is rarely used directly;
// the fmt package recognizes it as an implementation of fmt.Scanner.
@@ -35,9 +34,9 @@
} else {
fmt.Println(r)
}
+ // Output: 3/2
}
-// 18446744073709551617
func ExampleInt_Scan() {
// The Scan function is rarely used directly;
// the fmt package recognizes it as an implementation of fmt.Scanner.
@@ -48,4 +47,5 @@
} else {
fmt.Println(i)
}
+ // Output: 18446744073709551617
}