MCPcopy
hub / github.com/stretchr/testify / Matches

Method Matches

mock/mock.go:875–899  ·  view source on GitHub ↗
(argument interface{})

Source from the content-addressed store, hash-verified

873}
874
875func (f argumentMatcher) Matches(argument interface{}) bool {
876 expectType := f.fn.Type().In(0)
877 expectTypeNilSupported := false
878 switch expectType.Kind() {
879 case reflect.Interface, reflect.Chan, reflect.Func, reflect.Map, reflect.Slice, reflect.Ptr:
880 expectTypeNilSupported = true
881 }
882
883 argType := reflect.TypeOf(argument)
884 var arg reflect.Value
885 if argType == nil {
886 arg = reflect.New(expectType).Elem()
887 } else {
888 arg = reflect.ValueOf(argument)
889 }
890
891 if argType == nil && !expectTypeNilSupported {
892 panic(errors.New("attempting to call matcher with nil for non-nil expected type"))
893 }
894 if argType == nil || argType.AssignableTo(expectType) {
895 result := f.fn.Call([]reflect.Value{arg})
896 return result[0].Bool()
897 }
898 return false
899}
900
901func (f argumentMatcher) String() string {
902 return fmt.Sprintf("func(%s) bool", f.fn.Type().In(0).String())

Callers 1

DiffMethod · 0.80

Calls 2

BoolMethod · 0.80
CallMethod · 0.65

Tested by

no test coverage detected