-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fix isDataClassEqualTo
not working with data object
s
#552
base: main
Are you sure you want to change the base?
Fix isDataClassEqualTo
not working with data object
s
#552
Conversation
@@ -82,7 +82,7 @@ fun <T : Any> Assert<T>.isDataClassEqualTo(expected: T) = given { actual -> | |||
private fun <T> Assert<T>.isDataClassEqualToImpl(expected: T, kclass: KClass<*>?): Unit = given { actual -> | |||
if (actual == expected) return | |||
val compareProps = actual != null && expected != null | |||
if (compareProps && kclass != null && kclass.isData) { | |||
if (compareProps && kclass != null && kclass.isData && kclass.objectInstance == null) { |
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 seemed like the best way to check if kclass
is a data object
, but there could be a better way.
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.
could we check the types directly? This should always fail if expected::class != actual::class
right?
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.
Sure, how does this look?
val compareProps = actual != null && expected?.let { it::class } == kclass
if (compareProps && kclass != null && kclass.isData) {
val compareProps = actual != null && expected != null | ||
val compareProps = actual != null && expected?.let { it::class } == kclass | ||
if (compareProps && kclass != null && kclass.isData) { |
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 technically removes the expected != null
check, but it's essentially still done since we check for equality with kclass
which is then later checked not to be null
.
This fixes #551 by going right to
isEqualTo
if the passed value is adata object
.