...

Source file src/github.com/MakeNowJust/heredoc/example_test.go

Documentation: github.com/MakeNowJust/heredoc

     1  // Copyright (c) 2014-2019 TSUYUSATO Kitsune
     2  // This software is released under the MIT License.
     3  // http://opensource.org/licenses/mit-license.php
     4  
     5  package heredoc_test
     6  
     7  import (
     8  	"fmt"
     9  )
    10  
    11  import "github.com/MakeNowJust/heredoc"
    12  
    13  func ExampleDoc_lipsum() {
    14  	fmt.Print(heredoc.Doc(`
    15  		Lorem ipsum dolor sit amet, consectetur adipisicing elit,
    16  		sed do eiusmod tempor incididunt ut labore et dolore magna
    17  		aliqua. Ut enim ad minim veniam, ...
    18  	`))
    19  	// Output:
    20  	// Lorem ipsum dolor sit amet, consectetur adipisicing elit,
    21  	// sed do eiusmod tempor incididunt ut labore et dolore magna
    22  	// aliqua. Ut enim ad minim veniam, ...
    23  	//
    24  }
    25  
    26  func ExampleDoc_spec() {
    27  	// Single line string is no change.
    28  	fmt.Println(heredoc.Doc(`It is single line.`))
    29  	// If first line is empty, heredoc.Doc removes first line.
    30  	fmt.Println(heredoc.Doc(`
    31  		It is first line.
    32  		It is second line.`))
    33  	// If last line is empty and more little length than indents,
    34  	// heredoc.Doc removes last line's content.
    35  	fmt.Println(heredoc.Doc(`
    36  		Next is last line.
    37  	`))
    38  	fmt.Println("Previous is last line.")
    39  	// Output:
    40  	// It is single line.
    41  	// It is first line.
    42  	// It is second line.
    43  	// Next is last line.
    44  	//
    45  	// Previous is last line.
    46  }
    47  
    48  func ExampleDocf() {
    49  	libName := "github.com/MakeNowJust/heredoc"
    50  	author := "TSUYUSATO Kitsune (@MakeNowJust)"
    51  	fmt.Printf(heredoc.Docf(`
    52  		Library Name  : %s
    53  		Author        : %s
    54  		Repository URL: http://%s.git
    55  	`, libName, author, libName))
    56  	// Output:
    57  	// Library Name  : github.com/MakeNowJust/heredoc
    58  	// Author        : TSUYUSATO Kitsune (@MakeNowJust)
    59  	// Repository URL: http://github.com/MakeNowJust/heredoc.git
    60  }
    61  

View as plain text