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