Path: blob/main/vendor/github.com/onsi/gomega/matchers/have_len_matcher.go
2880 views
package matchers12import (3"fmt"45"github.com/onsi/gomega/format"6)78type HaveLenMatcher struct {9Count int10}1112func (matcher *HaveLenMatcher) Match(actual any) (success bool, err error) {13length, ok := lengthOf(actual)14if !ok {15return false, fmt.Errorf("HaveLen matcher expects a string/array/map/channel/slice/iterator. Got:\n%s", format.Object(actual, 1))16}1718return length == matcher.Count, nil19}2021func (matcher *HaveLenMatcher) FailureMessage(actual any) (message string) {22return fmt.Sprintf("Expected\n%s\nto have length %d", format.Object(actual, 1), matcher.Count)23}2425func (matcher *HaveLenMatcher) NegatedFailureMessage(actual any) (message string) {26return fmt.Sprintf("Expected\n%s\nnot to have length %d", format.Object(actual, 1), matcher.Count)27}282930