Path: blob/main/vendor/github.com/onsi/gomega/matchers/contain_elements_matcher.go
2880 views
package matchers12import (3"fmt"45"github.com/onsi/gomega/format"6"github.com/onsi/gomega/matchers/internal/miter"7"github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"8)910type ContainElementsMatcher struct {11Elements []any12missingElements []any13}1415func (matcher *ContainElementsMatcher) Match(actual any) (success bool, err error) {16if !isArrayOrSlice(actual) && !isMap(actual) && !miter.IsIter(actual) {17return false, fmt.Errorf("ContainElements matcher expects an array/slice/map/iter.Seq/iter.Seq2. Got:\n%s", format.Object(actual, 1))18}1920matchers := matchers(matcher.Elements)21bipartiteGraph, err := bipartitegraph.NewBipartiteGraph(valuesOf(actual), matchers, neighbours)22if err != nil {23return false, err24}2526edges := bipartiteGraph.LargestMatching()27if len(edges) == len(matchers) {28return true, nil29}3031_, missingMatchers := bipartiteGraph.FreeLeftRight(edges)32matcher.missingElements = equalMatchersToElements(missingMatchers)3334return false, nil35}3637func (matcher *ContainElementsMatcher) FailureMessage(actual any) (message string) {38message = format.Message(actual, "to contain elements", presentable(matcher.Elements))39return appendMissingElements(message, matcher.missingElements)40}4142func (matcher *ContainElementsMatcher) NegatedFailureMessage(actual any) (message string) {43return format.Message(actual, "not to contain elements", presentable(matcher.Elements))44}454647