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

Collection assertions #2695

Merged
merged 13 commits into from
Mar 12, 2022
Merged

Collection assertions #2695

merged 13 commits into from
Mar 12, 2022

Conversation

Kantis
Copy link
Member

@Kantis Kantis commented Nov 29, 2021

Highlights:

  • Deprecates shouldExist in favor of forAny
  • Adds forSingle inspector, that asserts that a collection has a single element, which matches the assertion
  • Adds lambda-based alternatives to predicate-based existInOrder matcher
    • matchEach 1:1 match element:assertion
    • matchInOrder assert in order, with no gaps
    • matchInOrderSubset assert in order, gaps allowed

@Kantis
Copy link
Member Author

Kantis commented Nov 30, 2021

Any feedback on the naming of existInAssertedOrder()?

I would ideally have liked to use existInOrder(assertions: List<(T) -> Unit>) for this one as well, but it seemed to clash with the existing existInOrder(ps: List<(T) -> Boolean>)

@sksamuel
Copy link
Member

I don't like the name existInAssertedOrder.
Perhaps shouldAssertInOrder but we need one that works with gaps and one that doesn't.

shouldAssertSubset <- gaps ?
shouldAssert <- no gaps ?

@Kantis
Copy link
Member Author

Kantis commented Nov 30, 2021

shouldAssert means the matcher would be named assert? I think that might be confusing?

Maybe shouldFullyMatch, shouldPartiallyMatch? 🤔

I agree it would be nice to offer both a complete match opportunity, and a subset match.. Perhaps it would also be nice to be able to specify if they shouold exist in order or not..

@sksamuel
Copy link
Member

sksamuel commented Nov 30, 2021 via email

@Kantis
Copy link
Member Author

Kantis commented Nov 30, 2021

shouldMatchInOrder - Test vararg of assertions against collection, does not require exhaustive test
shouldMatchInOrderWithoutGaps - same as above, disallowing gaps
shouldMatchAll - same as above, but must be exhaustive for the list. E..g assertion 1 must pass element 1, and one assertion must exist for each element

Matchers would then be matchAll and matchInOrder, latter taking a parameter to decide whether gaps are allowed.

Do you prefer another verb?

@Kantis Kantis marked this pull request as draft December 1, 2021 23:34
@sksamuel
Copy link
Member

I think those names should good, and maybe shouldMatchInOrderWithoutGaps could be shouldMatchInOrderSubset

@sksamuel sksamuel added this to the 5.1 milestone Dec 18, 2021
@sksamuel
Copy link
Member

@Kantis can you rebase whenever you're able :)

@sksamuel
Copy link
Member

@Kantis do you have time to finish this up for 5.1 release this week?
If not I can move to 5.2

@Kantis
Copy link
Member Author

Kantis commented Jan 12, 2022

@Kantis do you have time to finish this up for 5.1 release this week? If not I can move to 5.2

I'll try ✌🏼 Sorry for not responding for a while, I mentally checked out over the holidays

@sksamuel
Copy link
Member

sksamuel commented Jan 12, 2022 via email

@sksamuel sksamuel modified the milestones: 5.1, 5.2 Jan 16, 2022
@Kantis Kantis marked this pull request as ready for review February 15, 2022 23:24
@Kantis Kantis requested a review from sksamuel March 7, 2022 19:57
@Kantis
Copy link
Member Author

Kantis commented Mar 7, 2022

@sksamuel this one's ready ✌🏼

@sksamuel
Copy link
Member

It's been a while :)
Can you remind me what the matchEach is solving again.

@sksamuel sksamuel mentioned this pull request Mar 12, 2022
22 tasks
@sksamuel sksamuel merged commit e7097a3 into master Mar 12, 2022
@sksamuel sksamuel deleted the collection-assertions branch March 12, 2022 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants