Skip to content

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

@Baccata

Description

@Baccata

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions