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

Add labels to prop produced from IsEq #2052

Merged
merged 1 commit into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ package cats.kernel.laws

import cats.kernel.Eq
import org.scalacheck.Prop
import org.scalacheck.util.Pretty

package object discipline {
implicit def catsLawsIsEqToProp[A](isEq: IsEq[A])(implicit ev: Eq[A]): Prop =
ev.eqv(isEq.lhs, isEq.rhs)
implicit def catsLawsIsEqToProp[A](isEq: IsEq[A])(implicit ev: Eq[A], pp: A => Pretty): Prop =
isEq match { case IsEq(x, y) =>
if (ev.eqv(x, y)) Prop.proved else Prop.falsified :| {
val exp = Pretty.pretty[A](y, Pretty.Params(0))
val act = Pretty.pretty[A](x, Pretty.Params(0))
s"Expected: $exp\n" + s"Received: $act"
}
}
}
3 changes: 2 additions & 1 deletion laws/src/main/scala/cats/laws/discipline/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cats
package laws

import org.scalacheck.Prop
import org.scalacheck.util.Pretty

package object discipline {

val SerializableTests = cats.kernel.laws.discipline.SerializableTests

implicit def catsLawsIsEqToProp[A: Eq](isEq: IsEq[A]): Prop =
implicit def catsLawsIsEqToProp[A: Eq](isEq: IsEq[A])(implicit pp: A => Pretty): Prop =
cats.kernel.laws.discipline.catsLawsIsEqToProp[A](isEq)
}