4 . "github.com/onsi/ginkgo"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/matchers"
9 var _ = Describe("OrMatcher", func() {
10 It("works with positive cases", func() {
11 Expect(input).To(Or(true1))
12 Expect(input).To(Or(true1, true2))
13 Expect(input).To(Or(true1, false1))
14 Expect(input).To(Or(false1, true2))
15 Expect(input).To(Or(true1, true2, true3))
16 Expect(input).To(Or(true1, true2, false3))
17 Expect(input).To(Or(true1, false2, true3))
18 Expect(input).To(Or(false1, true2, true3))
19 Expect(input).To(Or(true1, false2, false3))
20 Expect(input).To(Or(false1, false2, true3))
23 Expect(input).To(SatisfyAny(false1, false2, true3))
26 It("works with negative cases", func() {
27 Expect(input).ToNot(Or())
28 Expect(input).ToNot(Or(false1))
29 Expect(input).ToNot(Or(false1, false2))
30 Expect(input).ToNot(Or(false1, false2, false3))
33 Context("failure messages", func() {
34 Context("when match fails", func() {
35 It("gives a descriptive message", func() {
36 verifyFailureMessage(Or(false1, false2), input,
37 "To satisfy at least one of these matchers: [%!s(*matchers.HaveLenMatcher=&{1}) %!s(*matchers.EqualMatcher=&{hip})]")
41 Context("when match succeeds, but expected it to fail", func() {
42 It("gives a descriptive message", func() {
43 verifyFailureMessage(Not(Or(true1, true2)), input, `not to have length 2`)
48 Context("MatchMayChangeInTheFuture", func() {
49 Context("Match returned false", func() {
50 It("returns true if any of the matchers could change", func() {
51 // 3 matchers, all return false, and all could change
52 m := Or(BeNil(), Equal("hip"), HaveLen(1))
53 Expect(m.Match("hi")).To(BeFalse())
54 Expect(m.(*OrMatcher).MatchMayChangeInTheFuture("hi")).To(BeTrue()) // all 3 of these matchers default to 'true'
56 It("returns false if none of the matchers could change", func() {
57 // empty Or() has the property of never matching, and never can change since there are no sub-matchers that could change
59 Expect(m.Match("anything")).To(BeFalse())
60 Expect(m.(*OrMatcher).MatchMayChangeInTheFuture("anything")).To(BeFalse())
62 // Or() with 3 sub-matchers that return false, and can't change
63 m = Or(Or(), Or(), Or())
64 Expect(m.Match("hi")).To(BeFalse())
65 Expect(m.(*OrMatcher).MatchMayChangeInTheFuture("hi")).To(BeFalse()) // the 3 empty Or()'s won't change
68 Context("Match returned true", func() {
69 Context("returns value of the successful matcher", func() {
70 It("false if successful matcher not going to change", func() {
71 // 3 matchers: 1st returns false, 2nd returns true and is not going to change, 3rd is never called
72 m := Or(BeNil(), And(), Equal(1))
73 Expect(m.Match("hi")).To(BeTrue())
74 Expect(m.(*OrMatcher).MatchMayChangeInTheFuture("hi")).To(BeFalse())
76 It("true if successful matcher indicates it might change", func() {
77 // 3 matchers: 1st returns false, 2nd returns true and "might" change, 3rd is never called
78 m := Or(Not(BeNil()), Equal("hi"), Equal(1))
79 Expect(m.Match("hi")).To(BeTrue())
80 Expect(m.(*OrMatcher).MatchMayChangeInTheFuture("hi")).To(BeTrue()) // Equal("hi") indicates it might change