You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
956 B

  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. // +build go1.7
  5. package godoc
  6. import (
  7. "bytes"
  8. "fmt"
  9. "testing"
  10. )
  11. // Verify that scanIdentifier isn't quadratic.
  12. // This doesn't actually measure and fail on its own, but it was previously
  13. // very obvious when running by hand.
  14. //
  15. // TODO: if there's a reliable and non-flaky way to test this, do so.
  16. // Maybe count user CPU time instead of wall time? But that's not easy
  17. // to do portably in Go.
  18. func TestStructField(t *testing.T) {
  19. for _, n := range []int{10, 100, 1000, 10000} {
  20. n := n
  21. t.Run(fmt.Sprint(n), func(t *testing.T) {
  22. var buf bytes.Buffer
  23. fmt.Fprintf(&buf, "package foo\n\ntype T struct {\n")
  24. for i := 0; i < n; i++ {
  25. fmt.Fprintf(&buf, "\t// Field%d is foo.\n\tField%d int\n\n", i, i)
  26. }
  27. fmt.Fprintf(&buf, "}\n")
  28. linkifySource(t, buf.Bytes())
  29. })
  30. }
  31. }