github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/codescan/parser_go119_test.go (about)

     1  //go:build go1.19
     2  // +build go1.19
     3  
     4  package codescan
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestSectionedParser_TitleDescriptionGo119(t *testing.T) {
    13  
    14  	text := `# This has a title that starts with a hash tag
    15  
    16  The punctuation here does indeed matter. But it won't for go.
    17  `
    18  
    19  	text2 := `This has a title without whitespace.
    20  
    21  The punctuation here does indeed matter. But it won't for go.
    22  
    23  # There is an inline header here that doesn't count for finding a title
    24  
    25  `
    26  
    27  	var err error
    28  
    29  	st := &sectionedParser{}
    30  	st.setTitle = func(lines []string) {}
    31  	err = st.Parse(ascg(text))
    32  	assert.NoError(t, err)
    33  
    34  	assert.EqualValues(t, []string{"This has a title that starts with a hash tag"}, st.Title())
    35  	assert.EqualValues(t, []string{"The punctuation here does indeed matter. But it won't for go."}, st.Description())
    36  
    37  	st = &sectionedParser{}
    38  	st.setTitle = func(lines []string) {}
    39  	err = st.Parse(ascg(text2))
    40  	assert.NoError(t, err)
    41  
    42  	assert.EqualValues(t, []string{"This has a title without whitespace."}, st.Title())
    43  	assert.EqualValues(t, []string{"The punctuation here does indeed matter. But it won't for go.", "", "# There is an inline header here that doesn't count for finding a title"}, st.Description())
    44  }