be_identical_to.go 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // untested sections: 2
  2. package matchers
  3. import (
  4. "fmt"
  5. "runtime"
  6. "github.com/onsi/gomega/format"
  7. )
  8. type BeIdenticalToMatcher struct {
  9. Expected interface{}
  10. }
  11. func (matcher *BeIdenticalToMatcher) Match(actual interface{}) (success bool, matchErr error) {
  12. if actual == nil && matcher.Expected == nil {
  13. 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.")
  14. }
  15. defer func() {
  16. if r := recover(); r != nil {
  17. if _, ok := r.(runtime.Error); ok {
  18. success = false
  19. matchErr = nil
  20. }
  21. }
  22. }()
  23. return actual == matcher.Expected, nil
  24. }
  25. func (matcher *BeIdenticalToMatcher) FailureMessage(actual interface{}) string {
  26. return format.Message(actual, "to be identical to", matcher.Expected)
  27. }
  28. func (matcher *BeIdenticalToMatcher) NegatedFailureMessage(actual interface{}) string {
  29. return format.Message(actual, "not to be identical to", matcher.Expected)
  30. }