Skip to content

Commit

Permalink
Require Comparison instance for eql and same.
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-ali committed Apr 3, 2024
1 parent d678cfa commit 09e8683
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
4 changes: 2 additions & 2 deletions modules/core/shared/src/main/scala/weaver/Comparison.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ trait Comparison[A] {
}

object Comparison {
def fromEqAndShow[A](
implicit eqv: Eq[A] = Eq.fromUniversalEquals[A],
implicit def fromEqAndShow[A](
implicit eqv: Eq[A],
showA: Show[A] = Show.fromToString[A]
): Comparison[A] = {
new Comparison[A] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ import cats.kernel.Eq
private[weaver] trait ExpectSame {

def eql[A](
expected: A,
found: A)(
implicit eqA: Eq[A],
showA: Show[A] = Show.fromToString[A],
loc: SourceLocation): Expectations = {
val comparison = Comparison.fromEqAndShow(eqA, showA)
diff(expected, found)(comparison, loc)
}

/**
* Same as eql but defaults to universal equality.
*/
def same[A](
expected: A,
found: A)(
implicit eqA: Eq[A] = Eq.fromUniversalEquals[A],
showA: Show[A] = Show.fromToString[A],
loc: SourceLocation): Expectations = eql(expected, found)(eqA, showA, loc)

def diff[A](
expected: A,
found: A)(
implicit comparisonA: Comparison[A],
Expand All @@ -42,4 +22,14 @@ private[weaver] trait ExpectSame {
new AssertionException(header + "\n\n" + diff, sourceLocs)))
}
}

/**
* Same as eql but defaults to universal equality.
*/
def same[A](
expected: A,
found: A)(
implicit loc: SourceLocation): Expectations = eql(expected, found)(
Comparison.fromEqAndShow(Eq.fromUniversalEquals, Show.fromToString),
loc)
}

0 comments on commit 09e8683

Please sign in to comment.