Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,29 @@ func MatchRegexp(regexp string, args ...interface{}) types.GomegaMatcher {
}
}

// ContainSubstring succeeds if actual is a string or stringer that contains the
// passed-in substring. Optional arguments can be provided to construct the substring
// via fmt.Sprintf().
// ContainSubstring succeeds if actual is a string, stringer, []bytes, or json.RawMessage
// that contains the passed-in substring.
// Optional arguments can be provided to construct the substring via fmt.Sprintf().
func ContainSubstring(substr string, args ...interface{}) types.GomegaMatcher {
return &matchers.ContainSubstringMatcher{
Substr: substr,
Args: args,
}
}

// HavePrefix succeeds if actual is a string or stringer that contains the
// passed-in string as a prefix. Optional arguments can be provided to construct
// via fmt.Sprintf().
// HavePrefix succeeds if actual is a string, stringer, []bytes, or json.RawMessage
// that contains the passed-in string as a prefix.
// Optional arguments can be provided to construct the substring via fmt.Sprintf().
func HavePrefix(prefix string, args ...interface{}) types.GomegaMatcher {
return &matchers.HavePrefixMatcher{
Prefix: prefix,
Args: args,
}
}

// HaveSuffix succeeds if actual is a string or stringer that contains the
// passed-in string as a suffix. Optional arguments can be provided to construct
// via fmt.Sprintf().
// HaveSuffix succeeds if actual is a string, stringer, []bytes, or json.RawMessage
// that contains the passed-in string as a suffix.
// Optional arguments can be provided to construct the substring via fmt.Sprintf().
func HaveSuffix(suffix string, args ...interface{}) types.GomegaMatcher {
return &matchers.HaveSuffixMatcher{
Suffix: suffix,
Expand Down
3 changes: 2 additions & 1 deletion matchers/contain_substring_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type ContainSubstringMatcher struct {
func (matcher *ContainSubstringMatcher) Match(actual interface{}) (success bool, err error) {
actualString, ok := toString(actual)
if !ok {
return false, fmt.Errorf("ContainSubstring matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
return false, fmt.Errorf("ContainSubstring matcher requires a string, stringer, []bytes, or json.RawMessage. "+
"Got:\n%s", format.Object(actual, 1))
}

return strings.Contains(actualString, matcher.stringToMatch()), nil
Expand Down
3 changes: 2 additions & 1 deletion matchers/have_prefix_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type HavePrefixMatcher struct {
func (matcher *HavePrefixMatcher) Match(actual interface{}) (success bool, err error) {
actualString, ok := toString(actual)
if !ok {
return false, fmt.Errorf("HavePrefix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
return false, fmt.Errorf("HavePrefix matcher requires a string, stringer, []bytes, or json.RawMessage. "+
"Got:\n%s", format.Object(actual, 1))
}
prefix := matcher.prefix()
return len(actualString) >= len(prefix) && actualString[0:len(prefix)] == prefix, nil
Expand Down
3 changes: 2 additions & 1 deletion matchers/have_suffix_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type HaveSuffixMatcher struct {
func (matcher *HaveSuffixMatcher) Match(actual interface{}) (success bool, err error) {
actualString, ok := toString(actual)
if !ok {
return false, fmt.Errorf("HaveSuffix matcher requires a string or stringer. Got:\n%s", format.Object(actual, 1))
return false, fmt.Errorf("HaveSuffix matcher requires a string, stringer, []bytes, or json.RawMessage. "+
"Got:\n%s", format.Object(actual, 1))
}
suffix := matcher.suffix()
return len(actualString) >= len(suffix) && actualString[len(actualString)-len(suffix):] == suffix, nil
Expand Down