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