aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/onsi/gomega/matchers/have_len_matcher_test.go
blob: 1e6aa69d9d174895e935731b957918b55edacac5 (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
53
package matchers_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/matchers"
)

var _ = Describe("HaveLen", func() {
	Context("when passed a supported type", func() {
		It("should do the right thing", func() {
			Ω("").Should(HaveLen(0))
			Ω("AA").Should(HaveLen(2))

			Ω([0]int{}).Should(HaveLen(0))
			Ω([2]int{1, 2}).Should(HaveLen(2))

			Ω([]int{}).Should(HaveLen(0))
			Ω([]int{1, 2, 3}).Should(HaveLen(3))

			Ω(map[string]int{}).Should(HaveLen(0))
			Ω(map[string]int{"a": 1, "b": 2, "c": 3, "d": 4}).Should(HaveLen(4))

			c := make(chan bool, 3)
			Ω(c).Should(HaveLen(0))
			c <- true
			c <- true
			Ω(c).Should(HaveLen(2))
		})
	})

	Context("when passed a correctly typed nil", func() {
		It("should operate succesfully on the passed in value", func() {
			var nilSlice []int
			Ω(nilSlice).Should(HaveLen(0))

			var nilMap map[int]string
			Ω(nilMap).Should(HaveLen(0))
		})
	})

	Context("when passed an unsupported type", func() {
		It("should error", func() {
			success, err := (&HaveLenMatcher{Count: 0}).Match(0)
			Ω(success).Should(BeFalse())
			Ω(err).Should(HaveOccurred())

			success, err = (&HaveLenMatcher{Count: 0}).Match(nil)
			Ω(success).Should(BeFalse())
			Ω(err).Should(HaveOccurred())
		})
	})
})