summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/matchers
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/onsi/gomega/matchers')
-rw-r--r--vendor/github.com/onsi/gomega/matchers/be_element_of_matcher.go22
-rw-r--r--vendor/github.com/onsi/gomega/matchers/with_transform.go19
2 files changed, 18 insertions, 23 deletions
diff --git a/vendor/github.com/onsi/gomega/matchers/be_element_of_matcher.go b/vendor/github.com/onsi/gomega/matchers/be_element_of_matcher.go
index 1f9d7a8e6..9ee75a5d5 100644
--- a/vendor/github.com/onsi/gomega/matchers/be_element_of_matcher.go
+++ b/vendor/github.com/onsi/gomega/matchers/be_element_of_matcher.go
@@ -18,23 +18,9 @@ func (matcher *BeElementOfMatcher) Match(actual interface{}) (success bool, err
return false, fmt.Errorf("BeElement matcher expects actual to be typed")
}
- length := len(matcher.Elements)
- valueAt := func(i int) interface{} {
- return matcher.Elements[i]
- }
- // Special handling of a single element of type Array or Slice
- if length == 1 && isArrayOrSlice(valueAt(0)) {
- element := valueAt(0)
- value := reflect.ValueOf(element)
- length = value.Len()
- valueAt = func(i int) interface{} {
- return value.Index(i).Interface()
- }
- }
-
var lastError error
- for i := 0; i < length; i++ {
- matcher := &EqualMatcher{Expected: valueAt(i)}
+ for _, m := range flatten(matcher.Elements) {
+ matcher := &EqualMatcher{Expected: m}
success, err := matcher.Match(actual)
if err != nil {
lastError = err
@@ -49,9 +35,9 @@ func (matcher *BeElementOfMatcher) Match(actual interface{}) (success bool, err
}
func (matcher *BeElementOfMatcher) FailureMessage(actual interface{}) (message string) {
- return format.Message(actual, "to be an element of", matcher.Elements)
+ return format.Message(actual, "to be an element of", presentable(matcher.Elements))
}
func (matcher *BeElementOfMatcher) NegatedFailureMessage(actual interface{}) (message string) {
- return format.Message(actual, "not to be an element of", matcher.Elements)
+ return format.Message(actual, "not to be an element of", presentable(matcher.Elements))
}
diff --git a/vendor/github.com/onsi/gomega/matchers/with_transform.go b/vendor/github.com/onsi/gomega/matchers/with_transform.go
index 8e58d8a0f..f3dec9101 100644
--- a/vendor/github.com/onsi/gomega/matchers/with_transform.go
+++ b/vendor/github.com/onsi/gomega/matchers/with_transform.go
@@ -40,15 +40,24 @@ func NewWithTransformMatcher(transform interface{}, matcher types.GomegaMatcher)
}
func (m *WithTransformMatcher) Match(actual interface{}) (bool, error) {
- // return error if actual's type is incompatible with Transform function's argument type
- actualType := reflect.TypeOf(actual)
- if !actualType.AssignableTo(m.transformArgType) {
- return false, fmt.Errorf("Transform function expects '%s' but we have '%s'", m.transformArgType, actualType)
+ // prepare a parameter to pass to the Transform function
+ var param reflect.Value
+ if actual != nil && reflect.TypeOf(actual).AssignableTo(m.transformArgType) {
+ // The dynamic type of actual is compatible with the transform argument.
+ param = reflect.ValueOf(actual)
+
+ } else if actual == nil && m.transformArgType.Kind() == reflect.Interface {
+ // The dynamic type of actual is unknown, so there's no way to make its
+ // reflect.Value. Create a nil of the transform argument, which is known.
+ param = reflect.Zero(m.transformArgType)
+
+ } else {
+ return false, fmt.Errorf("Transform function expects '%s' but we have '%T'", m.transformArgType, actual)
}
// call the Transform function with `actual`
fn := reflect.ValueOf(m.Transform)
- result := fn.Call([]reflect.Value{reflect.ValueOf(actual)})
+ result := fn.Call([]reflect.Value{param})
m.transformedValue = result[0].Interface() // expect exactly one value
return m.Matcher.Match(m.transformedValue)