Skip to content

Commit

Permalink
test:add overload render test
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Apr 7, 2024
1 parent fd4860a commit bdf1365
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/godoc/dochtml/dochtml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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.
Expand Down
61 changes: 61 additions & 0 deletions internal/godoc/dochtml/testdata/overload.go
Original file line number Diff line number Diff line change
@@ -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()) {
}
Loading

0 comments on commit bdf1365

Please sign in to comment.