-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testdoc_test.go
126 lines (114 loc) · 2.91 KB
/
testdoc_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package testdoc_test
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
"github.com/Eun/go-testdoc"
"github.com/traefik/yaegi/interp"
)
func test(dir string, includePrivate bool, expectedCalls []string) func(t *testing.T) {
return func(t *testing.T) {
var gotCalls []string
testdoc.TestCodeDocumentation(t, &testdoc.Options{
Path: dir,
PkgName: "test",
Sections: []string{"Example"},
Symbols: []interp.Exports{
map[string]map[string]reflect.Value{
"test": {
"test": reflect.ValueOf(func(caller string) {
gotCalls = append(gotCalls, caller)
}),
},
},
},
Imports: []testdoc.Import{
{
Name: ".",
Path: "test",
},
{
Name: ".",
Path: dir,
},
},
IncludePrivate: includePrivate,
})
require.Equal(t, expectedCalls, gotCalls)
}
}
func TestTestCodeDocumentation(t *testing.T) {
t.Run("package", func(t *testing.T) {
t.Run("public", test("./tests/package", false, []string{
"Package",
}))
t.Run("private", test("./tests/package", true, []string{
"Package",
}))
})
t.Run("func", func(t *testing.T) {
t.Run("public", test("./tests/func", false, []string{
"PublicFunc",
}))
t.Run("private", test("./tests/func", true, []string{
"PublicFunc",
"privateFunc",
}))
})
t.Run("variable", func(t *testing.T) {
t.Run("public", test("./tests/variable", false, []string{
"PublicVariable",
}))
t.Run("private", test("./tests/variable", true, []string{
"PublicVariable",
"privateVariable",
}))
})
t.Run("const", func(t *testing.T) {
t.Run("public", test("./tests/const", false, []string{
"PublicConst",
}))
t.Run("private", test("./tests/const", true, []string{
"PublicConst",
"privateConst",
}))
})
t.Run("struct", func(t *testing.T) {
t.Run("public", test("./tests/struct", false, []string{
"PublicStruct",
"PublicStruct.PublicStructField",
"privateStruct.PublicStructField",
}))
t.Run("private", test("./tests/struct", true, []string{
"PublicStruct",
"PublicStruct.PublicStructField",
"PublicStruct.privateStructField",
"privateStruct",
"privateStruct.PublicStructField",
"privateStruct.privateStructField",
}))
})
t.Run("interface", func(t *testing.T) {
t.Run("public", test("./tests/interface", false, []string{
"PublicInterface",
"PublicInterface.PublicInterfaceMethod",
"privateInterface.PublicInterfaceMethod",
}))
t.Run("private", test("./tests/interface", true, []string{
"PublicInterface",
"PublicInterface.PublicInterfaceMethod",
"PublicInterface.privateInterfaceMethod",
"privateInterface",
"privateInterface.PublicInterfaceMethod",
"privateInterface.privateInterfaceMethod",
}))
})
t.Run("reference", func(t *testing.T) {
t.Run("public", test("./tests/reference", false, []string{
"Reference",
}))
t.Run("private", test("./tests/reference", true, []string{
"Reference",
}))
})
}