github.com/onsi/gomega@v1.32.0/matchers/have_cap_matcher.go (about) 1 // untested sections: 2 2 3 package matchers 4 5 import ( 6 "fmt" 7 8 "github.com/onsi/gomega/format" 9 ) 10 11 type HaveCapMatcher struct { 12 Count int 13 } 14 15 func (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 24 func (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 28 func (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 }