"go/printer"
"go/token"
"strings"
- "testing"
)
-// Dummy test function so that godoc does not use the entire file as example.
-func Test(*testing.T) {}
-
func parseFunc(filename, functionname string) (fun *ast.FuncDecl, fset *token.FileSet) {
fset = token.NewFileSet()
if file, err := parser.ParseFile(fset, filename, nil, 0); err == nil {
panic("function not found")
}
-func ExampleFprint() {
+func printSelf() {
// Parse source file and extract the AST without comments for
// this function, with position information referring to the
// file set fset.
- funcAST, fset := parseFunc("example_test.go", "ExampleFprint")
+ funcAST, fset := parseFunc("example_test.go", "printSelf")
// Print the function body into buffer buf.
// The file set is provided to the printer so that it knows
// Print the cleaned-up body text to stdout.
fmt.Println(s)
+}
+
+func ExampleFprint() {
+ printSelf()
- // output:
- // funcAST, fset := parseFunc("example_test.go", "ExampleFprint")
+ // Output:
+ // funcAST, fset := parseFunc("example_test.go", "printSelf")
//
// var buf bytes.Buffer
// printer.Fprint(&buf, fset, funcAST.Body)