github.com/daixiang0/gci@v0.13.0/pkg/section/errors_test.go (about) 1 package section 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestErrorMatching(t *testing.T) { 11 assert.True(t, errors.Is(MissingParameterClosingBracketsError, MissingParameterClosingBracketsError)) 12 assert.True(t, errors.Is(MoreThanOneOpeningQuotesError, MoreThanOneOpeningQuotesError)) 13 assert.True(t, errors.Is(SectionTypeDoesNotAcceptParametersError, SectionTypeDoesNotAcceptParametersError)) 14 assert.True(t, errors.Is(SectionTypeDoesNotAcceptPrefixError, SectionTypeDoesNotAcceptPrefixError)) 15 assert.True(t, errors.Is(SectionTypeDoesNotAcceptSuffixError, SectionTypeDoesNotAcceptSuffixError)) 16 } 17 18 func TestErrorClass(t *testing.T) { 19 subError := MissingParameterClosingBracketsError 20 errorGroup := SectionParsingError{subError} 21 assert.True(t, errors.Is(errorGroup, SectionParsingError{})) 22 assert.True(t, errors.Is(errorGroup, subError)) 23 assert.True(t, errors.Is(errorGroup.Wrap("x"), SectionParsingError{})) 24 assert.True(t, errors.Is(errorGroup.Wrap("x"), subError)) 25 }