-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add conditional invert function with parameter to conditionally invert #2658
Comments
Do you have an example of the usage?
…On Fri, 19 Nov 2021, 20:44 Dale King, ***@***.***> wrote:
Sometimes you need to conditionally invert a matcher based on some data,
so depending on the data you might need to invert the matcher or you may
not. It occurs to me (and am writing an extension function to do it myself)
that it would be hander if the invert function on Matcher were written like
this:
fun invert(inverted: Boolean = true): Matcher<T> =
if(inverted)
Matcher {
with(test(it)) {
MatcherResult(!passed(), { negatedFailureMessage() }, { failureMessage() })
}
}
}
else this
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2658>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFVSGUMGYDUP5HVIZTRJKDUM4DRDANCNFSM5INNWSFA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
In my case I am using reflection to verify the characteristics of some properties on a data class are defined correctly. This is a boiled down version of my code. Say you have this data class:
I might use it like this:
which is using some reflective matchers I created on KProperty (let me know if you would like them to add to the library) |
Makes sense to add these I think. |
I fixed the definition in the first comment that swallowed the generic parameters. And if you are interested these are the reflective property matchers I mentioned:
|
Will be included in 5.1.0 |
Sometimes you need to conditionally invert a matcher based on some data, so depending on the data you might need to invert the matcher or you may not. It occurs to me (and am writing an extension function to do it myself) that it would be hander if there was a member or extension function that did this:
fun <T> Matcher<T>.invertIf(invert: Boolean): Matcher<T> = if(invert) invert() else this
The text was updated successfully, but these errors were encountered: