arnaucube
arnaucube/mirror-to-giteaPublic Self-hosted repository
mirror-to-gitea/vendor/github.com/onsi/gomega/matchers/have_suffix_matcher.go
vendor/github.com/onsi/gomega/matchers/have_suffix_matcher.goRaw
 1package matchers
 2
 3import (
 4	"fmt"
 5
 6	"github.com/onsi/gomega/format"
 7)
 8
 9type HaveSuffixMatcher struct {
10	Suffix string
11	Args   []interface{}
12}
13
14func (matcher *HaveSuffixMatcher) Match(actual interface{}) (success bool, err error) {
15	actualString, ok := toString(actual)
16	if !ok {
17		return false, fmt.Errorf("HaveSuffix matcher requires a string or stringer.  Got:\n%s", format.Object(actual, 1))
18	}
19	suffix := matcher.suffix()
20	return len(actualString) >= len(suffix) && actualString[len(actualString)-len(suffix):] == suffix, nil
21}
22
23func (matcher *HaveSuffixMatcher) suffix() string {
24	if len(matcher.Args) > 0 {
25		return fmt.Sprintf(matcher.Suffix, matcher.Args...)
26	}
27	return matcher.Suffix
28}
29
30func (matcher *HaveSuffixMatcher) FailureMessage(actual interface{}) (message string) {
31	return format.Message(actual, "to have suffix", matcher.suffix())
32}
33
34func (matcher *HaveSuffixMatcher) NegatedFailureMessage(actual interface{}) (message string) {
35	return format.Message(actual, "not to have suffix", matcher.suffix())
36}