Skip to content

Commit

Permalink
test:update godoc.Render
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed May 10, 2024
1 parent 6aed5c8 commit 3721a51
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
40 changes: 40 additions & 0 deletions internal/godoc/render_gop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package godoc

import (
"context"
"path/filepath"
"strings"
"testing"

"golang.org/x/net/html"
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/godoc/dochtml"
"golang.org/x/pkgsite/internal/source"
)

func TestGopRender(t *testing.T) {
dochtml.LoadTemplates(templateFS)
ctx := context.Background()
p, err := packageForDir(filepath.Join("testdata", "gop"), false)
if err != nil {
t.Fatal(err)
}
parts, err := p.Render(ctx, "", &source.Info{}, &dochtml.ModuleInfo{}, nil, internal.BuildContext{})
if err != nil {
t.Fatal(err)
}
htmlDoc, err := html.Parse(strings.NewReader(parts.Body.String()))
if err != nil {
t.Fatal(err)
}
wantFuncAnchor := []string{"Mul", "Mul__1", "Mul__2", "MulFloat", "MulInt"}
for _, anchor := range wantFuncAnchor {
t.Run(anchor, func(t *testing.T) {
checker := in("h4.Documentation-functionHeader#" + anchor)
if err := checker(htmlDoc); err != nil {
t.Fatal(err)
}
})
}
// TODO: check overload method (htmlcheck.Checker cant select id like "foo.Division")

Check warning on line 39 in internal/godoc/render_gop_test.go

View check run for this annotation

qiniu-x / note-check

internal/godoc/render_gop_test.go#L39

A Note is recommended to use "MARKER(uid): note body" format.
}
20 changes: 20 additions & 0 deletions internal/godoc/testdata/gop/overload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package foo

const GopPackage = true

const Gopo_Mul = "MulInt,,MulFloat"

// 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
}
4 changes: 3 additions & 1 deletion internal/gopdoc/z_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ func TestIsGopPackage(t *testing.T) {
if isGopPackage(&doc.Package{}) {
t.Fatal("isGopPackage: true?")
}
if _, gopInfo := Transform(&doc.Package{}); gopInfo != nil {
t.Fatal("go package should not get gopInfo after transform")
}
}

func TestDocRecv(t *testing.T) {
if _, ok := docRecv(&ast.Field{}); ok {
t.Fatal("docRecv: ok?")
Expand Down

0 comments on commit 3721a51

Please sign in to comment.