...

Source file src/github.com/onsi/gomega/matchers/be_equivalent_to_matcher.go

Documentation: github.com/onsi/gomega/matchers

     1  // untested sections: 2
     2  
     3  package matchers
     4  
     5  import (
     6  	"fmt"
     7  	"reflect"
     8  
     9  	"github.com/onsi/gomega/format"
    10  )
    11  
    12  type BeEquivalentToMatcher struct {
    13  	Expected interface{}
    14  }
    15  
    16  func (matcher *BeEquivalentToMatcher) Match(actual interface{}) (success bool, err error) {
    17  	if actual == nil && matcher.Expected == nil {
    18  		return false, fmt.Errorf("Both actual and expected must not be nil.")
    19  	}
    20  
    21  	convertedActual := actual
    22  
    23  	if actual != nil && matcher.Expected != nil && reflect.TypeOf(actual).ConvertibleTo(reflect.TypeOf(matcher.Expected)) {
    24  		convertedActual = reflect.ValueOf(actual).Convert(reflect.TypeOf(matcher.Expected)).Interface()
    25  	}
    26  
    27  	return reflect.DeepEqual(convertedActual, matcher.Expected), nil
    28  }
    29  
    30  func (matcher *BeEquivalentToMatcher) FailureMessage(actual interface{}) (message string) {
    31  	return format.Message(actual, "to be equivalent to", matcher.Expected)
    32  }
    33  
    34  func (matcher *BeEquivalentToMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    35  	return format.Message(actual, "not to be equivalent to", matcher.Expected)
    36  }
    37  

View as plain text