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