Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
2880 views
1
package matchers
2
3
import (
4
"fmt"
5
6
"github.com/onsi/gomega/format"
7
)
8
9
type HaveLenMatcher struct {
10
Count int
11
}
12
13
func (matcher *HaveLenMatcher) Match(actual any) (success bool, err error) {
14
length, ok := lengthOf(actual)
15
if !ok {
16
return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice/iterator. Got:\n%s", format.Object(actual, 1))
17
}
18
19
return length == matcher.Count, nil
20
}
21
22
func (matcher *HaveLenMatcher) FailureMessage(actual any) (message string) {
23
return fmt.Sprintf("Expected\n%s\nto have length %d", format.Object(actual, 1), matcher.Count)
24
}
25
26
func (matcher *HaveLenMatcher) NegatedFailureMessage(actual any) (message string) {
27
return fmt.Sprintf("Expected\n%s\nnot to have length %d", format.Object(actual, 1), matcher.Count)
28
}
29
30