-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlinter_test.go
43 lines (38 loc) · 1.34 KB
/
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
package thriftlint
import (
"testing"
"github.com/alecthomas/go-thrift/parser"
"github.com/stretchr/testify/require"
)
func TestCallCheckerValidation(t *testing.T) {
failf := func(*parser.Thrift) {}
require.Panics(t, func() { callChecker(failf, []interface{}{}) })
okf := func(*parser.Thrift) Messages { return nil }
require.NotPanics(t, func() { callChecker(okf, []interface{}{&parser.Thrift{}}) })
}
func TestCallChecker(t *testing.T) {
okfuncs := []interface{}{
func(*parser.Thrift, *parser.Struct, *parser.Field) Messages {
return Messages{}
},
func(*parser.Struct, *parser.Field) Messages { return Messages{} },
func(*parser.Thrift, *parser.Field) Messages { return Messages{} },
func(*parser.Field) Messages { return Messages{} },
func(self interface{}) Messages { return Messages{} },
func(parent, self interface{}) Messages { return Messages{} },
}
ancestors := []interface{}{&parser.Thrift{}, &parser.Struct{}, &parser.Field{}}
for _, okf := range okfuncs {
out := callChecker(okf, ancestors)
require.NotNil(t, out)
}
badfuncs := []interface{}{
func(*parser.Thrift) Messages { return Messages{} },
func(*parser.Struct) Messages { return Messages{} },
func(*parser.Field, *parser.Struct) Messages { return Messages{} },
}
for _, badf := range badfuncs {
out := callChecker(badf, ancestors)
require.Nil(t, out)
}
}