diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go index 617f4f7a3..7ab053242 100644 --- a/internal/godoc/dochtml/dochtml_test.go +++ b/internal/godoc/dochtml/dochtml_test.go @@ -26,6 +26,8 @@ import ( "golang.org/x/net/html" "golang.org/x/pkgsite/internal/godoc/dochtml/internal/render" "golang.org/x/pkgsite/internal/testing/testhelper" + + gopdoc "golang.org/x/pkgsite/internal/gopdoc" ) var templateFS = template.TrustedFSFromTrustedSource(template.TrustedSourceFromConstant("../../../static")) @@ -90,6 +92,18 @@ func TestRenderDeprecated(t *testing.T) { compareWithGolden(t, parts, "deprecated-on", *update) } +func TestRenderOverload(t *testing.T) { + t.Helper() + LoadTemplates(templateFS) + fset, d := mustLoadPackage("overload") + gopdoc.Transform(d) + parts, err := Render(context.Background(), fset, d, testRenderOptions) + if err != nil { + t.Fatal(err) + } + compareWithGolden(t, parts, "overload", *update) +} + func compareWithGolden(t *testing.T, parts *Parts, name string, update bool) { got := fmt.Sprintf("%s\n----\n%s\n----\n%s\n", parts.Body, parts.Outline, parts.MobileOutline) // Remove blank lines and whitespace around lines. diff --git a/internal/godoc/dochtml/testdata/overload.go b/internal/godoc/dochtml/testdata/overload.go new file mode 100644 index 000000000..02971743c --- /dev/null +++ b/internal/godoc/dochtml/testdata/overload.go @@ -0,0 +1,61 @@ +package overload + +import "fmt" + +const GopPackage = true + +const Gopo_Mul = "MulInt,,MulFloat" + +type N struct { +} +type Foo struct { +} + +const Gopo_Foo_Division = ".DivisionInt,.DivisionFoo" + +// Add int +func Add__0(a int, b int) int { + return a + b +} + +// Add string +func Add__1(a string, b string) string { + return a + b +} + +// Mut int +func MulInt(a int, b int) int { + return a * b +} + +// Mut string +func Mul__1(a string, b string) string { + return a + b +} + +// Mut float +func MulFloat(a float64, b float64) float64 { + return a * b +} + +func (a *Foo) DivisionInt(b int) *Foo { + fmt.Println("DivisionInt") + return a +} + +func (a *Foo) DivisionFoo(b *Foo) *Foo { + fmt.Println("DivisionFoo") + return a +} + +// OnKey string && fn +func (m *N) OnKey__0(a string, fn func()) { +} + +// OnKey string && fn(string) +func (m *N) OnKey__1(a string, fn func(key string)) { +} + +// OnKey string[] && fn(string) +func (m *N) OnKey__2(a []string, fn func()) { +} diff --git a/internal/godoc/dochtml/testdata/overload.golden b/internal/godoc/dochtml/testdata/overload.golden new file mode 100644 index 000000000..fde385165 --- /dev/null +++ b/internal/godoc/dochtml/testdata/overload.golden @@ -0,0 +1,378 @@ +
+

Index

+ +

Constants

+
+
+View Source +
const GopPackage = true
+
+
+View Source +
const Gopo_Foo_Division = ".DivisionInt,.DivisionFoo"
+
+
+View Source +
const Gopo_Mul = "MulInt,,MulFloat"
+
+
+

Variables

+

This section is empty.

+

Functions

+
+

+func Add + + +

+
+
func Add(a int, b int) int
+
+

Add int +

+
+

+func Add + + +

+
+
func Add(a string, b string) string
+
+

Add string +

+
+

+func Mul + + +

+
+
func Mul(a int, b int) int
+
+

Mut int +

+
+

+func Mul + + +

+
+
func Mul(a string, b string) string
+
+

Mut string +

+
+

+func Mul + + +

+
+
func Mul(a float64, b float64) float64
+
+

Mut float +

+
+

+func MulFloat + + +

+
+
func MulFloat(a float64, b float64) float64
+
+

Mut float +

+
+

+func MulInt + + +

+
+
func MulInt(a int, b int) int
+
+

Mut int +

+
+

Types

+
+

+type Foo + + +

+
+
type Foo struct {
+}
+
+
+

+func (*Foo) Division + + +

+
+
func (a *Foo) Division(b int) *Foo
+
+
+

+func (*Foo) Division + + +

+
+
func (a *Foo) Division(b *Foo) *Foo
+
+
+

+func (*Foo) DivisionFoo + + +

+
+
func (a *Foo) DivisionFoo(b *Foo) *Foo
+
+
+

+func (*Foo) DivisionInt + + +

+
+
func (a *Foo) DivisionInt(b int) *Foo
+
+
+
+

+type N + + +

+
+
type N struct {
+}
+
+
+

+func (*N) OnKey + + +

+
+
func (m *N) OnKey(a string, fn func())
+
+

OnKey string && fn +

+
+

+func (*N) OnKey + + +

+
+
func (m *N) OnKey(a string, fn func(key string))
+
+

OnKey string && fn(string) +

+
+

+func (*N) OnKey + + +

+
+
func (m *N) OnKey(a []string, fn func())
+
+

OnKey string[] && fn(string) +

+
+
+---- + +---- + + + + + + + + + + + + + + + + + + + + + + + +