Source file src/cmd/doc/testdata/pkg.go

     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  	//
   115  	//	// Code block showing how to use ExportedMethod
   116  	//	func DoSomething() error {
   117  	//		ExportedMethod()
   118  	//		return nil
   119  	//	}
   120  	//
   121  	ExportedMethod()   // Comment on line with exported method.
   122  	unexportedMethod() // Comment on line with unexported method.
   123  	io.Reader          // Comment on line with embedded Reader.
   124  	error              // Comment on line with embedded error.
   125  }
   126  
   127  // Comment about unexported type.
   128  type unexportedType int
   129  
   130  func (unexportedType) ExportedMethod() bool {
   131  	return true
   132  }
   133  
   134  func (unexportedType) unexportedMethod() bool {
   135  	return true
   136  }
   137  
   138  // Constants tied to unexportedType.
   139  const (
   140  	ExportedTypedConstant_unexported unexportedType = iota
   141  )
   142  
   143  const unexportedTypedConstant unexportedType = 1 // In a separate section to test -u.
   144  
   145  // For case matching.
   146  const CaseMatch = 1
   147  const Casematch = 2
   148  
   149  func ReturnUnexported() unexportedType { return 0 }
   150  func ReturnExported() ExportedType     { return ExportedType{} }
   151  
   152  const MultiLineConst = `
   153  	MultiLineString1
   154  	MultiLineString2
   155  	MultiLineString3
   156  `
   157  
   158  func MultiLineFunc(x interface {
   159  	MultiLineMethod1() int
   160  	MultiLineMethod2() int
   161  	MultiLineMethod3() int
   162  }) (r struct {
   163  	MultiLineField1 int
   164  	MultiLineField2 int
   165  	MultiLineField3 int
   166  }) {
   167  	return r
   168  }
   169  
   170  var MultiLineVar = map[struct {
   171  	MultiLineField1 string
   172  	MultiLineField2 uint64
   173  }]struct {
   174  	MultiLineField3 error
   175  	MultiLineField2 error
   176  }{
   177  	{"FieldVal1", 1}: {},
   178  	{"FieldVal2", 2}: {},
   179  	{"FieldVal3", 3}: {},
   180  }
   181  
   182  const (
   183  	_, _ uint64 = 2 * iota, 1 << iota
   184  	constLeft1, constRight1
   185  	ConstLeft2, constRight2
   186  	constLeft3, ConstRight3
   187  	ConstLeft4, ConstRight4
   188  )
   189  
   190  const (
   191  	ConstGroup1 unexportedType = iota
   192  	ConstGroup2
   193  	ConstGroup3
   194  )
   195  
   196  const ConstGroup4 ExportedType = ExportedType{}
   197  
   198  func newLongLine(ss ...string)
   199  
   200  var LongLine = newLongLine(
   201  	"someArgument1",
   202  	"someArgument2",
   203  	"someArgument3",
   204  	"someArgument4",
   205  	"someArgument5",
   206  	"someArgument6",
   207  	"someArgument7",
   208  	"someArgument8",
   209  )
   210  
   211  type T2 int
   212  
   213  type T1 = T2
   214  
   215  const (
   216  	Duplicate = iota
   217  	duplicate
   218  )
   219  
   220  // Comment about exported function with formatting.
   221  //
   222  // Example
   223  //
   224  //	fmt.Println(FormattedDoc())
   225  //
   226  // Text after pre-formatted block.
   227  func ExportedFormattedDoc(a int) bool {
   228  	return true
   229  }
   230  
   231  type ExportedFormattedType struct {
   232  	// Comment before exported field with formatting.
   233  	//
   234  	// Example
   235  	//
   236  	//	a.ExportedField = 123
   237  	//
   238  	// Text after pre-formatted block.
   239  	ExportedField int
   240  }
   241  
   242  type SimpleConstraint interface {
   243  	~int | ~float64
   244  }
   245  
   246  type TildeConstraint interface {
   247  	~int
   248  }
   249  
   250  type StructConstraint interface {
   251  	struct { F int }
   252  }
   253  

View as plain text