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

toContain matcher for Map #42

Merged
merged 15 commits into from
Jan 18, 2020
Merged

toContain matcher for Map #42

merged 15 commits into from
Jan 18, 2020

Conversation

eliasson
Copy link
Contributor

@eliasson eliasson commented Nov 26, 2019

Initial work to support .toContain and .toContainAllOf for Map.

@provegard, what do you think of the matcher style, and the output?

Still needed (although in separate PR's):

  • Support for mutable Map
  • Matcher for only key(s)
  • Equality matchers on complete Map

Part of #36

@eliasson eliasson requested a review from provegard November 26, 2019 22:06
Copy link
Collaborator

@provegard provegard left a comment

Choose a reason for hiding this comment

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

I like both matcher style and output!

Two comments I think need to be addressed (formatters + negative test case). The other are minor.

message += failingValues.map(p => s"${p._1} -> ${p._2} but found ${p._1} -> ${p._3}").mkString("\n ")
expect.fail(message)

private def describeActualWithContext(actual: Map[K, V]): String = "Map(...)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not much context here... ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope =)
What is a good context for a Map? Map(of 23 entries),Map[K, V] or to print a few keys (similar to Seq, and using the same cutoff)?

"when negated":
"error is described properly also for multiple elements" in:
runExpectation(
expect(Map("one" -> 1, "two" -> 2)).not.toContainAllOf("one" -> 1, "two" -> 2),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to have a test for the negation of toContainAllOf where:

  • Actual is one->1, two->2
  • Expected is one->1, three->3

In the positive case, this should be a failure, since actual doesn't contain three->3. Thus the negative case should be a success, I think. Does it work like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disagree. To not contain all of, should fail if >0 pairs are present in the Map.

Still, adding such a test case would be good, just with a slightly different result than what you propose ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, new year, new thoughts =)

I revisited this and I agree with your view and will add the following tests:

"when partially matching":
  "error is described properly" in:
    runExpectation(
      expect(Map("one" -> 1, "two" -> 2)).toContainAllOf("one" -> 1, "three" -> 3),
      """Expected Map(...) to contain:
      |  "three" -> 3""".stripMargin)
  "and negating":
    "should pass since Map is not missing both pairs" in:
      expect(Map("one" -> 1, "two" -> 2)).not.toContainAllOf("one" -> 1, "three" -> 3)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9a5f01

@eliasson eliasson requested a review from provegard November 27, 2019 22:23
@eliasson eliasson merged commit dba41df into master Jan 18, 2020
@eliasson eliasson deleted the map-matcher branch January 18, 2020 10:17
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.

2 participants