arnaucube
arnaucube/mirror-to-giteaPublic Self-hosted repository
mirror-to-gitea/vendor/github.com/onsi/gomega/matchers/be_identical_to.go
vendor/github.com/onsi/gomega/matchers/be_identical_to.goRaw
 1// untested sections: 2
 2
 3package matchers
 4
 5import (
 6	"fmt"
 7	"runtime"
 8
 9	"github.com/onsi/gomega/format"
10)
11
12type BeIdenticalToMatcher struct {
13	Expected interface{}
14}
15
16func (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
33func (matcher *BeIdenticalToMatcher) FailureMessage(actual interface{}) string {
34	return format.Message(actual, "to be identical to", matcher.Expected)
35}
36
37func (matcher *BeIdenticalToMatcher) NegatedFailureMessage(actual interface{}) string {
38	return format.Message(actual, "not to be identical to", matcher.Expected)
39}