blob: de0ffc0b0230308c4b2b85e1ec5df2c3db04a3a7 [file] [log] [blame]
Austin Clementsc9329452021-01-08 21:03:30 -05001// 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
5package benchfmt
6
7import (
8 "bytes"
9 "strings"
10 "testing"
11)
12
13func TestWriter(t *testing.T) {
14 const input = `BenchmarkOne 1 1 ns/op
Austin Clements96728ec2021-10-21 10:33:54 -040015Unit ns/op a=1
16Unit ns/op b=2
17Unit MB/s c=3
Austin Clementsc9329452021-01-08 21:03:30 -050018
19key: val
20key1: val1
21
22BenchmarkOne 1 1 ns/op
23
24key:
25
26BenchmarkOne 1 1 ns/op
27
28key: a
29
30BenchmarkOne 1 1 ns/op
31
32key1: val2
33key: b
34
35BenchmarkOne 1 1 ns/op
36BenchmarkTwo 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}