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