gitee.com/lonely0422/gometalinter.git@v3.0.1-0.20190307123442-32416ab75314+incompatible/directives_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestIgnoreRangeMatch(t *testing.T) {
    10  	var testcases = []struct {
    11  		doc      string
    12  		issue    Issue
    13  		linters  []string
    14  		expected bool
    15  	}{
    16  		{
    17  			doc:   "unmatched line",
    18  			issue: Issue{Line: 100},
    19  		},
    20  		{
    21  			doc:      "matched line, all linters",
    22  			issue:    Issue{Line: 5},
    23  			expected: true,
    24  		},
    25  		{
    26  			doc:     "matched line, unmatched linter",
    27  			issue:   Issue{Line: 5},
    28  			linters: []string{"vet"},
    29  		},
    30  		{
    31  			doc:      "matched line and linters",
    32  			issue:    Issue{Line: 20, Linter: "vet"},
    33  			linters:  []string{"vet"},
    34  			expected: true,
    35  		},
    36  	}
    37  
    38  	for _, testcase := range testcases {
    39  		ir := ignoredRange{col: 20, start: 5, end: 20, linters: testcase.linters}
    40  		assert.Equal(t, testcase.expected, ir.matches(&testcase.issue), testcase.doc)
    41  	}
    42  }