5 "github.com/onsi/gomega/format"
8 type HavePrefixMatcher struct {
13 func (matcher *HavePrefixMatcher) Match(actual interface{}) (success bool, err error) {
14 actualString, ok := toString(actual)
16 return false, fmt.Errorf("HavePrefix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
18 prefix := matcher.prefix()
19 return len(actualString) >= len(prefix) && actualString[0:len(prefix)] == prefix, nil
22 func (matcher *HavePrefixMatcher) prefix() string {
23 if len(matcher.Args) > 0 {
24 return fmt.Sprintf(matcher.Prefix, matcher.Args...)
29 func (matcher *HavePrefixMatcher) FailureMessage(actual interface{}) (message string) {
30 return format.Message(actual, "to have prefix", matcher.prefix())
33 func (matcher *HavePrefixMatcher) NegatedFailureMessage(actual interface{}) (message string) {
34 return format.Message(actual, "not to have prefix", matcher.prefix())