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

Add shouldContainAllIgnoringFields #3394

Conversation

sherviiin
Copy link
Contributor

Add shouldContainAllIgnoringFields() which compares collections ignoring one or more fields, in any order

Copy link
Member

@Kantis Kantis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall.

Consider handling large collections (AssertionsConfig.maxCollectionEnumerateSize)
Perhaps some KDoc on the assertions, as well as the kotest.io docs

What do you think about null-handling? Should this pass?

data class Person(val name: String, age: Int)

val sammy = Person("Sammy", 20)
val sara = Person("Sara", 27)

listOf(sammy, sara, null).shouldContainAllIgnoringFields(
  listOf(null, sara.copy(age = 28), sammy),
  Person::age
)

@sherviiin
Copy link
Contributor Author

sherviiin commented Feb 8, 2023

Thanks @Kantis ,
Added docs.
About maxCollectionEnumerateSize I'm wondering why it is not being used in other assertions 🤔
On the null topic: I prefer to align the most possible with shouldContainAll. That one ignores null AFAIK.

@Kantis
Copy link
Member

Kantis commented Feb 9, 2023

Thanks @Kantis , Added docs. About maxCollectionEnumerateSize I'm wondering why it is not being used in other assertions 🤔

I'm not sure why it's not used everywhere. I think it's been added incrementally whenever we had someone who cared enough about lack of readability in outputs :) but I would have to do some digging in git to get the whole picture.. Looking around a bit more I think we should probably use maxCollectionPrintSize in this case.

On the null topic: I prefer to align the most possible with shouldContainAll. That one ignores null AFAIK.

listOf(1, 2, null, 3, null).shouldContainAll(1, 2, null) // passes

listOf(1, 2, 3).shouldContainAll(1, 2, null)
// fails: Collection should contain all of [1, 2, <null>] but was missing [<null>]

@stale
Copy link

stale bot commented Mar 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale 🏚️ Issues that were lost to time and are no longer up-to-date label Mar 18, 2023
@stale stale bot closed this Mar 25, 2023
@sksamuel sksamuel reopened this Mar 25, 2023
@stale stale bot removed the stale 🏚️ Issues that were lost to time and are no longer up-to-date label Mar 25, 2023
@sksamuel
Copy link
Member

sksamuel commented Apr 2, 2023

@sherviiin do you mind adding maxCollectionPrintSize support and then we can merge.

@sherviiin
Copy link
Contributor Author

Hey @sksamuel ,
Added maxCollectionPrintSize in last commit.
Thanks for for reminding me about this.

@sksamuel sksamuel enabled auto-merge (squash) April 2, 2023 21:29
@sksamuel sksamuel merged commit 923128c into kotest:master Apr 12, 2023
18 checks passed
@sherviiin sherviiin deleted the feature/3393-Compare-collections-ignoring-fiields-in-any-order branch April 13, 2023 06:31
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.

None yet

3 participants