-
Notifications
You must be signed in to change notification settings - Fork 470
/
matchers.go
49 lines (41 loc) · 1.48 KB
/
matchers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package matchers
import (
"encoding/json"
"reflect"
"unsafe"
"github.com/onsi/gomega/types"
)
type GossMatcher interface {
// This is needed due to oMegaMatcher test in some of the GomegaMatcher logic
types.GomegaMatcher
//Match(actual interface{}) (success bool, err error)
FailureResult(actual interface{}) MatcherResult
NegatedFailureResult(actual interface{}) MatcherResult
// This doesn't seem to make a difference, maybe not needed
json.Marshaler
}
type MatcherResult struct {
Actual interface{} `json:"actual"`
Message string `json:"message"`
Expected interface{} `json:"expected"`
MissingElements interface{} `json:"missing-elements"`
FoundElements interface{} `json:"found-elements"`
ExtraElements interface{} `json:"extra-elements"`
TransformerChain []Transformer `json:"transform-chain"`
UntransformedValue interface{} `json:"untransformed-value"`
}
func getUnexported(i interface{}, field string) interface{} {
rs := reflect.ValueOf(i).Elem()
rf := rs.FieldByName(field)
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem()
return rf.Interface()
}
type fakeOmegaMatcher struct{}
// FailureMessage is a stub to honor omegaMatcher interface
func (m *fakeOmegaMatcher) FailureMessage(_ interface{}) (message string) {
return ""
}
// NegatedFailureMessage is a stub to honor omegaMatcher interface
func (m *fakeOmegaMatcher) NegatedFailureMessage(_ interface{}) (message string) {
return ""
}