-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs_test.go
76 lines (69 loc) · 1.21 KB
/
funcs_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package nit_test
import (
"go/ast"
"go/token"
"testing"
"github.com/MarioCarrion/nit"
)
//nolint:dupl
func TestFuncsValidator_Validate(t *testing.T) {
tests := [...]struct {
name string
filename string
expectedError bool
}{
{
"OK",
"funcs_valid.go",
false,
},
{
"OK: grouped",
"funcs_group.go",
false,
},
{
"OK: sorted",
"funcs_sorted_ok.go",
false,
},
{
"Error: sorted",
"funcs_sorted.go",
true,
},
{
"Error: grouped",
"funcs_group_error.go",
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(ts *testing.T) {
var (
err error
f *ast.File
fset *token.FileSet
)
f, fset = newParserFile(ts, tt.filename)
if err != nil {
ts.Fatalf("expected no error, got %s", err)
}
comments := nit.NewBreakComments(fset, f.Comments)
validator := nit.NewFuncsValidator(comments)
for _, s := range f.Decls {
switch g := s.(type) {
case *ast.FuncDecl:
if g.Recv == nil {
if err = validator.Validate(g, fset); err != nil {
break
}
}
}
}
if tt.expectedError != (err != nil) {
ts.Fatalf("expected error %t, got %s", tt.expectedError, err)
}
})
}
}