-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgodoc_test.go
143 lines (118 loc) · 3.71 KB
/
godoc_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ackage should trigger TestGoDocPackageReject
package main
import (
"testing"
)
type docCheck struct {
ct []*CheckedLexeme
}
func (dc *docCheck) get(t *testing.T, path string) *docCheck {
if len(dc.ct) == 0 {
cts, err := CheckAll([]string{path})
if err != nil {
t.Fatal(err)
}
dc.ct = cts
}
return dc
}
// this will trigger a warning that TestGoDocNoFuncNameReject isn't the function name
func TestGoDocNoFuncNameReject(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocNoFuncNameReject")
}
// TestGoDocNoFuncNameReject has the wrong name; want TestGoDocWrongFuncNameReject.
func TestGoDocWrongFuncNameReject(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocWrongFuncNameReject")
}
// this will trigger TestGoDocNoTypeNameReject
type godocStructReject struct {
// this will trigger TestGoDocNoFieldNameReject
oopsie int
// okthough will pass TestGoDocFieldNamePass
okthough int
}
// TestGoDocNoTypeNameReject rejects a type missing name in comments
func TestGoDocNoTypeNameReject(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocNoFuncNameReject")
}
// TestGoDocNoFieldNameReject rejects a field missing name in comments
func TestGoDocNoFieldNameReject(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocNoFieldNameReject")
}
// TestGoDocFieldNamePass accepts a godoc of a field
func TestGoDocFieldNamePass(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocFieldNamePass")
}
// TestGoDocFuncPass will not trigger a warning
func TestGoDocFuncPass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocFuncPass")
}
// TestGoDocMultiLinePass should pass
// even though this is a multiple line comment
func TestGoDocMultiLinePass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocMultiLinePass")
}
// this comment not part of the function documentation
// TestGoDocCommentBreakPass will not trigger a warning
func TestGoDocCommentBreakPass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocCommentBreak")
}
type godocSideComment struct {
sideComment int // a side comment isn't a godoc
unrelated int
}
func TestGoDocSideCommentPass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocSideCommentPass")
}
// TestGoDocSkipLinesPass will not trigger a warning
//
// even though there are multiple lines
// that could
//
// break the checker's
// ability to parse
func TestGoDocSkipLinesPass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocSkipLinesPass")
}
// it's OK not to match TestGoDocSkipAndMissingPass since blank below
func TestGoDocSkipAndMissingPass(t *testing.T) {
accept(t, "godoc_test.go", "TestGoDocSkipAndMissingPass")
}
type hello interface {
// this should trigger TestInterfaceFuncReject
f() int
}
func TestInterfaceFuncReject(t *testing.T) {
reject(t, "godoc_test.go", "TestInterfaceFuncReject")
}
type morestruct struct {
// this should trigger TestStructFieldReject
hello int
// this should trigger TestStructFieldPtrReject
hello2 *int
// this should trigger TestStructFieldChanReject
hello3 chan int
// this should trigger TestStructFieldRChanReject
hello4 <-chan int
}
func TestStructFieldReject(t *testing.T) {
reject(t, "godoc_test.go", "TestStructFieldReject")
}
func TestStructFieldPtrReject(t *testing.T) {
reject(t, "godoc_test.go", "TestStructFieldPtrReject")
}
func TestStructFieldChanReject(t *testing.T) {
reject(t, "godoc_test.go", "TestStructFieldChanReject")
}
func TestStructFieldRChanReject(t *testing.T) {
reject(t, "godoc_test.go", "TestStructFieldRChanReject")
}
func TestGoDocPackageReject(t *testing.T) {
reject(t, "godoc_test.go", "TestGoDocPackageReject")
}
func TestGoDocPackageNameReject(t *testing.T) {
reject(t, "util_test.go", "TestGoDocPackageNameReject")
}
func TestGoDocPackageMain(t *testing.T) {
accept(t, "goword.go", "TestGoDocPackageMain")
}