github.com/onsi/gomega@v1.32.0/matchers/be_identical_to.go (about) 1 // untested sections: 2 2 3 package matchers 4 5 import ( 6 "fmt" 7 "runtime" 8 9 "github.com/onsi/gomega/format" 10 ) 11 12 type BeIdenticalToMatcher struct { 13 Expected interface{} 14 } 15 16 func (matcher *BeIdenticalToMatcher) Match(actual interface{}) (success bool, matchErr error) { 17 if actual == nil && matcher.Expected == nil { 18 return false, fmt.Errorf("Refusing to compare <nil> to <nil>.\nBe explicit and use BeNil() instead. This is to avoid mistakes where both sides of an assertion are erroneously uninitialized.") 19 } 20 21 defer func() { 22 if r := recover(); r != nil { 23 if _, ok := r.(runtime.Error); ok { 24 success = false 25 matchErr = nil 26 } 27 } 28 }() 29 30 return actual == matcher.Expected, nil 31 } 32 33 func (matcher *BeIdenticalToMatcher) FailureMessage(actual interface{}) string { 34 return format.Message(actual, "to be identical to", matcher.Expected) 35 } 36 37 func (matcher *BeIdenticalToMatcher) NegatedFailureMessage(actual interface{}) string { 38 return format.Message(actual, "not to be identical to", matcher.Expected) 39 }