]> Cypherpunks repositories - gostls13.git/commit
go/printer: make ExampleFprint correctly run as online example
authorShengyu Zhang <zhangshengyu.0@bytedance.com>
Tue, 23 Aug 2022 02:27:04 +0000 (02:27 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 16 Sep 2022 14:55:02 +0000 (14:55 +0000)
commit88b51d2e630738f9396e3825eafd90d03727ec0d
treef0652b01bf0a60ff72be98de73cbbfe368aa9dc4
parentb35b4a31e167a170a5ee481ed525272bc44dcc33
go/printer: make ExampleFprint correctly run as online example

function "ExampleFprint" will be rewritten to function "main"
when displayed on the godoc pages, so the online example is failed to
run:

    Output:

    panic: function not found

    goroutine 1 [running]:
    main.parseFunc({0x4f772e, 0xf}, {0x4f713f, 0xd})
            /tmp/sandbox1264544227/prog.go:23 +0x13b
    main.main()
            /tmp/sandbox1264544227/prog.go:30 +0x45

See: https://pkg.go.dev/go/printer#example-Fprint

Add printSelf function to prevent the function not found when running in godoc
sandbox. Beside, deleting the dummy test function to make the example show
the entire file, as we want to show the newly added printSelf function.

Change-Id: Ia2b772937081b58a0fce9860838959c95f2d650c
GitHub-Last-Rev: bac11891735e48b8ffe99cd1096bcb3f08c6575d
GitHub-Pull-Request: golang/go#53141
Reviewed-on: https://go-review.googlesource.com/c/go/+/409314
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/go/printer/example_test.go