forked from reviewdog/reviewdog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment_iowriter_test.go
95 lines (92 loc) · 1.98 KB
/
comment_iowriter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package reviewdog
import (
"bytes"
"context"
"strings"
"testing"
"github.com/reviewdog/reviewdog/filter"
"github.com/reviewdog/reviewdog/proto/rdf"
)
func TestUnifiedCommentWriter_Post(t *testing.T) {
tests := []struct {
in *Comment
want string
}{
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{Path: "/path/to/file"},
Message: "message",
},
},
ToolName: "tool name",
},
want: `/path/to/file: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Column: 14,
}},
},
Message: "message",
},
},
ToolName: "tool name",
},
want: `/path/to/file: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
}},
},
Message: "message",
},
},
ToolName: "tool name",
},
want: `/path/to/file:14: [tool name] message`,
},
{
in: &Comment{
Result: &filter.FilteredDiagnostic{
Diagnostic: &rdf.Diagnostic{
Location: &rdf.Location{
Path: "/path/to/file",
Range: &rdf.Range{Start: &rdf.Position{
Line: 14,
Column: 7,
}},
},
Message: "line1\nline2",
},
},
ToolName: "tool name",
},
want: `/path/to/file:14:7: [tool name] line1
line2`,
},
}
for _, tt := range tests {
buf := new(bytes.Buffer)
mc := NewUnifiedCommentWriter(buf)
if err := mc.Post(context.Background(), tt.in); err != nil {
t.Error(err)
continue
}
if got := strings.Trim(buf.String(), "\n"); got != tt.want {
t.Errorf("UnifiedCommentWriter_Post(%v) = \n%v\nwant:\n%v", tt.in, got, tt.want)
}
}
}