golang.org/x/tools@v0.21.0/godoc/godoc17_test.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.7
     6  // +build go1.7
     7  
     8  package godoc
     9  
    10  import (
    11  	"bytes"
    12  	"fmt"
    13  	"testing"
    14  )
    15  
    16  // Verify that scanIdentifier isn't quadratic.
    17  // This doesn't actually measure and fail on its own, but it was previously
    18  // very obvious when running by hand.
    19  //
    20  // TODO: if there's a reliable and non-flaky way to test this, do so.
    21  // Maybe count user CPU time instead of wall time? But that's not easy
    22  // to do portably in Go.
    23  func TestStructField(t *testing.T) {
    24  	for _, n := range []int{10, 100, 1000, 10000} {
    25  		n := n
    26  		t.Run(fmt.Sprint(n), func(t *testing.T) {
    27  			var buf bytes.Buffer
    28  			fmt.Fprintf(&buf, "package foo\n\ntype T struct {\n")
    29  			for i := 0; i < n; i++ {
    30  				fmt.Fprintf(&buf, "\t// Field%d is foo.\n\tField%d int\n\n", i, i)
    31  			}
    32  			fmt.Fprintf(&buf, "}\n")
    33  			linkifySource(t, buf.Bytes())
    34  		})
    35  	}
    36  }