From d47c6794606eb47f95ae80898adc9e5e42d3f51b Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Sat, 6 Apr 2024 01:35:12 +0800 Subject: [PATCH] test:add overload render test --- internal/godoc/dochtml/dochtml_test.go | 14 + internal/godoc/dochtml/testdata/overload.go | 47 +++ .../godoc/dochtml/testdata/overload.golden | 296 ++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 internal/godoc/dochtml/testdata/overload.go create mode 100644 internal/godoc/dochtml/testdata/overload.golden 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..1396d3c7b --- /dev/null +++ b/internal/godoc/dochtml/testdata/overload.go @@ -0,0 +1,47 @@ +package qqq + +type App struct{} + +const GopPackage = true + +const Gopo_Mul = "MulInt,,MulFloat" + +// 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 +} + +type N struct { +} + +// 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..352c57dd4 --- /dev/null +++ b/internal/godoc/dochtml/testdata/overload.golden @@ -0,0 +1,296 @@ +
const GopPackage = true
+const Gopo_Mul = "MulInt,,MulFloat"
+This section is empty.