1
0
mirror of https://github.com/golang/go synced 2024-11-05 20:26:13 -07:00
go/godoc/godoc17_test.go
Jay Conrod e1bdc76d04 x/tools/cmd/godoc: fix broken links in composite literals
Previously, field names in composite literals were treated as normal
identifiers. For example, in Foo{X: 42}, X was treated link a normal
variable and was linked to "#X".

With this change, field links now include a prefix for their type
definition, for example, "#Foo.X".

Fixes golang/go#16031

Change-Id: I9cb501704f284fbbc05424555312307c61843e47
Reviewed-on: https://go-review.googlesource.com/36830
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2017-02-17 22:21:49 +00:00

36 lines
956 B
Go

// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.7
package godoc
import (
"bytes"
"fmt"
"testing"
)
// Verify that scanIdentifier isn't quadratic.
// This doesn't actually measure and fail on its own, but it was previously
// very obvious when running by hand.
//
// TODO: if there's a reliable and non-flaky way to test this, do so.
// Maybe count user CPU time instead of wall time? But that's not easy
// to do portably in Go.
func TestStructField(t *testing.T) {
for _, n := range []int{10, 100, 1000, 10000} {
n := n
t.Run(fmt.Sprint(n), func(t *testing.T) {
var buf bytes.Buffer
fmt.Fprintf(&buf, "package foo\n\ntype T struct {\n")
for i := 0; i < n; i++ {
fmt.Fprintf(&buf, "\t// Field%d is foo.\n\tField%d int\n\n", i, i)
}
fmt.Fprintf(&buf, "}\n")
linkifySource(t, buf.Bytes())
})
}
}