github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/report/reporters/tscReporter_test.go (about) 1 package reporters_test 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/yoheimuta/protolint/internal/linter/report/reporters" 8 9 "github.com/yoheimuta/go-protoparser/v4/parser/meta" 10 11 "github.com/yoheimuta/protolint/linter/report" 12 ) 13 14 func TestTscReporter_Report(t *testing.T) { 15 tests := []struct { 16 name string 17 inputFailures []report.Failure 18 wantOutput string 19 }{ 20 { 21 name: "Prints failures in the plain format", 22 inputFailures: []report.Failure{ 23 report.FailureWithSeverityf( 24 meta.Position{ 25 Filename: "example.proto", 26 Offset: 100, 27 Line: 5, 28 Column: 10, 29 }, 30 "ENUM_NAMES_UPPER_CAMEL_CASE", 31 "error", 32 `EnumField name "fIRST_VALUE" must be CAPITALS_WITH_UNDERSCORES`, 33 ), 34 report.FailureWithSeverityf( 35 meta.Position{ 36 Filename: "example.proto", 37 Offset: 200, 38 Line: 10, 39 Column: 20, 40 }, 41 "ENUM_NAMES_UPPER_CAMEL_CASE", 42 "warning", 43 `EnumField name "SECOND.VALUE" must be CAPITALS_WITH_UNDERSCORES`, 44 ), 45 }, 46 wantOutput: `example.proto(5,10): error ENUM_NAMES_UPPER_CAMEL_CASE: 'EnumField name "fIRST_VALUE" must be CAPITALS_WITH_UNDERSCORES' 47 example.proto(10,20): warning ENUM_NAMES_UPPER_CAMEL_CASE: 'EnumField name "SECOND.VALUE" must be CAPITALS_WITH_UNDERSCORES' 48 `, 49 }, 50 } 51 52 for _, test := range tests { 53 test := test 54 t.Run(test.name, func(t *testing.T) { 55 buf := &bytes.Buffer{} 56 err := reporters.TscReporter{}.Report(buf, test.inputFailures) 57 if err != nil { 58 t.Errorf("got err %v, but want nil", err) 59 return 60 } 61 if buf.String() != test.wantOutput { 62 t.Errorf("got %s, but want %s", buf.String(), test.wantOutput) 63 } 64 }) 65 } 66 }