github.com/mistwind/reviewdog@v0.0.0-20230322024206-9cfa11856d58/parser/rdjsonl_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestRDJSONLParser(t *testing.T) {
     9  	const sample = `{"source":{"name":"deadcode"},"message":"'unused' is unused","location":{"path":"testdata/main.go","range":{"start":{"line":18,"column":6}}}}
    10  {"source":{"name":"deadcode"},"message":"'unused2' is unused","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}}
    11  {"source":{"name":"errcheck"},"message":"Error return value of 'os.Open' is not checked","location":{"path":"testdata/main.go","range":{"start":{"line":15,"column":9}}}}
    12  {"source":{"name":"ineffassign"},"message":"ineffectual assignment to 'x'","location":{"path":"testdata/main.go","range":{"start":{"line":12,"column":2}}}}
    13  {"source":{"name":"govet"},"message":"printf: Sprintf format %d reads arg #1, but call has 0 args","location":{"path":"testdata/main.go","range":{"start":{"line":13,"column":2}}}}
    14  {"source":{"name":"severity-test"},"message":"severity test (string)","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}, "severity": "WARNING"}
    15  {"source":{"name":"severity-test"},"message":"severity test (number)","location":{"path":"testdata/main.go","range":{"start":{"line":24,"column":6}}}, "severity": "WARNING"}`
    16  	sampleLines := strings.Split(sample, "\n")
    17  	p := NewRDJSONLParser()
    18  	diagnostics, err := p.Parse(strings.NewReader(sample))
    19  	if err != nil {
    20  		t.Error(err)
    21  	}
    22  	for i, d := range diagnostics {
    23  		if got, want := d.GetOriginalOutput(), sampleLines[i]; got != want {
    24  			t.Errorf("%d: got %v, want %v", i, got, want)
    25  		}
    26  	}
    27  }