...

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

Documentation: cmd/doc/testdata

     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  	// BUG(me): function body note
    61  	return true != false
    62  }
    63  
    64  // Comment about internal function.
    65  func internalFunc(a int) bool
    66  
    67  // Comment about exported type.
    68  type 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.
    82  func (ExportedType) ExportedMethod(a int) bool {
    83  	return true != true
    84  }
    85  
    86  func (ExportedType) Uncommented(a int) bool {
    87  	return true != true
    88  }
    89  
    90  // Comment about unexported method.
    91  func (ExportedType) unexportedMethod(a int) bool {
    92  	return true
    93  }
    94  
    95  type 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.)
   101  const (
   102  	ExportedTypedConstant ExportedType = iota
   103  )
   104  
   105  // Comment about constructor for exported type.
   106  func ExportedTypeConstructor() *ExportedType {
   107  	return nil
   108  }
   109  
   110  const unexportedTypedConstant ExportedType = 1 // In a separate section to test -u.
   111  
   112  // Comment about exported interface.
   113  type 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.
   129  type unexportedType int
   130  
   131  func (unexportedType) ExportedMethod() bool {
   132  	return true
   133  }
   134  
   135  func (unexportedType) unexportedMethod() bool {
   136  	return true
   137  }
   138  
   139  // Constants tied to unexportedType.
   140  const (
   141  	ExportedTypedConstant_unexported unexportedType = iota
   142  )
   143  
   144  const unexportedTypedConstant unexportedType = 1 // In a separate section to test -u.
   145  
   146  // For case matching.
   147  const CaseMatch = 1
   148  const Casematch = 2
   149  
   150  func ReturnUnexported() unexportedType { return 0 }
   151  func ReturnExported() ExportedType     { return ExportedType{} }
   152  
   153  const MultiLineConst = `
   154  	MultiLineString1
   155  	MultiLineString2
   156  	MultiLineString3
   157  `
   158  
   159  func 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  
   171  var 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  
   183  const (
   184  	_, _ uint64 = 2 * iota, 1 << iota
   185  	constLeft1, constRight1
   186  	ConstLeft2, constRight2
   187  	constLeft3, ConstRight3
   188  	ConstLeft4, ConstRight4
   189  )
   190  
   191  const (
   192  	ConstGroup1 unexportedType = iota
   193  	ConstGroup2
   194  	ConstGroup3
   195  )
   196  
   197  const ConstGroup4 ExportedType = ExportedType{}
   198  
   199  func newLongLine(ss ...string)
   200  
   201  var LongLine = newLongLine(
   202  	"someArgument1",
   203  	"someArgument2",
   204  	"someArgument3",
   205  	"someArgument4",
   206  	"someArgument5",
   207  	"someArgument6",
   208  	"someArgument7",
   209  	"someArgument8",
   210  )
   211  
   212  type T2 int
   213  
   214  type T1 = T2
   215  
   216  const (
   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.
   228  func ExportedFormattedDoc(a int) bool {
   229  	return true
   230  }
   231  
   232  type 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  
   244  type SimpleConstraint interface {
   245  	~int | ~float64
   246  }
   247  
   248  type TildeConstraint interface {
   249  	~int
   250  }
   251  
   252  type StructConstraint interface {
   253  	struct { F int }
   254  }
   255  

View as plain text