-
Notifications
You must be signed in to change notification settings - Fork 10
/
doc_test.go
81 lines (73 loc) · 1.67 KB
/
doc_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
package bel
import (
"testing"
"github.com/go-test/deep"
)
// InterfaceWithDocumentation has this documentation
type InterfaceWithDocumentation interface {
// DoSomething also has documentation
DoSomething(DoSomethingReq)
}
// DoSomethingReq is a struct with documentation
type DoSomethingReq struct {
// Field has documentation as well
Field string
}
func TestParsedSourceDocHandler(t *testing.T) {
handler, err := NewParsedSourceDocHandler(".", "github.com/32leaves/")
if err != nil {
t.Error(err)
return
}
extract, err := Extract((*InterfaceWithDocumentation)(nil), WithDocumentation(handler), FollowStructs)
if err != nil {
t.Error(err)
return
}
expectation := []TypescriptType{
{
Name: "DoSomethingReq",
Comment: "DoSomethingReq is a struct with documentation",
Kind: TypescriptKind("iface"),
Members: []TypescriptMember{
{
TypedElement: TypedElement{
Name: "Field",
Type: TypescriptType{
Name: "string",
Kind: TypescriptKind("simple"),
},
},
},
},
},
{
Name: "InterfaceWithDocumentation",
Comment: "InterfaceWithDocumentation has this documentation",
Kind: TypescriptKind("iface"),
Members: []TypescriptMember{
{
TypedElement: TypedElement{
Name: "DoSomething",
Type: TypescriptType{},
},
Comment: "DoSomething also has documentation",
IsFunction: true,
Args: []TypedElement{
{
Name: "arg0",
Type: TypescriptType{
Name: "DoSomethingReq",
Kind: TypescriptKind("simple"),
},
},
},
},
},
},
}
diff := deep.Equal(expectation, extract)
for _, d := range diff {
t.Error(d)
}
}