Path: blob/main/vendor/github.com/onsi/gomega/matchers/have_suffix_matcher.go
2880 views
package matchers12import (3"fmt"45"github.com/onsi/gomega/format"6)78type HaveSuffixMatcher struct {9Suffix string10Args []any11}1213func (matcher *HaveSuffixMatcher) Match(actual any) (success bool, err error) {14actualString, ok := toString(actual)15if !ok {16return false, fmt.Errorf("HaveSuffix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))17}18suffix := matcher.suffix()19return len(actualString) >= len(suffix) && actualString[len(actualString)-len(suffix):] == suffix, nil20}2122func (matcher *HaveSuffixMatcher) suffix() string {23if len(matcher.Args) > 0 {24return fmt.Sprintf(matcher.Suffix, matcher.Args...)25}26return matcher.Suffix27}2829func (matcher *HaveSuffixMatcher) FailureMessage(actual any) (message string) {30return format.Message(actual, "to have suffix", matcher.suffix())31}3233func (matcher *HaveSuffixMatcher) NegatedFailureMessage(actual any) (message string) {34return format.Message(actual, "not to have suffix", matcher.suffix())35}363738