5 "github.com/onsi/gomega/format"
8 type HaveSuffixMatcher struct {
13 func (matcher *HaveSuffixMatcher) Match(actual interface{}) (success bool, err error) {
14 actualString, ok := toString(actual)
16 return false, fmt.Errorf("HaveSuffix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
18 suffix := matcher.suffix()
19 return len(actualString) >= len(suffix) && actualString[len(actualString)-len(suffix):] == suffix, nil
22 func (matcher *HaveSuffixMatcher) suffix() string {
23 if len(matcher.Args) > 0 {
24 return fmt.Sprintf(matcher.Suffix, matcher.Args...)
29 func (matcher *HaveSuffixMatcher) FailureMessage(actual interface{}) (message string) {
30 return format.Message(actual, "to have suffix", matcher.suffix())
33 func (matcher *HaveSuffixMatcher) NegatedFailureMessage(actual interface{}) (message string) {
34 return format.Message(actual, "not to have suffix", matcher.suffix())