github.com/KEINOS/go-countline@v1.1.1-0.20221217083629-60710df7606b/cl/example_test.go (about)

     1  package cl_test
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"strings"
     7  
     8  	"github.com/KEINOS/go-countline/cl"
     9  )
    10  
    11  func ExampleCountLines() {
    12  	for _, sample := range []struct {
    13  		Input string
    14  	}{
    15  		{""},            // --> 0
    16  		{"Hello"},       // --> 1
    17  		{"Hello\n"},     // --> 1
    18  		{"\n"},          // --> 1
    19  		{"\n\n"},        // --> 2
    20  		{"\nHello"},     // --> 2
    21  		{"\nHello\n"},   // --> 2
    22  		{"\n\nHello"},   // --> 3
    23  		{"\n\nHello\n"}, // --> 3
    24  	} {
    25  		readerFile := strings.NewReader(sample.Input)
    26  
    27  		count, err := cl.CountLines(readerFile)
    28  		if err != nil {
    29  			log.Fatal(err)
    30  		}
    31  
    32  		fmt.Printf("%#v --> %v\n", sample.Input, count)
    33  	}
    34  	// Output:
    35  	// "" --> 0
    36  	// "Hello" --> 1
    37  	// "Hello\n" --> 1
    38  	// "\n" --> 1
    39  	// "\n\n" --> 2
    40  	// "\nHello" --> 2
    41  	// "\nHello\n" --> 2
    42  	// "\n\nHello" --> 3
    43  	// "\n\nHello\n" --> 3
    44  }