github.com/haya14busa/reviewdog@v0.0.0-20180723114510-ffb00ef78fd3/comment_iowriter_test.go (about) 1 package reviewdog 2 3 import ( 4 "bytes" 5 "context" 6 "strings" 7 "testing" 8 ) 9 10 func TestUnifiedCommentWriter_Post(t *testing.T) { 11 tests := []struct { 12 in *Comment 13 want string 14 }{ 15 { 16 in: &Comment{ 17 CheckResult: &CheckResult{ 18 Path: "/path/to/file", 19 }, 20 ToolName: "tool name", 21 Body: "message", 22 }, 23 want: `/path/to/file: [tool name] message`, 24 }, 25 { 26 in: &Comment{ 27 CheckResult: &CheckResult{ 28 Path: "/path/to/file", 29 Col: 14, 30 }, 31 ToolName: "tool name", 32 Body: "message", 33 }, 34 want: `/path/to/file: [tool name] message`, 35 }, 36 { 37 in: &Comment{ 38 CheckResult: &CheckResult{ 39 Path: "/path/to/file", 40 Lnum: 14, 41 }, 42 ToolName: "tool name", 43 Body: "message", 44 }, 45 want: `/path/to/file:14: [tool name] message`, 46 }, 47 { 48 in: &Comment{ 49 CheckResult: &CheckResult{ 50 Path: "/path/to/file", 51 Lnum: 14, 52 Col: 7, 53 }, 54 ToolName: "tool name", 55 Body: "line1\nline2", 56 }, 57 want: `/path/to/file:14:7: [tool name] line1 58 line2`, 59 }, 60 } 61 for _, tt := range tests { 62 buf := new(bytes.Buffer) 63 mc := NewUnifiedCommentWriter(buf) 64 if err := mc.Post(context.Background(), tt.in); err != nil { 65 t.Error(err) 66 continue 67 } 68 if got := strings.Trim(buf.String(), "\n"); got != tt.want { 69 t.Errorf("UnifiedCommentWriter_Post(%v) = \n%v\nwant:\n%v", tt.in, got, tt.want) 70 } 71 } 72 }