github.com/trigonella/golangci-lint@v1.10.1/pkg/golinters/typecheck_test.go (about)

     1  package golinters
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestParseError(t *testing.T) {
    12  	cases := []struct {
    13  		in, out string
    14  		good    bool
    15  	}{
    16  		{"f.go:1:2: text", "", true},
    17  		{"f.go:1:2: text: with: colons", "", true},
    18  
    19  		{"f.go:1:2:text wo leading space", "f.go:1:2: text wo leading space", true},
    20  
    21  		{"f.go:1:2:", "", false},
    22  		{"f.go:1:2: ", "", false},
    23  
    24  		{"f.go:1:2", "f.go:1: 2", true},
    25  		{"f.go:1: text no column", "", true},
    26  		{"f.go:1: text no column: but with colon", "", true},
    27  		{"f.go:1:text no column", "f.go:1: text no column", true},
    28  
    29  		{"f.go: no line", "", false},
    30  		{"f.go: 1: text", "", false},
    31  
    32  		{"f.go:", "", false},
    33  		{"f.go", "", false},
    34  	}
    35  
    36  	lint := TypeCheck{}
    37  	for _, c := range cases {
    38  		i, _ := lint.parseError(errors.New(c.in))
    39  		if !c.good {
    40  			assert.Nil(t, i)
    41  			continue
    42  		}
    43  
    44  		assert.NotNil(t, i)
    45  
    46  		pos := fmt.Sprintf("%s:%d", i.FilePath(), i.Line())
    47  		if i.Pos.Column != 0 {
    48  			pos += fmt.Sprintf(":%d", i.Pos.Column)
    49  		}
    50  		out := fmt.Sprintf("%s: %s", pos, i.Text)
    51  		expOut := c.out
    52  		if expOut == "" {
    53  			expOut = c.in
    54  		}
    55  		assert.Equal(t, expOut, out)
    56  
    57  		assert.Equal(t, "typecheck", i.FromLinter)
    58  	}
    59  }