github.com/bgpat/reviewdog@v0.0.0-20230909064023-077e44ca1f66/parser/parser_test.go (about) 1 package parser 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestNewParser(t *testing.T) { 9 tests := []struct { 10 in *Option 11 typ Parser 12 wantErr bool 13 }{ 14 { 15 in: &Option{ 16 FormatName: "checkstyle", 17 }, 18 typ: &CheckStyleParser{}, 19 }, 20 { 21 in: &Option{ 22 FormatName: "rdjsonl", 23 }, 24 typ: &RDJSONLParser{}, 25 }, 26 { 27 in: &Option{ 28 FormatName: "golint", 29 }, 30 typ: &ErrorformatParser{}, 31 }, 32 { 33 in: &Option{ 34 Errorformat: []string{`%f:%l:%c:%m`}, 35 }, 36 typ: &ErrorformatParser{}, 37 }, 38 { 39 in: &Option{ 40 FormatName: "sarif", 41 }, 42 typ: &SarifParser{}, 43 }, 44 { // empty 45 in: &Option{}, 46 wantErr: true, 47 }, 48 { // both 49 in: &Option{ 50 FormatName: "checkstyle", 51 Errorformat: []string{`%f:%l:%c:%m`}, 52 }, 53 wantErr: true, 54 }, 55 { // unsupported 56 in: &Option{ 57 FormatName: "unsupported format", 58 }, 59 wantErr: true, 60 }, 61 } 62 for _, tt := range tests { 63 p, err := New(tt.in) 64 if tt.wantErr && err != nil { 65 continue 66 } 67 if err != nil { 68 t.Error(err) 69 continue 70 } 71 if got, want := reflect.TypeOf(p), reflect.TypeOf(tt.typ); got != want { 72 t.Errorf("typ: got %v, want %v", got, want) 73 } 74 } 75 }