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