1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:54:44 -07:00
go/godoc/godoc17_test.go
Robert Griesemer 7e08f6711b godoc: run TestStructField for Go 1.7 and up only (fix build)
There's no testing.T.Run method in Go 1.6.

Change-Id: I0ed7bdbe91d4cc4406ad5626dbae9acc42b4853a
Reviewed-on: https://go-review.googlesource.com/36119
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-02-01 22:56:31 +00:00

36 lines
962 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")
linkifyStructFields(t, buf.Bytes())
})
}
}