1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:34:48 -07:00

go/doc: fix example generation for package prefixed with go-

Trim go- prefix from package name (like it's done on runtime) before looking for related unresolved package.

Fixes #56740
This commit is contained in:
Yoanm 2022-11-15 20:18:02 +01:00
parent 96711e4d8b
commit 9d90f935ac
3 changed files with 34 additions and 0 deletions

View File

@ -238,6 +238,9 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File {
// We can't resolve dot imports (yet).
return nil
}
} else {
// Trim 'go-' prefix from package name (like done at runtime) to ensure match
n = strings.TrimPrefix(n, "go-")
}
if unresolved[n] {
// Copy the spec and its path to avoid modifying the original.

View File

@ -0,0 +1,17 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package foo_test
import (
"fmt"
"github.com/xxx/go-foo"
)
func ExampleMyMethod() {
fmt.Println(foo.MyMethod())
// Output:
// expected output
}

View File

@ -0,0 +1,14 @@
-- MyMethod.Play --
package main
import (
"fmt"
"github.com/xxx/go-foo"
)
func main() {
fmt.Println(foo.MyMethod())
}
-- MyMethod.Output --
expected output