...

Source file src/github.com/onsi/gomega/matchers/contain_elements_matcher.go

Documentation: github.com/onsi/gomega/matchers

     1  package matchers
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onsi/gomega/format"
     7  	"github.com/onsi/gomega/matchers/support/goraph/bipartitegraph"
     8  )
     9  
    10  type ContainElementsMatcher struct {
    11  	Elements        []interface{}
    12  	missingElements []interface{}
    13  }
    14  
    15  func (matcher *ContainElementsMatcher) Match(actual interface{}) (success bool, err error) {
    16  	if !isArrayOrSlice(actual) && !isMap(actual) {
    17  		return false, fmt.Errorf("ContainElements matcher expects an array/slice/map.  Got:\n%s", format.Object(actual, 1))
    18  	}
    19  
    20  	matchers := matchers(matcher.Elements)
    21  	bipartiteGraph, err := bipartitegraph.NewBipartiteGraph(valuesOf(actual), matchers, neighbours)
    22  	if err != nil {
    23  		return false, err
    24  	}
    25  
    26  	edges := bipartiteGraph.LargestMatching()
    27  	if len(edges) == len(matchers) {
    28  		return true, nil
    29  	}
    30  
    31  	_, missingMatchers := bipartiteGraph.FreeLeftRight(edges)
    32  	matcher.missingElements = equalMatchersToElements(missingMatchers)
    33  
    34  	return false, nil
    35  }
    36  
    37  func (matcher *ContainElementsMatcher) FailureMessage(actual interface{}) (message string) {
    38  	message = format.Message(actual, "to contain elements", presentable(matcher.Elements))
    39  	return appendMissingElements(message, matcher.missingElements)
    40  }
    41  
    42  func (matcher *ContainElementsMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    43  	return format.Message(actual, "not to contain elements", presentable(matcher.Elements))
    44  }
    45  

View as plain text