initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / equal_matcher.go
1 package matchers
2
3 import (
4         "fmt"
5         "reflect"
6
7         "github.com/onsi/gomega/format"
8 )
9
10 type EqualMatcher struct {
11         Expected interface{}
12 }
13
14 func (matcher *EqualMatcher) Match(actual interface{}) (success bool, err error) {
15         if actual == nil && matcher.Expected == nil {
16                 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.")
17         }
18         return reflect.DeepEqual(actual, matcher.Expected), nil
19 }
20
21 func (matcher *EqualMatcher) FailureMessage(actual interface{}) (message string) {
22         actualString, actualOK := actual.(string)
23         expectedString, expectedOK := matcher.Expected.(string)
24         if actualOK && expectedOK {
25                 return format.MessageWithDiff(actualString, "to equal", expectedString)
26         }
27
28         return format.Message(actual, "to equal", matcher.Expected)
29 }
30
31 func (matcher *EqualMatcher) NegatedFailureMessage(actual interface{}) (message string) {
32         return format.Message(actual, "not to equal", matcher.Expected)
33 }