initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / have_len_matcher_test.go
1 package matchers_test
2
3 import (
4         . "github.com/onsi/ginkgo"
5         . "github.com/onsi/gomega"
6         . "github.com/onsi/gomega/matchers"
7 )
8
9 var _ = Describe("HaveLen", func() {
10         Context("when passed a supported type", func() {
11                 It("should do the right thing", func() {
12                         Ω("").Should(HaveLen(0))
13                         Ω("AA").Should(HaveLen(2))
14
15                         Ω([0]int{}).Should(HaveLen(0))
16                         Ω([2]int{1, 2}).Should(HaveLen(2))
17
18                         Ω([]int{}).Should(HaveLen(0))
19                         Ω([]int{1, 2, 3}).Should(HaveLen(3))
20
21                         Ω(map[string]int{}).Should(HaveLen(0))
22                         Ω(map[string]int{"a": 1, "b": 2, "c": 3, "d": 4}).Should(HaveLen(4))
23
24                         c := make(chan bool, 3)
25                         Ω(c).Should(HaveLen(0))
26                         c <- true
27                         c <- true
28                         Ω(c).Should(HaveLen(2))
29                 })
30         })
31
32         Context("when passed a correctly typed nil", func() {
33                 It("should operate succesfully on the passed in value", func() {
34                         var nilSlice []int
35                         Ω(nilSlice).Should(HaveLen(0))
36
37                         var nilMap map[int]string
38                         Ω(nilMap).Should(HaveLen(0))
39                 })
40         })
41
42         Context("when passed an unsupported type", func() {
43                 It("should error", func() {
44                         success, err := (&HaveLenMatcher{Count: 0}).Match(0)
45                         Ω(success).Should(BeFalse())
46                         Ω(err).Should(HaveOccurred())
47
48                         success, err = (&HaveLenMatcher{Count: 0}).Match(nil)
49                         Ω(success).Should(BeFalse())
50                         Ω(err).Should(HaveOccurred())
51                 })
52         })
53 })