1package matchers_test 2 3import ( 4 . "github.com/onsi/ginkgo" 5 . "github.com/onsi/gomega" 6 . "github.com/onsi/gomega/matchers" 7) 8 9var _ = Describe("NotMatcher", func() { 10 Context("basic examples", func() { 11 It("works", func() { 12 Expect(input).To(Not(false1)) 13 Expect(input).To(Not(Not(true2))) 14 Expect(input).ToNot(Not(true3)) 15 Expect(input).ToNot(Not(Not(false1))) 16 Expect(input).To(Not(Not(Not(false2)))) 17 }) 18 }) 19 20 Context("De Morgan's laws", func() { 21 It("~(A && B) == ~A || ~B", func() { 22 Expect(input).To(Not(And(false1, false2))) 23 Expect(input).To(Or(Not(false1), Not(false2))) 24 }) 25 It("~(A || B) == ~A && ~B", func() { 26 Expect(input).To(Not(Or(false1, false2))) 27 Expect(input).To(And(Not(false1), Not(false2))) 28 }) 29 }) 30 31 Context("failure messages are opposite of original matchers' failure messages", func() { 32 Context("when match fails", func() { 33 It("gives a descriptive message", func() { 34 verifyFailureMessage(Not(HaveLen(2)), input, "not to have length 2") 35 }) 36 }) 37 38 Context("when match succeeds, but expected it to fail", func() { 39 It("gives a descriptive message", func() { 40 verifyFailureMessage(Not(Not(HaveLen(3))), input, "to have length 3") 41 }) 42 }) 43 }) 44 45 Context("MatchMayChangeInTheFuture()", func() { 46 It("Propagates value from wrapped matcher", func() { 47 m := Not(Or()) // an empty Or() always returns false, and indicates it cannot change 48 Expect(m.Match("anything")).To(BeTrue()) 49 Expect(m.(*NotMatcher).MatchMayChangeInTheFuture("anything")).To(BeFalse()) 50 }) 51 It("Defaults to true", func() { 52 m := Not(Equal(1)) // Equal does not have this method 53 Expect(m.Match(2)).To(BeTrue()) 54 Expect(m.(*NotMatcher).MatchMayChangeInTheFuture(2)).To(BeTrue()) // defaults to true 55 }) 56 }) 57}) 58