mirror-to-gitea/vendor/github.com/onsi/gomega/matchers/have_cap_matcher.go
vendor/github.com/onsi/gomega/matchers/have_cap_matcher.goRaw
1// untested sections: 2
2
3package matchers
4
5import (
6 "fmt"
7
8 "github.com/onsi/gomega/format"
9)
10
11type HaveCapMatcher struct {
12 Count int
13}
14
15func (matcher *HaveCapMatcher) Match(actual interface{}) (success bool, err error) {
16 length, ok := capOf(actual)
17 if !ok {
18 return false, fmt.Errorf("HaveCap matcher expects a array/channel/slice. Got:\n%s", format.Object(actual, 1))
19 }
20
21 return length == matcher.Count, nil
22}
23
24func (matcher *HaveCapMatcher) FailureMessage(actual interface{}) (message string) {
25 return fmt.Sprintf("Expected\n%s\nto have capacity %d", format.Object(actual, 1), matcher.Count)
26}
27
28func (matcher *HaveCapMatcher) NegatedFailureMessage(actual interface{}) (message string) {
29 return fmt.Sprintf("Expected\n%s\nnot to have capacity %d", format.Object(actual, 1), matcher.Count)
30}