Created
November 20, 2018 21:25
-
-
Save bancek/206befaa3cfb2eb040ef9852bc6f7284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gomegahelpers | |
import ( | |
"github.com/onsi/gomega/types" | |
) | |
func Transform(transform func(oldValue interface{}) interface{}, matcher types.GomegaMatcher) types.GomegaMatcher { | |
return &TransformMatcher{ | |
Transform: transform, | |
Matcher: matcher, | |
} | |
} | |
type TransformMatcher struct { | |
Transform func(oldValue interface{}) interface{} | |
Matcher types.GomegaMatcher | |
} | |
func (m *TransformMatcher) Match(actual interface{}) (success bool, err error) { | |
return m.Matcher.Match(m.Transform(actual)) | |
} | |
func (m *TransformMatcher) FailureMessage(actual interface{}) (message string) { | |
return m.Matcher.FailureMessage(m.Transform(actual)) | |
} | |
func (m *TransformMatcher) NegatedFailureMessage(actual interface{}) (message string) { | |
return m.Matcher.NegatedFailureMessage(m.Transform(actual)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment