-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Hook Eq up to scalactic/scalatest's equality #522
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cats | ||
package tests | ||
|
||
import org.scalactic._ | ||
import TripleEqualsSupport.AToBEquivalenceConstraint | ||
import TripleEqualsSupport.BToAEquivalenceConstraint | ||
|
||
// The code in this file was taken and only slightly modified from | ||
// https://github.com/bvenners/equality-integration-demo | ||
// Thanks for the great examples, Bill! | ||
|
||
final class CatsEquivalence[T](T: Eq[T]) extends Equivalence[T] { | ||
def areEquivalent(a: T, b: T): Boolean = T.eqv(a, b) | ||
} | ||
|
||
trait LowPriorityStrictCatsConstraints extends TripleEquals { | ||
implicit def lowPriorityCatsCanEqual[A, B](implicit B: Eq[B], ev: A <:< B): CanEqual[A, B] = | ||
new AToBEquivalenceConstraint[A, B](new CatsEquivalence(B), ev) | ||
} | ||
|
||
trait StrictCatsEquality extends LowPriorityStrictCatsConstraints { | ||
override def convertToEqualizer[T](left: T): Equalizer[T] = super.convertToEqualizer[T](left) | ||
implicit override def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T] = new CheckingEqualizer(left) | ||
override def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B] = super.unconstrainedEquality[A, B] | ||
implicit def catsCanEqual[A, B](implicit A: Eq[A], ev: B <:< A): CanEqual[A, B] = | ||
new BToAEquivalenceConstraint[A, B](new CatsEquivalence(A), ev) | ||
} | ||
|
||
object StrictCatsEquality extends StrictCatsEquality |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ package cats | |
package tests | ||
|
||
import cats.std.AllInstances | ||
import cats.syntax.AllSyntax | ||
import cats.syntax.{AllSyntax, EqOps} | ||
import org.scalatest.{ FunSuite, PropSpec, Matchers } | ||
import org.scalatest.prop.PropertyChecks | ||
import org.typelevel.discipline.scalatest.Discipline | ||
|
@@ -16,13 +16,15 @@ import scala.util.{Failure, Success, Try} | |
* An opinionated stack of traits to improve consistency and reduce | ||
* boilerplate in Cats tests. | ||
*/ | ||
trait CatsSuite extends FunSuite with Matchers with Discipline with AllInstances with AllSyntax with TestInstances { | ||
trait CatsSuite extends FunSuite with Matchers with Discipline with AllInstances with AllSyntax with TestInstances with StrictCatsEquality { | ||
implicit override val generatorDrivenConfig: PropertyCheckConfiguration = | ||
PropertyCheckConfiguration( | ||
minSuccessful = Platform.minSuccessful, | ||
maxDiscardedFactor = Platform.maxDiscardedFactor) | ||
// disable scalatest's === | ||
override def convertToEqualizer[T](left: T): Equalizer[T] = ??? | ||
|
||
// disable Eq syntax (by making `eqSyntax` not implicit), since it collides | ||
// with scalactic's equality | ||
override def eqSyntax[A: Eq](a: A): EqOps[A] = new EqOps[A](a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per previous comment, consider moving this into its own trait in |
||
} | ||
|
||
trait CatsProps extends PropSpec with Matchers with PropertyChecks with TestInstances { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole file would be useful in tests that use the cats library, and not just cats itself. So, if that is the case, consider moving the file to
main
, so it could be exported - i.e.tests/shared/src/main/scala/cats/tests/CatsEquality.scala