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

Contain exactly more detail (#26) #3849

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AlexCue987
Copy link
Contributor

improve output of shouldContainExactly, try to find matching sublists, just like git diff does, as follows:

            val expected = listOf(sweetGreenApple, sweetRedApple, sweetGreenPear)
            val actual = listOf(sweetGreenPear, sweetGreenApple, sweetRedApple)
            shouldThrow<AssertionError> {
               actual shouldContainExactly expected
            }.shouldHaveMessage("""
               |Collection should contain exactly: [Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet), Fruit(name=pear, color=green, taste=sweet)] but was: [Fruit(name=pear, color=green, taste=sweet), Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet)]
               |
               |Mismatch:
               |expected[0] = Fruit(name=pear, color=green, taste=sweet)
               |
               |Match:
               |expected[1] == actual[0]: Fruit(name=apple, color=green, taste=sweet)
               |expected[2] == actual[1]: Fruit(name=apple, color=red, taste=sweet)
               |
               |Mismatch:
               |actual[2] = Fruit(name=pear, color=green, taste=sweet)
               |
               |""".trimMargin())

@Kantis
Copy link
Member

Kantis commented Feb 27, 2024

@AlexCue987 Should this be refactored to use the similarity package now?

@AlexCue987
Copy link
Contributor Author

@AlexCue987 Should this be refactored to use the similarity package now?

of course, that's the plan. This will add more info to the output. No code will be removed, a couple lines will be added. As this PR is large as is, do we want to make it slightly larger, or should we add similarity in a later PR? WDYT @Kantis ?

@AlexCue987
Copy link
Contributor Author

so the enhanced message should look like this:

shouldHaveMessage("""
               |Collection should contain exactly: [Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet), Fruit(name=pear, color=green, taste=sweet)] but was: [Fruit(name=pear, color=green, taste=sweet), Fruit(name=apple, color=green, taste=sweet), Fruit(name=apple, color=red, taste=sweet)]
               |
               |Mismatch:
               |expected[0] = Fruit(name=pear, color=green, taste=sweet)
               |
               |Match:
               |expected[1] == actual[0]: Fruit(name=apple, color=green, taste=sweet)
               |expected[2] == actual[1]: Fruit(name=apple, color=red, taste=sweet)
               |
               |Mismatch:
               |actual[2] = Fruit(name=pear, color=green, taste=sweet)
               |
               | ----- <<< add similarity output here
               |""".trimMargin())

@sksamuel
Copy link
Member

There are conflicts on the merge.

@AlexCue987
Copy link
Contributor Author

There are conflicts on the merge.

just resolved a redeclaration. did I miss any other conflicts?

@AlexCue987
Copy link
Contributor Author

@AlexCue987 Should this be refactored to use the similarity package now?

this is the PR which adds search for similar elements in the same matcher: #3910
it adds some other useful output, not replacing the need for this one.

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