-
-
Notifications
You must be signed in to change notification settings - Fork 64
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 anyForType() dedicated to sealed classes and interfaces in Kotlin module: anyForSubtypeOf() #555
Conversation
6cf1fed
to
6d8eb8f
Compare
This will fix #523 for Kotlin only. |
I haven't had time to check the code yet, but as for
maybe a simple if-clause could do, along the lines: if (targetType.isSealed()) {
return anyForSubtype(targetType)
}
... // do whatever was there in the first place
} |
I see many difficulties with this simple
… unless you were thinking of putting this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the entry point for anyForSubtypeOf(..)
should be in file JqwikGlobals.kt
, next to anyForType
. Of course, you can delegate from there to the real implementation in a different file.
I think we can deal with this later. Let's get |
Could |
Done (all moved in
This is what I meant by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the implementation is sufficiently complex I'd rather have it in a separate file and the function in JqwikGlobals
delegating to it. What do you think?
* } | ||
* ``` | ||
* @param enableArbitraryRecursion is applied to all created [TypeArbitrary]. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add api annotation:
@API(status = API.Status.EXPERIMENTAL, since = "1.8.4")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
inline fun <reified T> anyForSubtypeOf( | ||
enableArbitraryRecursion: Boolean = false, | ||
crossinline subtypeScope: SubtypeScope<T>.() -> Unit = {} | ||
): Arbitrary<T> where T : Any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to have TypeArbitrary<T>
as return type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would imply that custom arbitrary (registered with SubtypeScope<T>.provide()
) can only be TypeArbitrary<T>
. This would make custom arbitraries useless, wouldn't it?
175a776
to
e599a36
Compare
I have no opinion. With only So I have no opinion. |
Overview
anyForType()
does not support sealed classes or interfaces. The idea here is to support these cases with a dedicated functionanyForSubtypeOf()
for Kotlin only, since it is easier to implement than in Java.Details
anyForSubtypeOf()
useTypeArray
under the hood for each sealed subtypes, recursively:It is also possible to enable recursion with created
TypeArray
withenableArbitraryRecursion
, or to provide custom arbitraries for specific subtypes.Notable decisions
enableRecursion
is not handled through a fluent api (but with a parameter), which seems to be the common way to do such things in jqwik. I didn't succeed to implement this feature with a dedicated type (exSubtypeArbitrary
), which would permit to use a fluent api.AnyForSubtypeOfDsl.kt
(instead ofJqwikGlobals.kt
whereanyForType()
is declared).@Group
annotations, since sealed interface cannot be declared in inner classes.anyForType()
, but I'm not familiar enough withDefaultTypeArbitrary
andTraverseArbitrary
classes to be able to do that. Maybe with a little help…I hereby agree to the terms of the jqwik Contributor Agreement.