7 "github.com/onsi/gomega/format"
8 "github.com/onsi/gomega/types"
11 //PointTo applies the given matcher to the value pointed to by actual. It fails if the pointer is
14 // Expect(&actual).To(PointTo(Equal(5)))
15 func PointTo(matcher types.GomegaMatcher) types.GomegaMatcher {
16 return &PointerMatcher{
21 type PointerMatcher struct {
22 Matcher types.GomegaMatcher
28 func (m *PointerMatcher) Match(actual interface{}) (bool, error) {
29 val := reflect.ValueOf(actual)
31 // return error if actual type is not a pointer
32 if val.Kind() != reflect.Ptr {
33 return false, fmt.Errorf("PointerMatcher expects a pointer but we have '%s'", val.Kind())
36 if !val.IsValid() || val.IsNil() {
37 m.failure = format.Message(actual, "not to be <nil>")
42 elem := val.Elem().Interface()
43 match, err := m.Matcher.Match(elem)
45 m.failure = m.Matcher.FailureMessage(elem)
50 func (m *PointerMatcher) FailureMessage(_ interface{}) (message string) {
54 func (m *PointerMatcher) NegatedFailureMessage(actual interface{}) (message string) {
55 return m.Matcher.NegatedFailureMessage(actual)