...

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

Documentation: github.com/onsi/gomega/matchers

     1  // untested sections: 1
     2  
     3  package matchers
     4  
     5  import (
     6  	"fmt"
     7  	"reflect"
     8  
     9  	"github.com/onsi/gomega/format"
    10  )
    11  
    12  type BeElementOfMatcher struct {
    13  	Elements []interface{}
    14  }
    15  
    16  func (matcher *BeElementOfMatcher) Match(actual interface{}) (success bool, err error) {
    17  	if reflect.TypeOf(actual) == nil {
    18  		return false, fmt.Errorf("BeElement matcher expects actual to be typed")
    19  	}
    20  
    21  	var lastError error
    22  	for _, m := range flatten(matcher.Elements) {
    23  		matcher := &EqualMatcher{Expected: m}
    24  		success, err := matcher.Match(actual)
    25  		if err != nil {
    26  			lastError = err
    27  			continue
    28  		}
    29  		if success {
    30  			return true, nil
    31  		}
    32  	}
    33  
    34  	return false, lastError
    35  }
    36  
    37  func (matcher *BeElementOfMatcher) FailureMessage(actual interface{}) (message string) {
    38  	return format.Message(actual, "to be an element of", presentable(matcher.Elements))
    39  }
    40  
    41  func (matcher *BeElementOfMatcher) NegatedFailureMessage(actual interface{}) (message string) {
    42  	return format.Message(actual, "not to be an element of", presentable(matcher.Elements))
    43  }
    44  

View as plain text