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