blob: 132480cfc5a23eeb07c8d3c4aef3219ab086a5e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package matchers_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/matchers"
)
var _ = Describe("BeEmpty", func() {
Context("when passed a supported type", func() {
It("should do the right thing", func() {
Expect("").Should(BeEmpty())
Expect(" ").ShouldNot(BeEmpty())
Expect([0]int{}).Should(BeEmpty())
Expect([1]int{1}).ShouldNot(BeEmpty())
Expect([]int{}).Should(BeEmpty())
Expect([]int{1}).ShouldNot(BeEmpty())
Expect(map[string]int{}).Should(BeEmpty())
Expect(map[string]int{"a": 1}).ShouldNot(BeEmpty())
c := make(chan bool, 1)
Expect(c).Should(BeEmpty())
c <- true
Expect(c).ShouldNot(BeEmpty())
})
})
Context("when passed a correctly typed nil", func() {
It("should be true", func() {
var nilSlice []int
Expect(nilSlice).Should(BeEmpty())
var nilMap map[int]string
Expect(nilMap).Should(BeEmpty())
})
})
Context("when passed an unsupported type", func() {
It("should error", func() {
success, err := (&BeEmptyMatcher{}).Match(0)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
success, err = (&BeEmptyMatcher{}).Match(nil)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
})
})
})
|