...

Source file src/github.com/onsi/gomega/matchers/have_len_matcher_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("HaveLen", func() {
    10  	When("passed a supported type", func() {
    11  		It("should do the right thing", func() {
    12  			Expect("").Should(HaveLen(0))
    13  			Expect("AA").Should(HaveLen(2))
    14  
    15  			Expect([0]int{}).Should(HaveLen(0))
    16  			Expect([2]int{1, 2}).Should(HaveLen(2))
    17  
    18  			Expect([]int{}).Should(HaveLen(0))
    19  			Expect([]int{1, 2, 3}).Should(HaveLen(3))
    20  
    21  			Expect(map[string]int{}).Should(HaveLen(0))
    22  			Expect(map[string]int{"a": 1, "b": 2, "c": 3, "d": 4}).Should(HaveLen(4))
    23  
    24  			c := make(chan bool, 3)
    25  			Expect(c).Should(HaveLen(0))
    26  			c <- true
    27  			c <- true
    28  			Expect(c).Should(HaveLen(2))
    29  		})
    30  	})
    31  
    32  	When("passed a correctly typed nil", func() {
    33  		It("should operate succesfully on the passed in value", func() {
    34  			var nilSlice []int
    35  			Expect(nilSlice).Should(HaveLen(0))
    36  
    37  			var nilMap map[int]string
    38  			Expect(nilMap).Should(HaveLen(0))
    39  		})
    40  	})
    41  
    42  	When("passed an unsupported type", func() {
    43  		It("should error", func() {
    44  			success, err := (&HaveLenMatcher{Count: 0}).Match(0)
    45  			Expect(success).Should(BeFalse())
    46  			Expect(err).Should(HaveOccurred())
    47  
    48  			success, err = (&HaveLenMatcher{Count: 0}).Match(nil)
    49  			Expect(success).Should(BeFalse())
    50  			Expect(err).Should(HaveOccurred())
    51  		})
    52  	})
    53  })
    54  

View as plain text