12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package oglematchers
- import (
- "errors"
- "fmt"
- "reflect"
- "strings"
- )
- func HasSubstr(s string) Matcher {
- return NewMatcher(
- func(c interface{}) error { return hasSubstr(s, c) },
- fmt.Sprintf("has substring \"%s\"", s))
- }
- func hasSubstr(needle string, c interface{}) error {
- v := reflect.ValueOf(c)
- if v.Kind() != reflect.String {
- return NewFatalError("which is not a string")
- }
-
- haystack := v.String()
- if strings.Contains(haystack, needle) {
- return nil
- }
- return errors.New("")
- }
|