diff --git a/src/go/doc/example.go b/src/go/doc/example.go index 228bdf58f8..ba1f863df0 100644 --- a/src/go/doc/example.go +++ b/src/go/doc/example.go @@ -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 { diff --git a/src/go/doc/testdata/examples/major_version.go b/src/go/doc/testdata/examples/major_version.go new file mode 100644 index 0000000000..6d91874a89 --- /dev/null +++ b/src/go/doc/testdata/examples/major_version.go @@ -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 +} diff --git a/src/go/doc/testdata/examples/major_version.golden b/src/go/doc/testdata/examples/major_version.golden new file mode 100644 index 0000000000..7cf2f2f32a --- /dev/null +++ b/src/go/doc/testdata/examples/major_version.golden @@ -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