...

Source file src/github.com/onsi/gomega/matchers/not_test.go

Documentation: github.com/onsi/gomega/matchers

     1  package matchers_test
     2  
     3  import (
     4  	. "github.com/onsi/ginkgo/v2"
     5  	. "github.com/onsi/gomega"
     6  	. "github.com/onsi/gomega/matchers"
     7  )
     8  
     9  var _ = 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  		It("fails on error", func() {
    20  			failuresMessages := InterceptGomegaFailures(func() {
    21  				Expect(input).To(Not(Panic()))
    22  			})
    23  			Expect(failuresMessages).To(Equal([]string{"PanicMatcher expects a function.  Got:\n    <string>: hi"}))
    24  		})
    25  	})
    26  
    27  	Context("De Morgan's laws", func() {
    28  		It("~(A && B) == ~A || ~B", func() {
    29  			Expect(input).To(Not(And(false1, false2)))
    30  			Expect(input).To(Or(Not(false1), Not(false2)))
    31  		})
    32  		It("~(A || B) == ~A && ~B", func() {
    33  			Expect(input).To(Not(Or(false1, false2)))
    34  			Expect(input).To(And(Not(false1), Not(false2)))
    35  		})
    36  	})
    37  
    38  	Context("failure messages are opposite of original matchers' failure messages", func() {
    39  		When("match fails", func() {
    40  			It("gives a descriptive message", func() {
    41  				verifyFailureMessage(Not(HaveLen(2)), input, "not to have length 2")
    42  			})
    43  		})
    44  
    45  		When("match succeeds, but expected it to fail", func() {
    46  			It("gives a descriptive message", func() {
    47  				verifyFailureMessage(Not(Not(HaveLen(3))), input, "to have length 3")
    48  			})
    49  		})
    50  	})
    51  
    52  	Context("MatchMayChangeInTheFuture()", func() {
    53  		It("Propagates value from wrapped matcher", func() {
    54  			m := Not(Or()) // an empty Or() always returns false, and indicates it cannot change
    55  			Expect(m.Match("anything")).To(BeTrue())
    56  			Expect(m.(*NotMatcher).MatchMayChangeInTheFuture("anything")).To(BeFalse())
    57  		})
    58  		It("Defaults to true", func() {
    59  			m := Not(Equal(1)) // Equal does not have this method
    60  			Expect(m.Match(2)).To(BeTrue())
    61  			Expect(m.(*NotMatcher).MatchMayChangeInTheFuture(2)).To(BeTrue()) // defaults to true
    62  		})
    63  	})
    64  })
    65  

View as plain text