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