github.com/daixiang0/gci@v0.13.0/pkg/section/parser_test.go (about)

     1  package section
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type sectionTestData struct {
    11  	input           []string
    12  	expectedSection SectionList
    13  	expectedError   error
    14  }
    15  
    16  func TestParse(t *testing.T) {
    17  	testCases := []sectionTestData{
    18  		{
    19  			input:           []string{""},
    20  			expectedSection: nil,
    21  			expectedError:   nil,
    22  		},
    23  		{
    24  			input:           []string{"prefix(go)"},
    25  			expectedSection: SectionList{Custom{"go"}},
    26  			expectedError:   nil,
    27  		},
    28  		{
    29  			input:           []string{"prefix(go-UPPER-case)"},
    30  			expectedSection: SectionList{Custom{"go-UPPER-case"}},
    31  			expectedError:   nil,
    32  		},
    33  		{
    34  			input:           []string{"PREFIX(go-UPPER-case)"},
    35  			expectedSection: SectionList{Custom{"go-UPPER-case"}},
    36  			expectedError:   nil,
    37  		},
    38  		{
    39  			input:           []string{"prefix("},
    40  			expectedSection: nil,
    41  			expectedError:   errors.New("invalid params: prefix("),
    42  		},
    43  		{
    44  			input:           []string{"prefix(domainA,domainB)"},
    45  			expectedSection: SectionList{Custom{"domainA,domainB"}},
    46  			expectedError:   nil,
    47  		},
    48  	}
    49  	for _, test := range testCases {
    50  		parsedSection, err := Parse(test.input)
    51  		assert.Equal(t, test.expectedSection, parsedSection)
    52  		assert.Equal(t, test.expectedError, err)
    53  	}
    54  }