-
Notifications
You must be signed in to change notification settings - Fork 5
/
parseref_test.go
83 lines (80 loc) · 1.58 KB
/
parseref_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
77
78
79
80
81
82
83
package requestgen
import "testing"
func TestParseTypeSelector(t *testing.T) {
type args struct {
main string
}
tests := []struct {
name string
args args
wantErr bool
wantSpec TypeSelector
}{
{
name: "full-qualified",
args: args{
main: `"github.com/c9s/requestgen".APIClient`,
},
wantErr: false,
wantSpec: TypeSelector{
Package: "github.com/c9s/requestgen",
Member: "APIClient",
},
},
{
name: "cwd",
args: args{
main: `".".APIClient`,
},
wantErr: false,
wantSpec: TypeSelector{
Package: "github.com/c9s/requestgen",
Member: "APIClient",
},
},
{
name: "slice",
args: args{
main: `[]APIClient`,
},
wantErr: false,
wantSpec: TypeSelector{
Package: "github.com/c9s/requestgen",
Member: "APIClient",
IsSlice: true,
},
},
{
name: "ident",
args: args{
main: `APIClient`,
},
wantErr: false,
wantSpec: TypeSelector{
Package: "github.com/c9s/requestgen",
Member: "APIClient",
},
},
{
name: "single dot",
args: args{
main: `.APIClient`,
},
wantErr: false,
wantSpec: TypeSelector{
Package: "github.com/c9s/requestgen",
Member: "APIClient",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
spec, err := ParseTypeSelector(tt.args.main)
if (err != nil) != tt.wantErr {
t.Errorf("ParseTypeSelector() error = %v, wantErr %v", err, tt.wantErr)
} else if spec != nil && *spec != tt.wantSpec {
t.Errorf("ParseTypeSelector() TypeSelector = %+v, wantSpec %+v", spec, tt.wantSpec)
}
})
}
}