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