diff --git a/godoc/godoc_test.go b/godoc/godoc_test.go
index 0595a153a..afc31374c 100644
--- a/godoc/godoc_test.go
+++ b/godoc/godoc_test.go
@@ -157,6 +157,33 @@ Opt *int
}
}
+// Test that we add 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 (
+NoDoc string = "NoDoc"
+
+
+Doc = "Doc"
+
+NoVal
+)`
+ 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 {
X int
}
-var S T = T{X: 12}`
+var S T = T{X: 12}`
if got != want {
t.Errorf("got: %s\n\nwant: %s\n", got, want)
}
diff --git a/godoc/linkify.go b/godoc/linkify.go
index 089737079..027205991 100644
--- a/godoc/linkify.go
+++ b/godoc/linkify.go
@@ -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}