1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package comment.
6package pkg
7
8import "io"
9
10// Constants
11
12// Comment about exported constant.
13const ExportedConstant = 1
14
15// Comment about internal constant.
16const internalConstant = 2
17
18// Comment about block of constants.
19const (
20	// Comment before ConstOne.
21	ConstOne   = 1
22	ConstTwo   = 2 // Comment on line with ConstTwo.
23	constThree = 3 // Comment on line with constThree.
24)
25
26// Const block where first entry is unexported.
27const (
28	constFour = iota
29	ConstFive
30	ConstSix
31)
32
33// Variables
34
35// Comment about exported variable.
36var ExportedVariable = 1
37
38var ExportedVarOfUnExported unexportedType
39
40// Comment about internal variable.
41var internalVariable = 2
42
43// Comment about block of variables.
44var (
45	// Comment before VarOne.
46	VarOne   = 1
47	VarTwo   = 2 // Comment on line with VarTwo.
48	varThree = 3 // Comment on line with varThree.
49)
50
51// Var block where first entry is unexported.
52var (
53	varFour = 4
54	VarFive = 5
55	varSix  = 6
56)
57
58// Comment about exported function.
59func ExportedFunc(a int) bool {
60	// BUG(me): function body note
61	return true != false
62}
63
64// Comment about internal function.
65func internalFunc(a int) bool
66
67// Comment about exported type.
68type ExportedType struct {
69	// Comment before exported field.
70	ExportedField                   int // Comment on line with exported field.
71	unexportedField                 int // Comment on line with unexported field.
72	ExportedEmbeddedType                // Comment on line with exported embedded field.
73	*ExportedEmbeddedType               // Comment on line with exported embedded *field.
74	*qualified.ExportedEmbeddedType     // Comment on line with exported embedded *selector.field.
75	unexportedType                      // Comment on line with unexported embedded field.
76	*unexportedType                     // Comment on line with unexported embedded *field.
77	io.Reader                           // Comment on line with embedded Reader.
78	error                               // Comment on line with embedded error.
79}
80
81// Comment about exported method.
82func (ExportedType) ExportedMethod(a int) bool {
83	return true != true
84}
85
86func (ExportedType) Uncommented(a int) bool {
87	return true != true
88}
89
90// Comment about unexported method.
91func (ExportedType) unexportedMethod(a int) bool {
92	return true
93}
94
95type ExportedStructOneField struct {
96	OnlyField int // the only field
97}
98
99// Constants tied to ExportedType. (The type is a struct so this isn't valid Go,
100// but it parses and that's all we need.)
101const (
102	ExportedTypedConstant ExportedType = iota
103)
104
105// Comment about constructor for exported type.
106func ExportedTypeConstructor() *ExportedType {
107	return nil
108}
109
110const unexportedTypedConstant ExportedType = 1 // In a separate section to test -u.
111
112// Comment about exported interface.
113type ExportedInterface interface {
114	// Comment before exported method.
115	//
116	//	// Code block showing how to use ExportedMethod
117	//	func DoSomething() error {
118	//		ExportedMethod()
119	//		return nil
120	//	}
121	//
122	ExportedMethod()   // Comment on line with exported method.
123	unexportedMethod() // Comment on line with unexported method.
124	io.Reader          // Comment on line with embedded Reader.
125	error              // Comment on line with embedded error.
126}
127
128// Comment about unexported type.
129type unexportedType int
130
131func (unexportedType) ExportedMethod() bool {
132	return true
133}
134
135func (unexportedType) unexportedMethod() bool {
136	return true
137}
138
139// Constants tied to unexportedType.
140const (
141	ExportedTypedConstant_unexported unexportedType = iota
142)
143
144const unexportedTypedConstant unexportedType = 1 // In a separate section to test -u.
145
146// For case matching.
147const CaseMatch = 1
148const Casematch = 2
149
150func ReturnUnexported() unexportedType { return 0 }
151func ReturnExported() ExportedType     { return ExportedType{} }
152
153const MultiLineConst = `
154	MultiLineString1
155	MultiLineString2
156	MultiLineString3
157`
158
159func MultiLineFunc(x interface {
160	MultiLineMethod1() int
161	MultiLineMethod2() int
162	MultiLineMethod3() int
163}) (r struct {
164	MultiLineField1 int
165	MultiLineField2 int
166	MultiLineField3 int
167}) {
168	return r
169}
170
171var MultiLineVar = map[struct {
172	MultiLineField1 string
173	MultiLineField2 uint64
174}]struct {
175	MultiLineField3 error
176	MultiLineField2 error
177}{
178	{"FieldVal1", 1}: {},
179	{"FieldVal2", 2}: {},
180	{"FieldVal3", 3}: {},
181}
182
183const (
184	_, _ uint64 = 2 * iota, 1 << iota
185	constLeft1, constRight1
186	ConstLeft2, constRight2
187	constLeft3, ConstRight3
188	ConstLeft4, ConstRight4
189)
190
191const (
192	ConstGroup1 unexportedType = iota
193	ConstGroup2
194	ConstGroup3
195)
196
197const ConstGroup4 ExportedType = ExportedType{}
198
199func newLongLine(ss ...string)
200
201var LongLine = newLongLine(
202	"someArgument1",
203	"someArgument2",
204	"someArgument3",
205	"someArgument4",
206	"someArgument5",
207	"someArgument6",
208	"someArgument7",
209	"someArgument8",
210)
211
212type T2 int
213
214type T1 = T2
215
216const (
217	Duplicate = iota
218	duplicate
219)
220
221// Comment about exported function with formatting.
222//
223// Example
224//
225//	fmt.Println(FormattedDoc())
226//
227// Text after pre-formatted block.
228func ExportedFormattedDoc(a int) bool {
229	return true
230}
231
232type ExportedFormattedType struct {
233	// Comment before exported field with formatting.
234	//
235	// Example
236	//
237	//	a.ExportedField = 123
238	//
239	// Text after pre-formatted block.
240	//ignore:directive
241	ExportedField int
242}
243
244type SimpleConstraint interface {
245	~int | ~float64
246}
247
248type TildeConstraint interface {
249	~int
250}
251
252type StructConstraint interface {
253	struct { F int }
254}
255