mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Revert "godoc: skip build tag annotations when displaying examples"
This reverts commit faa8a71ab532725a7fd9d901a97f74c5038c409b. Reason for revert: +build tag in test causes build to fail :( Change-Id: I8942a6dcc29faaceada23b63ba80ea881b3b2ca6 Reviewed-on: https://go-review.googlesource.com/126195 Reviewed-by: Andrew Bonventre <andybons@golang.org> Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
faa8a71ab5
commit
bfb5194568
@ -666,7 +666,6 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
|
||||
play := ""
|
||||
if eg.Play != nil && p.ShowPlayground {
|
||||
var buf bytes.Buffer
|
||||
eg.Play.Comments = filterOutBuildAnnotations(eg.Play.Comments)
|
||||
if err := format.Node(&buf, info.FSet, eg.Play); err != nil {
|
||||
log.Print(err)
|
||||
} else {
|
||||
@ -695,23 +694,6 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func filterOutBuildAnnotations(cg []*ast.CommentGroup) []*ast.CommentGroup {
|
||||
if len(cg) == 0 {
|
||||
return cg
|
||||
}
|
||||
|
||||
for i := range cg {
|
||||
if !strings.HasPrefix(cg[i].Text(), "+build ") {
|
||||
// Found the first non-build tag, return from here until the end
|
||||
// of the slice.
|
||||
return cg[i:]
|
||||
}
|
||||
}
|
||||
|
||||
// There weren't any non-build tags, return an empty slice.
|
||||
return []*ast.CommentGroup{}
|
||||
}
|
||||
|
||||
// example_nameFunc takes an example function name and returns its display
|
||||
// name. For example, "Foo_Bar_quux" becomes "Foo.Bar (Quux)".
|
||||
func (p *Presentation) example_nameFunc(s string) string {
|
||||
|
@ -321,48 +321,3 @@ func TestSrcToPkgLinkFunc(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterOutBuildAnnotations(t *testing.T) {
|
||||
src := []byte(`
|
||||
// +build !foo
|
||||
// +build !anothertag
|
||||
|
||||
// non-tag comment
|
||||
|
||||
package foo
|
||||
|
||||
func bar() int {
|
||||
return 42
|
||||
}`)
|
||||
|
||||
fset := token.NewFileSet()
|
||||
af, err := parser.ParseFile(fset, "foo.go", src, parser.ParseComments)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var found bool
|
||||
for _, cg := range af.Comments {
|
||||
if strings.HasPrefix(cg.Text(), "+build ") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("TestFilterOutBuildAnnotations is broken: missing build tag in test input")
|
||||
}
|
||||
|
||||
found = false
|
||||
for _, cg := range filterOutBuildAnnotations(af.Comments) {
|
||||
if strings.HasPrefix(cg.Text(), "+build ") {
|
||||
t.Errorf("filterOutBuildAnnotations failed to filter build tag")
|
||||
}
|
||||
|
||||
if strings.Contains(cg.Text(), "non-tag comment") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("filterOutBuildAnnotations should not remove non-build tag comment")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user