Path: blob/main/vendor/github.com/onsi/gomega/matchers/and.go
2880 views
package matchers12import (3"fmt"45"github.com/onsi/gomega/format"6"github.com/onsi/gomega/types"7)89type AndMatcher struct {10Matchers []types.GomegaMatcher1112// state13firstFailedMatcher types.GomegaMatcher14}1516func (m *AndMatcher) Match(actual any) (success bool, err error) {17m.firstFailedMatcher = nil18for _, matcher := range m.Matchers {19success, err := matcher.Match(actual)20if !success || err != nil {21m.firstFailedMatcher = matcher22return false, err23}24}25return true, nil26}2728func (m *AndMatcher) FailureMessage(actual any) (message string) {29return m.firstFailedMatcher.FailureMessage(actual)30}3132func (m *AndMatcher) NegatedFailureMessage(actual any) (message string) {33// not the most beautiful list of matchers, but not bad either...34return format.Message(actual, fmt.Sprintf("To not satisfy all of these matchers: %s", m.Matchers))35}3637func (m *AndMatcher) MatchMayChangeInTheFuture(actual any) bool {38/*39Example with 3 matchers: A, B, C4041Match evaluates them: T, F, <?> => F42So match is currently F, what should MatchMayChangeInTheFuture() return?43Seems like it only depends on B, since currently B MUST change to allow the result to become T4445Match eval: T, T, T => T46So match is currently T, what should MatchMayChangeInTheFuture() return?47Seems to depend on ANY of them being able to change to F.48*/4950if m.firstFailedMatcher == nil {51// so all matchers succeeded.. Any one of them changing would change the result.52for _, matcher := range m.Matchers {53if types.MatchMayChangeInTheFuture(matcher, actual) {54return true55}56}57return false // none of were going to change58}59// one of the matchers failed.. it must be able to change in order to affect the result60return types.MatchMayChangeInTheFuture(m.firstFailedMatcher, actual)61}626364