github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/doc/testdata/pkg.go (about) 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. 6 package pkg 7 8 import "io" 9 10 // Constants 11 12 // Comment about exported constant. 13 const ExportedConstant = 1 14 15 // Comment about internal constant. 16 const internalConstant = 2 17 18 // Comment about block of constants. 19 const ( 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. 27 const ( 28 constFour = iota 29 ConstFive 30 ConstSix 31 ) 32 33 // Variables 34 35 // Comment about exported variable. 36 var ExportedVariable = 1 37 38 var ExportedVarOfUnExported unexportedType 39 40 // Comment about internal variable. 41 var internalVariable = 2 42 43 // Comment about block of variables. 44 var ( 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. 52 var ( 53 varFour = 4 54 VarFive = 5 55 varSix = 6 56 ) 57 58 // Comment about exported function. 59 func ExportedFunc(a int) bool { 60 return true != false 61 } 62 63 // Comment about internal function. 64 func internalFunc(a int) bool 65 66 // Comment about exported type. 67 type ExportedType struct { 68 // Comment before exported field. 69 ExportedField int // Comment on line with exported field. 70 unexportedField int // Comment on line with unexported field. 71 ExportedEmbeddedType // Comment on line with exported embedded field. 72 *ExportedEmbeddedType // Comment on line with exported embedded *field. 73 *qualified.ExportedEmbeddedType // Comment on line with exported embedded *selector.field. 74 unexportedType // Comment on line with unexported embedded field. 75 *unexportedType // Comment on line with unexported embedded *field. 76 io.Reader // Comment on line with embedded Reader. 77 error // Comment on line with embedded error. 78 } 79 80 // Comment about exported method. 81 func (ExportedType) ExportedMethod(a int) bool { 82 return true != true 83 } 84 85 func (ExportedType) Uncommented(a int) bool { 86 return true != true 87 } 88 89 // Comment about unexported method. 90 func (ExportedType) unexportedMethod(a int) bool { 91 return true 92 } 93 94 type ExportedStructOneField struct { 95 OnlyField int // the only field 96 } 97 98 // Constants tied to ExportedType. (The type is a struct so this isn't valid Go, 99 // but it parses and that's all we need.) 100 const ( 101 ExportedTypedConstant ExportedType = iota 102 ) 103 104 // Comment about constructor for exported type. 105 func ExportedTypeConstructor() *ExportedType { 106 return nil 107 } 108 109 const unexportedTypedConstant ExportedType = 1 // In a separate section to test -u. 110 111 // Comment about exported interface. 112 type ExportedInterface interface { 113 // Comment before exported method. 114 ExportedMethod() // Comment on line with exported method. 115 unexportedMethod() // Comment on line with unexported method. 116 io.Reader // Comment on line with embedded Reader. 117 error // Comment on line with embedded error. 118 } 119 120 // Comment about unexported type. 121 type unexportedType int 122 123 func (unexportedType) ExportedMethod() bool { 124 return true 125 } 126 127 func (unexportedType) unexportedMethod() bool { 128 return true 129 } 130 131 // Constants tied to unexportedType. 132 const ( 133 ExportedTypedConstant_unexported unexportedType = iota 134 ) 135 136 const unexportedTypedConstant unexportedType = 1 // In a separate section to test -u. 137 138 // For case matching. 139 const CaseMatch = 1 140 const Casematch = 2 141 142 func ReturnUnexported() unexportedType { return 0 } 143 func ReturnExported() ExportedType { return ExportedType{} } 144 145 const MultiLineConst = ` 146 MultiLineString1 147 MultiLineString2 148 MultiLineString3 149 ` 150 151 func MultiLineFunc(x interface { 152 MultiLineMethod1() int 153 MultiLineMethod2() int 154 MultiLineMethod3() int 155 }) (r struct { 156 MultiLineField1 int 157 MultiLineField2 int 158 MultiLineField3 int 159 }) { 160 return r 161 } 162 163 var MultiLineVar = map[struct { 164 MultiLineField1 string 165 MultiLineField2 uint64 166 }]struct { 167 MultiLineField3 error 168 MultiLineField2 error 169 }{ 170 {"FieldVal1", 1}: {}, 171 {"FieldVal2", 2}: {}, 172 {"FieldVal3", 3}: {}, 173 } 174 175 const ( 176 _, _ uint64 = 2 * iota, 1 << iota 177 constLeft1, constRight1 178 ConstLeft2, constRight2 179 constLeft3, ConstRight3 180 ConstLeft4, ConstRight4 181 ) 182 183 const ( 184 ConstGroup1 unexportedType = iota 185 ConstGroup2 186 ConstGroup3 187 ) 188 189 const ConstGroup4 ExportedType = ExportedType{} 190 191 func newLongLine(ss ...string) 192 193 var LongLine = newLongLine( 194 "someArgument1", 195 "someArgument2", 196 "someArgument3", 197 "someArgument4", 198 "someArgument5", 199 "someArgument6", 200 "someArgument7", 201 "someArgument8", 202 ) 203 204 type T2 int 205 206 type T1 = T2 207 208 const ( 209 Duplicate = iota 210 duplicate 211 ) 212 213 // Comment about exported function with formatting. 214 // 215 // Example 216 // 217 // fmt.Println(FormattedDoc()) 218 // 219 // Text after pre-formatted block. 220 func ExportedFormattedDoc(a int) bool { 221 return true 222 } 223 224 type ExportedFormattedType struct { 225 // Comment before exported field with formatting. 226 // 227 // Example 228 // 229 // a.ExportedField = 123 230 // 231 // Text after pre-formatted block. 232 ExportedField int 233 }