1 package main
2
3 import (
4 "reflect"
5 "testing"
6
7 "golang.org/x/tools/cover"
8 )
9
10 func TestMergeProfs(t *testing.T) {
11 tests := []struct {
12 in [][]*cover.Profile
13 want []*cover.Profile
14 }{
15
16 {in: nil, want: nil},
17
18 {in: [][]*cover.Profile{{{FileName: "name1"}}}, want: []*cover.Profile{{FileName: "name1"}}},
19
20 {
21 in: [][]*cover.Profile{
22 {},
23 {
24 {
25 FileName: "name1",
26 Blocks: []cover.ProfileBlock{
27 {StartLine: 1, StartCol: 1, Count: 1},
28 },
29 },
30 {
31 FileName: "name2",
32 Blocks: []cover.ProfileBlock{
33 {StartLine: 1, StartCol: 1, Count: 0},
34 },
35 },
36 },
37 {},
38 {
39 {
40 FileName: "name1",
41 Blocks: []cover.ProfileBlock{
42 {StartLine: 1, StartCol: 1, Count: 1},
43 },
44 },
45 {
46 FileName: "name2",
47 Blocks: []cover.ProfileBlock{
48 {StartLine: 1, StartCol: 1, Count: 1},
49 },
50 },
51 },
52 },
53 want: []*cover.Profile{
54 {
55 FileName: "name1",
56 Blocks: []cover.ProfileBlock{
57 {StartLine: 1, StartCol: 1, Count: 2},
58 },
59 },
60 {
61 FileName: "name2",
62 Blocks: []cover.ProfileBlock{
63 {StartLine: 1, StartCol: 1, Count: 1},
64 },
65 },
66 },
67 },
68 }
69
70 for _, tt := range tests {
71 if got := mergeProfs(tt.in); !reflect.DeepEqual(got, tt.want) {
72 t.Errorf("mergeProfs(%#v) = %#v, want %#v", tt.in, got, tt.want)
73 }
74 }
75 }
76
View as plain text