6 "github.com/onsi/gomega/format"
7 "github.com/onsi/gomega/internal/oraclematcher"
8 "github.com/onsi/gomega/types"
11 type OrMatcher struct {
12 Matchers []types.GomegaMatcher
15 firstSuccessfulMatcher types.GomegaMatcher
18 func (m *OrMatcher) Match(actual interface{}) (success bool, err error) {
19 m.firstSuccessfulMatcher = nil
20 for _, matcher := range m.Matchers {
21 success, err := matcher.Match(actual)
26 m.firstSuccessfulMatcher = matcher
33 func (m *OrMatcher) FailureMessage(actual interface{}) (message string) {
34 // not the most beautiful list of matchers, but not bad either...
35 return format.Message(actual, fmt.Sprintf("To satisfy at least one of these matchers: %s", m.Matchers))
38 func (m *OrMatcher) NegatedFailureMessage(actual interface{}) (message string) {
39 return m.firstSuccessfulMatcher.NegatedFailureMessage(actual)
42 func (m *OrMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
44 Example with 3 matchers: A, B, C
46 Match evaluates them: F, T, <?> => T
47 So match is currently T, what should MatchMayChangeInTheFuture() return?
48 Seems like it only depends on B, since currently B MUST change to allow the result to become F
50 Match eval: F, F, F => F
51 So match is currently F, what should MatchMayChangeInTheFuture() return?
52 Seems to depend on ANY of them being able to change to T.
55 if m.firstSuccessfulMatcher != nil {
56 // one of the matchers succeeded.. it must be able to change in order to affect the result
57 return oraclematcher.MatchMayChangeInTheFuture(m.firstSuccessfulMatcher, actual)
59 // so all matchers failed.. Any one of them changing would change the result.
60 for _, matcher := range m.Matchers {
61 if oraclematcher.MatchMayChangeInTheFuture(matcher, actual) {
65 return false // none of were going to change