github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/example1/example1.go (about)

     1  // Package example1 exists in order to test various go to git
     2  // markdown (gToMD) extraction utilities.  Various object will be defined that
     3  // exhibit the various comment and declaration options permitted by gofmt.
     4  //
     5  // # Heading
     6  //
     7  // This paragraph will demonstrating further documentation under a "markdown"
     8  // header.
     9  //
    10  // Declarations can be single-line or multi-line blocks or constructions.  Each
    11  // type will be included here for complete testing.
    12  package example1
    13  
    14  import "strconv"
    15  
    16  // ConstDeclSingleCmtSingle has a single-line comment.
    17  const ConstDeclSingleCmtSingle = "single-line declaration and comment"
    18  
    19  // ConstDeclSingleCmtMulti has a multiline
    20  // comment.
    21  const ConstDeclSingleCmtMulti = "single-line declaration and comment"
    22  
    23  // ConstDeclMultiCmtSingle has a single-line comment with a multiline decl.
    24  const ConstDeclMultiCmtSingle = `multiline constant
    25  definition
    26  `
    27  
    28  // ConstDeclMultiCmtMulti has a multiline comment with
    29  // a multiline decl.
    30  const ConstDeclMultiCmtMulti = `multiline constant
    31  definition
    32  `
    33  
    34  // ConstDeclConstrCmtSingle has a single-line comment with a multiline decl.
    35  const ConstDeclConstrCmtSingle = `multiline constant` + "\n" +
    36  	ConstDeclMultiCmtSingle + " including other constants: \n" +
    37  	ConstDeclSingleCmtSingle + "\n" + `
    38  =========end of constant=============
    39  `
    40  
    41  // ConstDeclConstrCmtMulti has a multiline comment with
    42  // a multiline decl.
    43  const ConstDeclConstrCmtMulti = `multiline constant` + "\n" +
    44  	ConstDeclMultiCmtSingle + " including other constants: \n" +
    45  	ConstDeclSingleCmtSingle + "\n" + `
    46  =========end of constant=============
    47  `
    48  
    49  // ConstantSingleLine tests single line constant definitions.
    50  const ConstantSingleLine = "this is defined on a single-line"
    51  
    52  // ConstantMultipleLines1 test a multiline comment with string addition.
    53  // Also with longer:
    54  //
    55  // multiline comments with spacing.
    56  const ConstantMultipleLines1 = "this constant" +
    57  	"is defined on multiple " +
    58  	"lines"
    59  
    60  // ConstantMultipleLines2 tests a multiline comment with go multiline string.
    61  const ConstantMultipleLines2 = `this constant
    62  is defined on multiple
    63  	      lines
    64  `
    65  
    66  // Here is a constant block.  All constants are reported as a group.
    67  const (
    68  	// ConstantGroup1 is a constant defined in a group.
    69  	ConstantGroup1 = "constant 1"
    70  
    71  	// ConstantGroup2 is a constant defined in a group.
    72  	ConstantGroup2 = "constant 2"
    73  )
    74  
    75  // InterfaceType tests the documentation of interfaces.
    76  type InterfaceType interface {
    77  	func(int) int
    78  }
    79  
    80  // StructureType tests the documentation of structures.
    81  type StructureType struct {
    82  	// F1 is the first test field of the structure.
    83  	F1 string
    84  	// F2 is the second test field of the structure.
    85  	F2 int
    86  }
    87  
    88  // GetF1 is a method to a structure.
    89  func (s *StructureType) GetF1(
    90  	a, b, c int,
    91  ) string {
    92  	const base10 = 10
    93  
    94  	t := a + c + b
    95  
    96  	return s.F1 + strconv.FormatInt(int64(t), base10)
    97  }
    98  
    99  // TimesTwo returns the value times two.
   100  func TimesTwo(i int) int {
   101  	return i + i
   102  }
   103  
   104  // TimesThree returns the value times three.
   105  func TimesThree(i int) int {
   106  	return i + i + i
   107  }