github.com/hlts2/go@v0.0.0-20170904000733-812b34efaed8/src/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  // Constants
     9  
    10  // Comment about exported constant.
    11  const ExportedConstant = 1
    12  
    13  // Comment about internal constant.
    14  const internalConstant = 2
    15  
    16  // Comment about block of constants.
    17  const (
    18  	// Comment before ConstOne.
    19  	ConstOne   = 1
    20  	ConstTwo   = 2 // Comment on line with ConstTwo.
    21  	constThree = 3 // Comment on line with constThree.
    22  )
    23  
    24  // Const block where first entry is unexported.
    25  const (
    26  	constFour = iota
    27  	ConstFive
    28  	ConstSix
    29  )
    30  
    31  // Variables
    32  
    33  // Comment about exported variable.
    34  var ExportedVariable = 1
    35  
    36  // Comment about internal variable.
    37  var internalVariable = 2
    38  
    39  // Comment about block of variables.
    40  var (
    41  	// Comment before VarOne.
    42  	VarOne   = 1
    43  	VarTwo   = 2 // Comment on line with VarTwo.
    44  	varThree = 3 // Comment on line with varThree.
    45  )
    46  
    47  // Var block where first entry is unexported.
    48  var (
    49  	varFour = 4
    50  	VarFive = 5
    51  	varSix  = 6
    52  )
    53  
    54  // Comment about exported function.
    55  func ExportedFunc(a int) bool
    56  
    57  // Comment about internal function.
    58  func internalFunc(a int) bool
    59  
    60  // Comment about exported type.
    61  type ExportedType struct {
    62  	// Comment before exported field.
    63  	ExportedField         int // Comment on line with exported field.
    64  	unexportedField       int // Comment on line with unexported field.
    65  	ExportedEmbeddedType      // Comment on line with exported embedded field.
    66  	*ExportedEmbeddedType     // Comment on line with exported embedded *field.
    67  	unexportedType            // Comment on line with unexported embedded field.
    68  	*unexportedType           // Comment on line with unexported embedded *field.
    69  	io.Reader                 // Comment on line with embedded Reader.
    70  	error                     // Comment on line with embedded error.
    71  }
    72  
    73  // Comment about exported method.
    74  func (ExportedType) ExportedMethod(a int) bool {
    75  	return true
    76  }
    77  
    78  // Comment about unexported method.
    79  func (ExportedType) unexportedMethod(a int) bool {
    80  	return true
    81  }
    82  
    83  type ExportedStructOneField struct {
    84  	OnlyField int // the only field
    85  }
    86  
    87  // Constants tied to ExportedType. (The type is a struct so this isn't valid Go,
    88  // but it parses and that's all we need.)
    89  const (
    90  	ExportedTypedConstant ExportedType = iota
    91  )
    92  
    93  // Comment about constructor for exported type.
    94  func ExportedTypeConstructor() *ExportedType {
    95  	return nil
    96  }
    97  
    98  const unexportedTypedConstant ExportedType = 1 // In a separate section to test -u.
    99  
   100  // Comment about exported interface.
   101  type ExportedInterface interface {
   102  	// Comment before exported method.
   103  	ExportedMethod()   // Comment on line with exported method.
   104  	unexportedMethod() // Comment on line with unexported method.
   105  	io.Reader          // Comment on line with embedded Reader.
   106  	error              // Comment on line with embedded error.
   107  }
   108  
   109  // Comment about unexported type.
   110  type unexportedType int
   111  
   112  func (unexportedType) ExportedMethod() bool {
   113  	return true
   114  }
   115  
   116  func (unexportedType) unexportedMethod() bool {
   117  	return true
   118  }
   119  
   120  // Constants tied to unexportedType.
   121  const (
   122  	ExportedTypedConstant_unexported unexportedType = iota
   123  )
   124  
   125  const unexportedTypedConstant unexportedType = 1 // In a separate section to test -u.
   126  
   127  // For case matching.
   128  const CaseMatch = 1
   129  const Casematch = 2
   130  
   131  func ReturnUnexported() unexportedType { return 0 }
   132  func ReturnExported() ExportedType     { return ExportedType{} }
   133  
   134  const MultiLineConst = `
   135  	MultiLineString1
   136  	MultiLineString2
   137  	MultiLineString3
   138  `
   139  
   140  func MultiLineFunc(x interface {
   141  	MultiLineMethod1() int
   142  	MultiLineMethod2() int
   143  	MultiLineMethod3() int
   144  }) (r struct {
   145  	MultiLineField1 int
   146  	MultiLineField2 int
   147  	MultiLineField3 int
   148  }) {
   149  	return r
   150  }
   151  
   152  var MultiLineVar = map[struct {
   153  	MultiLineField1 string
   154  	MultiLineField2 uint64
   155  }]struct {
   156  	MultiLineField3 error
   157  	MultiLineField2 error
   158  }{
   159  	{"FieldVal1", 1}: {},
   160  	{"FieldVal2", 2}: {},
   161  	{"FieldVal3", 3}: {},
   162  }
   163  
   164  const (
   165  	_, _ uint64 = 2 * iota, 1 << iota
   166  	constLeft1, constRight1
   167  	ConstLeft2, constRight2
   168  	constLeft3, ConstRight3
   169  	ConstLeft4, ConstRight4
   170  )
   171  
   172  const (
   173  	ConstGroup1 unexportedType = iota
   174  	ConstGroup2
   175  	ConstGroup3
   176  )
   177  
   178  const ConstGroup4 ExportedType = ExportedType{}
   179  
   180  func newLongLine(ss ...string)
   181  
   182  var LongLine = newLongLine(
   183  	"someArgument1",
   184  	"someArgument2",
   185  	"someArgument3",
   186  	"someArgument4",
   187  	"someArgument5",
   188  	"someArgument6",
   189  	"someArgument7",
   190  	"someArgument8",
   191  )
   192  
   193  type T2 int
   194  
   195  type T1 = T2