-
Notifications
You must be signed in to change notification settings - Fork 11
/
ast_test.go
59 lines (51 loc) · 1.05 KB
/
ast_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
package main
import (
"reflect"
"testing"
)
const testGolangSrc = `package somepkg
import "fmt"
type T int
func (r T) String() string {
return fmt.Sprintf("%v", r)
}
func fn() string {
return "Hello"
}
`
func Test_getGolangFuncs(t *testing.T) {
tests := []struct {
name string
fileContent []byte
wantResult []Func
wantErr bool
}{
{
name: "without error",
fileContent: []byte(testGolangSrc),
wantResult: []Func{
{Name: "String", Begin: 44, End: 103},
{Name: "fn", Begin: 105, End: 141},
},
wantErr: false,
},
{
name: "with error",
fileContent: []byte("..."),
wantResult: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotResult, err := getGolangFuncs(tt.fileContent)
if (err != nil) != tt.wantErr {
t.Errorf("getGolangFuncs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotResult, tt.wantResult) {
t.Errorf("getGolangFuncs() = %#v, want %#v", gotResult, tt.wantResult)
}
})
}
}