Austin Clements | c932945 | 2021-01-08 21:03:30 -0500 | [diff] [blame] | 1 | // Copyright 2022 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 | package benchfmt |
| 6 | |
| 7 | import ( |
| 8 | "bytes" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | func TestWriter(t *testing.T) { |
| 14 | const input = `BenchmarkOne 1 1 ns/op |
Austin Clements | 96728ec | 2021-10-21 10:33:54 -0400 | [diff] [blame] | 15 | Unit ns/op a=1 |
| 16 | Unit ns/op b=2 |
| 17 | Unit MB/s c=3 |
Austin Clements | c932945 | 2021-01-08 21:03:30 -0500 | [diff] [blame] | 18 | |
| 19 | key: val |
| 20 | key1: val1 |
| 21 | |
| 22 | BenchmarkOne 1 1 ns/op |
| 23 | |
| 24 | key: |
| 25 | |
| 26 | BenchmarkOne 1 1 ns/op |
| 27 | |
| 28 | key: a |
| 29 | |
| 30 | BenchmarkOne 1 1 ns/op |
| 31 | |
| 32 | key1: val2 |
| 33 | key: b |
| 34 | |
| 35 | BenchmarkOne 1 1 ns/op |
| 36 | BenchmarkTwo 1 1 no-tidy-B/op |
| 37 | ` |
| 38 | |
| 39 | out := new(strings.Builder) |
| 40 | w := NewWriter(out) |
| 41 | r := NewReader(bytes.NewReader([]byte(input)), "test") |
| 42 | for r.Scan() { |
| 43 | if err := w.Write(r.Result()); err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if out.String() != input { |
| 49 | t.Fatalf("want:\n%sgot:\n%s", input, out.String()) |
| 50 | } |
| 51 | } |