Skip to content
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 objects #552

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

VirtualParticle
Copy link

@VirtualParticle VirtualParticle commented Oct 25, 2024

This fixes #551 by going right to isEqualTo if the passed value is a data object.

@@ -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) {
Copy link
Author

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.

Copy link
Collaborator

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?

Copy link
Author

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) {

Comment on lines -84 to 85
val compareProps = actual != null && expected != null
val compareProps = actual != null && expected?.let { it::class } == kclass
if (compareProps && kclass != null && kclass.isData) {
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isDataClassEqualTo passes when given different data objects
2 participants