Permalink
Browse files

test: TestUnifiedCommentWriter_Post

  • Loading branch information...
1 parent 4a0d893 commit ec0b8a79771746cff8697a1cf0903780af496f87 @haya14busa committed Dec 12, 2016
Showing with 71 additions and 0 deletions.
  1. +71 −0 comment_iowriter_test.go
@@ -0,0 +1,71 @@
+package reviewdog
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+)
+
+func TestUnifiedCommentWriter_Post(t *testing.T) {
+ tests := []struct {
+ in *Comment
+ want string
+ }{
+ {
+ in: &Comment{
+ CheckResult: &CheckResult{
+ Path: "/path/to/file",
+ },
+ ToolName: "tool name",
+ Body: "message",
+ },
+ want: `/path/to/file: [tool name] message`,
+ },
+ {
+ in: &Comment{
+ CheckResult: &CheckResult{
+ Path: "/path/to/file",
+ Col: 14,
+ },
+ ToolName: "tool name",
+ Body: "message",
+ },
+ want: `/path/to/file: [tool name] message`,
+ },
+ {
+ in: &Comment{
+ CheckResult: &CheckResult{
+ Path: "/path/to/file",
+ Lnum: 14,
+ },
+ ToolName: "tool name",
+ Body: "message",
+ },
+ want: `/path/to/file:14: [tool name] message`,
+ },
+ {
+ in: &Comment{
+ CheckResult: &CheckResult{
+ Path: "/path/to/file",
+ Lnum: 14,
+ Col: 7,
+ },
+ ToolName: "tool name",
+ Body: "line1\nline2",
+ },
+ 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(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)
+ }
+ }
+}

0 comments on commit ec0b8a7

Please sign in to comment.