Closed jibidus closed 8 months ago
This will fix #523 for Kotlin only.
I haven't had time to check the code yet, but as for
It would probably be more intuitive for jqwik users, to add this feature in anyForType(), but I'm not familiar enough with DefaultTypeArbitrary and TraverseArbitrary classes to be able to do that. Maybe with a little help…
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 if
:
if
should be in jqwik engine, where isSealed()
is not available (not in kotlin module.if
. Maybe in DefaultTraverseArbitrary
?… unless you were thinking of putting this if
in anyForType()
function? It would be better for jqwik users, but anyForSubtype()
have to return an instance of TypeArbitrary
, and this is one of the difficulties I have had to face.
unless you were thinking of putting this
if
inanyForType()
function? It would be better for jqwik users, butanyForSubtype()
have to return an instance ofTypeArbitrary
, and this is one of the difficulties I have had to face.
I think we can deal with this later. Let's get anyForSubtypeOf()
ready for release first.
- this
if
should be in jqwik engine, whereisSealed()
is not available (not in kotlin module.
Could https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-class/is-sealed.html do the trick?
I think the entry point for anyForSubtypeOf(..) should be in file
JqwikGlobals.kt
, next to anyForType.
Done (all moved in JqwikGlobals.kt
).
this if should be in jqwik engine, where isSealed() is not available (not in kotlin module).
Could https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-class/is-sealed.html do the trick?
This is what I meant by isSealed()
. We cannot use it from jqwik engine (where DefaultTypeArbitrary
or TypeTraverser
are located), right?
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?
I have no opinion.
With only anyForSubtypeOf()
in JqwikGlobals
, we follow a technical cohesion (with only entry points gathered in JqwikGlobals
). On the other side, with all components of anyForSubtypeOf
feature in the same place, we follow a functional cohesion.
It seems that the first one permits to follow convention of current codebase (which is great), whereas the second one permits to follow a better cohesion (based on functionalities, not on technical characteristics).
So I have no opinion. I have done what you suggest 🙂.
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.