godoc: Restore anchors for variables and constants

godoc once again adds anchors for variable and constant
declarations. Individual declarations and lists of declarations are
both covered.

Fixes golang/go#19894

Change-Id: If5f8f0c3429774f33535e2e654685ba5d71937f1
Reviewed-on: https://go-review.googlesource.com/40300
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Jay Conrod 2017-04-11 15:25:53 -04:00 коммит произвёл Brad Fitzpatrick
Родитель 25abe5b322
Коммит 3bcb6efb39
2 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -157,6 +157,33 @@ Opt *<a href="/pkg/builtin/#int">int</a>
}
}
// Test that we add <span id="ConstName"> elements to the HTML
// of definitions in const and var specs.
func TestValueSpecIDAttributes(t *testing.T) {
got := linkifySource(t, []byte(`
package foo
const (
NoDoc string = "NoDoc"
// Doc has a comment
Doc = "Doc"
NoVal
)`))
want := `const (
<span id="NoDoc">NoDoc</span> <a href="/pkg/builtin/#string">string</a> = &#34;NoDoc&#34;
<span class="comment">// Doc has a comment</span>
<span id="Doc">Doc</span> = &#34;Doc&#34;
<span id="NoVal">NoVal</span>
)`
if got != want {
t.Errorf("got: %s\n\nwant: %s\n", got, want)
}
}
func TestCompositeLitLinkFields(t *testing.T) {
got := linkifySource(t, []byte(`
package foo
@ -169,7 +196,7 @@ var S T = T{X: 12}`))
want := `type T struct {
<span id="T.X"></span>X <a href="/pkg/builtin/#int">int</a>
}
var S <a href="#T">T</a> = <a href="#T">T</a>{<a href="#T.X">X</a>: 12}`
var <span id="S">S</span> <a href="#T">T</a> = <a href="#T">T</a>{<a href="#T.X">X</a>: 12}`
if got != want {
t.Errorf("got: %s\n\nwant: %s\n", got, want)
}

Просмотреть файл

@ -109,7 +109,7 @@ func linksFor(node ast.Node) (links []link) {
}
case *ast.ValueSpec:
for _, n := range n.Names {
linkMap[n] = link{mode: identVal}
linkMap[n] = link{mode: identVal, name: n.Name}
}
case *ast.TypeSpec:
linkMap[n.Name] = link{mode: identDef}