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