mirror of
https://github.com/golang/go.git
synced 2025-12-28 06:34:04 +00:00
go/doc: reuse import name logic for examples
Examples resolved imports based on just the path name, but this doesn't work for go-name or modules on v2+. Updates #12794 Fixes #45110 Fixes #56740 Fixes #62059 Change-Id: I8c71b1e5311df04bccbdf319d759d3176a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/728280 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
927c89bbc5
commit
e8a83788a4
@ -11,7 +11,6 @@ import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"internal/lazyregexp"
|
||||
"path"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -221,7 +220,7 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File {
|
||||
// because the package syscall/js is not available in the playground.
|
||||
return nil
|
||||
}
|
||||
n := path.Base(p)
|
||||
n := assumedPackageName(p)
|
||||
if s.Name != nil {
|
||||
n = s.Name.Name
|
||||
switch n {
|
||||
|
||||
14
src/go/doc/testdata/examples/major_version.go
vendored
Normal file
14
src/go/doc/testdata/examples/major_version.go
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
package foo_test
|
||||
|
||||
import (
|
||||
"example.com/foo/v3"
|
||||
"example.com/go-bar"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
foo.Print("hello")
|
||||
bar.Print("world")
|
||||
// Output:
|
||||
// hello
|
||||
// world
|
||||
}
|
||||
15
src/go/doc/testdata/examples/major_version.golden
vendored
Normal file
15
src/go/doc/testdata/examples/major_version.golden
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
-- .Play --
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/foo/v3"
|
||||
"example.com/go-bar"
|
||||
)
|
||||
|
||||
func main() {
|
||||
foo.Print("hello")
|
||||
bar.Print("world")
|
||||
}
|
||||
-- .Output --
|
||||
hello
|
||||
world
|
||||
Loading…
Reference in New Issue
Block a user