forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinter_test.go
48 lines (41 loc) · 805 Bytes
/
linter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package goanalysis
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/tools/go/packages"
)
func TestParseError(t *testing.T) {
cases := []struct {
in, out string
good bool
}{
{"f.go:1:2", "", true},
{"f.go:1", "", true},
{"f.go", "", false},
{"f.go: 1", "", false},
}
for _, c := range cases {
i, _ := parseError(packages.Error{
Pos: c.in,
Msg: "msg",
})
if !c.good {
assert.Nil(t, i)
continue
}
assert.NotNil(t, i)
pos := fmt.Sprintf("%s:%d", i.FilePath(), i.Line())
if i.Pos.Column != 0 {
pos += fmt.Sprintf(":%d", i.Pos.Column)
}
out := pos
expOut := c.out
if expOut == "" {
expOut = c.in
}
assert.Equal(t, expOut, out)
assert.Equal(t, "typecheck", i.FromLinter)
assert.Equal(t, "msg", i.Text)
}
}