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

Revamp expect.same and expect.eql to work against a Comparison abstraction. #15

Closed
Tracked by #1
Baccata opened this issue Mar 13, 2024 · 1 comment
Closed
Tracked by #1

Comments

@Baccata
Copy link
Collaborator

Baccata commented Mar 13, 2024

Currently, expect.same and expect.eql require two things : a cats.Eq and a cats.Show, which implies that the user has no power whatsoever over the rendering that happen when the comparison is negative.

These methods should be amended to take a sort of Comparison abstraction, that should be roughly isomorphic to

trait Comparison[A] {
   def diff(received: A, expected: A) : Option[String] 
} 

where None would indicate equality/equivalence, whereas Some would imply differences, and would contain a textual representation of the differences. This approach would offer a greater flexibility for users to inject different rendering logic based on the data types being compared. For instance, JSON Merge patch could be a suitable way to render of diff JSON values.

A default implicit instance of the comparison could be provided, relying on Eq and Show as before, but using some better algorithm than what's currently available in weaver-test 0.8.x. The myers diff algorithm, currently used by munit, seems to be an interesting contender.

From my shared experience with @keynmol having to rely on a third party like expecty for this kind of thing, I think it'd be preferable to roll our own implementation, in particular if it's reasonably approachable.

@Baccata
Copy link
Collaborator Author

Baccata commented Apr 26, 2024

Done by @zainab-ali

@Baccata Baccata closed this as completed Apr 26, 2024
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

No branches or pull requests

1 participant