-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #617 from fd4s/scala-3-1.x
Update 1.x to Scala 3 final
- Loading branch information
Showing
4 changed files
with
165 additions
and
14 deletions.
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
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,56 @@ | ||
/* | ||
* Copied verbatim from cats-testkit-scalatest (https://github.com/typelevel/cats-testkit-scalatest) | ||
* which is licensed as follows: | ||
* | ||
* Copyright (c) 2019 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copied verbatim from cats-testkit-scalatest (https://github.com/typelevel/cats-testkit-scalatest) | ||
* which is licensed as follows: | ||
* | ||
* Copyright (c) 2019 Typelevel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package cats | ||
package tests | ||
|
||
import cats.instances._ | ||
import cats.platform.Platform | ||
import cats.syntax._ | ||
import org.scalactic.anyvals.{PosInt, PosZDouble, PosZInt} | ||
import org.scalatest.funsuite.AnyFunSuiteLike | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.prop.Configuration | ||
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks | ||
import org.typelevel.discipline.scalatest.FunSuiteDiscipline | ||
|
||
trait TestSettings extends Configuration with Matchers { | ||
|
||
lazy val checkConfiguration: PropertyCheckConfiguration = | ||
PropertyCheckConfiguration( | ||
minSuccessful = if (Platform.isJvm) PosInt(50) else PosInt(5), | ||
maxDiscardedFactor = if (Platform.isJvm) PosZDouble(5.0) else PosZDouble(50.0), | ||
minSize = PosZInt(0), | ||
sizeRange = if (Platform.isJvm) PosZInt(10) else PosZInt(5), | ||
workers = if (Platform.isJvm) PosInt(2) else PosInt(1) | ||
) | ||
|
||
lazy val slowCheckConfiguration: PropertyCheckConfiguration = | ||
if (Platform.isJvm) checkConfiguration | ||
else PropertyCheckConfiguration(minSuccessful = 1, sizeRange = 1) | ||
} | ||
|
||
/** | ||
* An opinionated stack of traits to improve consistency and reduce | ||
* boilerplate in Cats tests. | ||
*/ | ||
trait CatsSuite | ||
extends AnyFunSuiteLike | ||
with Matchers | ||
with ScalaCheckDrivenPropertyChecks | ||
with FunSuiteDiscipline | ||
with TestSettings | ||
with AllInstances | ||
with AllInstancesBinCompat0 | ||
with AllInstancesBinCompat1 | ||
with AllInstancesBinCompat2 | ||
with AllInstancesBinCompat3 | ||
with AllInstancesBinCompat4 | ||
with AllInstancesBinCompat5 | ||
with AllSyntax | ||
with AllSyntaxBinCompat0 | ||
with AllSyntaxBinCompat1 | ||
with AllSyntaxBinCompat2 | ||
with AllSyntaxBinCompat3 | ||
with AllSyntaxBinCompat4 | ||
with AllSyntaxBinCompat5 | ||
with StrictCatsEquality { | ||
|
||
implicit override val generatorDrivenConfig: PropertyCheckConfiguration = | ||
checkConfiguration | ||
|
||
// disable Eq syntax (by making `catsSyntaxEq` not implicit), since it collides | ||
// with scalactic's equality | ||
override def catsSyntaxEq[A: Eq](a: A): EqOps[A] = new EqOps[A](a) | ||
|
||
def even(i: Int): Boolean = i % 2 == 0 | ||
|
||
val evenPf: PartialFunction[Int, Int] = { case i if even(i) => i } | ||
} | ||
|
||
trait SlowCatsSuite extends CatsSuite { | ||
implicit override val generatorDrivenConfig: PropertyCheckConfiguration = | ||
slowCheckConfiguration | ||
} |