Skip to content

Commit

Permalink
Don't use b.Run() to make tests work in Go < 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks committed Feb 4, 2017
1 parent b33e7af commit 90de046
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ func TestLineWithPrefix(t *testing.T) {
}
}

func BenchmarkLine(b *testing.B) {
// Benchmark multiple line lengths.
for _, l := range tests {
// Benchmark each input line individually.
b.Run(
fmt.Sprintf("limit%d", l),
func(b *testing.B) {
for i := 0; i < b.N; i++ {
Line(loremIpsums[0], l)
}
},
)
func benchmarkLine(b *testing.B, limit int) {
for i := 0; i < b.N; i++ {
Line(loremIpsums[0], limit)
}
}

func BenchmarkLine0(b *testing.B) { benchmarkLine(b, 0) }
func BenchmarkLine5(b *testing.B) { benchmarkLine(b, 5) }
func BenchmarkLine10(b *testing.B) { benchmarkLine(b, 10) }
func BenchmarkLine25(b *testing.B) { benchmarkLine(b, 25) }
func BenchmarkLine80(b *testing.B) { benchmarkLine(b, 80) }
func BenchmarkLine120(b *testing.B) { benchmarkLine(b, 120) }
func BenchmarkLine500(b *testing.B) { benchmarkLine(b, 500) }

func ExampleLineWithPrefix() {
var loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vulputate quam nibh, et faucibus enim gravida vel. Integer bibendum lectus et erat semper fermentum quis a risus. Fusce dignissim tempus metus non pretium. Nunc sagittis magna nec purus porttitor mollis. Pellentesque feugiat quam eget laoreet aliquet. Donec gravida congue massa, et sollicitudin turpis lacinia a. Fusce non tortor magna. Cras vel finibus tellus."

Expand Down

0 comments on commit 90de046

Please sign in to comment.