github.com/alecthomas/gometalinter@v3.0.1-0.20190307123442-32416ab75314+incompatible/issue_test.go (about) 1 package main 2 3 import ( 4 "sort" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestSortedIssues(t *testing.T) { 12 actual := []*Issue{ 13 {Path: newIssuePath("", "b.go"), Line: 5, Col: 1}, 14 {Path: newIssuePath("", "a.go"), Line: 3, Col: 2}, 15 {Path: newIssuePath("", "b.go"), Line: 1, Col: 3}, 16 {Path: newIssuePath("", "a.go"), Line: 1, Col: 4}, 17 } 18 issues := &sortedIssues{ 19 issues: actual, 20 order: []string{"path", "line", "column"}, 21 } 22 sort.Sort(issues) 23 expected := []*Issue{ 24 {Path: newIssuePath("", "a.go"), Line: 1, Col: 4}, 25 {Path: newIssuePath("", "a.go"), Line: 3, Col: 2}, 26 {Path: newIssuePath( "", "b.go"), Line: 1, Col: 3}, 27 {Path: newIssuePath( "", "b.go"), Line: 5, Col: 1}, 28 } 29 require.Equal(t, expected, actual) 30 } 31 32 func TestCompareOrderWithMessage(t *testing.T) { 33 order := []string{"path", "line", "column", "message"} 34 issueM := Issue{Path: newIssuePath("", "file.go"), Message: "message"} 35 issueU := Issue{Path: newIssuePath("", "file.go"), Message: "unknown"} 36 37 assert.True(t, CompareIssue(issueM, issueU, order)) 38 assert.False(t, CompareIssue(issueU, issueM, order)) 39 }