1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package oglematchers
- import (
- "errors"
- "fmt"
- "reflect"
- )
- func Pointee(m Matcher) Matcher {
- return &pointeeMatcher{m}
- }
- type pointeeMatcher struct {
- wrapped Matcher
- }
- func (m *pointeeMatcher) Matches(c interface{}) (err error) {
-
- cv := reflect.ValueOf(c)
- if !cv.IsValid() || cv.Kind() != reflect.Ptr {
- return NewFatalError("which is not a pointer")
- }
-
- if cv.IsNil() {
- return NewFatalError("")
- }
-
-
- pointee := cv.Elem().Interface()
- err = m.wrapped.Matches(pointee)
- if err != nil && err.Error() == "" {
- s := fmt.Sprintf("whose pointee is %v", pointee)
- if _, ok := err.(*FatalError); ok {
- err = NewFatalError(s)
- } else {
- err = errors.New(s)
- }
- }
- return err
- }
- func (m *pointeeMatcher) Description() string {
- return fmt.Sprintf("pointee(%s)", m.wrapped.Description())
- }
|