...
1 package matchers
2
3 import (
4 "fmt"
5
6 "github.com/onsi/gomega/format"
7 "github.com/onsi/gomega/types"
8 )
9
10 type OrMatcher struct {
11 Matchers []types.GomegaMatcher
12
13
14 firstSuccessfulMatcher types.GomegaMatcher
15 }
16
17 func (m *OrMatcher) Match(actual interface{}) (success bool, err error) {
18 m.firstSuccessfulMatcher = nil
19 for _, matcher := range m.Matchers {
20 success, err := matcher.Match(actual)
21 if err != nil {
22 return false, err
23 }
24 if success {
25 m.firstSuccessfulMatcher = matcher
26 return true, nil
27 }
28 }
29 return false, nil
30 }
31
32 func (m *OrMatcher) FailureMessage(actual interface{}) (message string) {
33
34 return format.Message(actual, fmt.Sprintf("To satisfy at least one of these matchers: %s", m.Matchers))
35 }
36
37 func (m *OrMatcher) NegatedFailureMessage(actual interface{}) (message string) {
38 return m.firstSuccessfulMatcher.NegatedFailureMessage(actual)
39 }
40
41 func (m *OrMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
42
53
54 if m.firstSuccessfulMatcher != nil {
55
56 return types.MatchMayChangeInTheFuture(m.firstSuccessfulMatcher, actual)
57 } else {
58
59 for _, matcher := range m.Matchers {
60 if types.MatchMayChangeInTheFuture(matcher, actual) {
61 return true
62 }
63 }
64 return false
65 }
66 }
67
View as plain text