github.com/go-swagger/go-swagger@v0.31.0/codescan/parser_go119_test.go (about)

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