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

Re-encode relationships to avoid implicit conversion functions #3323

Merged
merged 1 commit into from
Feb 27, 2020
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 @@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
import cats.laws.discipline.arbitrary._

class NonEmptyLazyListSuite extends NonEmptyCollectionSuite[LazyList, NonEmptyLazyList, NonEmptyLazyListOps] {
def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyLazyList[A]): NonEmptyLazyListOps[A] = nea

checkAll("NonEmptyLazyList[Int]", SemigroupTests[NonEmptyLazyList[Int]].semigroup)
checkAll(s"Semigroup[NonEmptyLazyList]", SerializableTests.serializable(Semigroup[NonEmptyLazyList[Int]]))
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
import cats.laws.discipline.arbitrary._

class NonEmptyChainSuite extends NonEmptyCollectionSuite[Chain, NonEmptyChain, NonEmptyChainOps] {
def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
protected def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyChain[A]): NonEmptyChainOps[A] = nea

checkAll("NonEmptyChain[Int]", SemigroupKTests[NonEmptyChain].semigroupK[Int])
checkAll("SemigroupK[NonEmptyChain]", SerializableTests.serializable(SemigroupK[NonEmptyChain]))
Expand Down
12 changes: 7 additions & 5 deletions tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import org.scalacheck.Arbitrary

abstract class NonEmptyCollectionSuite[U[+_], NE[+_], NEC[x] <: NonEmptyCollection[x, U, NE]](
implicit arbitraryU: Arbitrary[U[Int]],
arbitraryNE: Arbitrary[NE[Int]],
ev: NE[Int] => NEC[Int],
evPair: NE[(Int, Int)] => NEC[(Int, Int)]
arbitraryNE: Arbitrary[NE[Int]]
) extends CatsSuite {
def toList[A](value: NE[A]): List[A]
def underlyingToList[A](underlying: U[A]): List[A]
protected def toList[A](value: NE[A]): List[A]
protected def underlyingToList[A](underlying: U[A]): List[A]

// Necessary because of the non-inheritance-based encoding of some non-empty collections.
protected def toNonEmptyCollection[A](nea: NE[A]): NEC[A]
implicit private def convertToNonEmptyCollection[A](nea: NE[A]): NEC[A] = toNonEmptyCollection(nea)

test("head is consistent with iterator.toList.head") {
forAll { (is: NE[Int]) =>
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import scala.collection.immutable.SortedMap
import scala.collection.immutable.SortedSet

class NonEmptyListSuite extends NonEmptyCollectionSuite[List, NonEmptyList, NonEmptyList] {
def toList[A](value: NonEmptyList[A]): List[A] = value.toList
def underlyingToList[A](underlying: List[A]): List[A] = underlying
protected def toList[A](value: NonEmptyList[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: List[A]): List[A] = underlying
protected def toNonEmptyCollection[A](nea: NonEmptyList[A]): NonEmptyList[A] = nea

// Lots of collections here.. telling ScalaCheck to calm down a bit
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
Expand Down
5 changes: 3 additions & 2 deletions tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import cats.platform.Platform
import scala.util.Properties

class NonEmptyVectorSuite extends NonEmptyCollectionSuite[Vector, NonEmptyVector, NonEmptyVector] {
def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
protected def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
protected def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
protected def toNonEmptyCollection[A](nea: NonEmptyVector[A]): NonEmptyVector[A] = nea

// Lots of collections here.. telling ScalaCheck to calm down a bit
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
Expand Down