From 7a4ba0bc559e0b3d7cd34c1330994e2fb7c6f099 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 02:50:42 +0200 Subject: [PATCH 01/29] Simplify ApplicativeSuite --- .../scala-3/cats/derived/ApplicativeSuite.scala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 562d6ff1..32f63b9d 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -26,18 +26,21 @@ class ApplicativeSuite extends KittensSuite: import ApplicativeSuite.* import TestDefns.* - inline def applicativeTests[F[_]](f: Isomorphisms[F] ?=> (at: ApplicativeTests[F]) => at.RuleSet) = - f(using summonInline)(ApplicativeTests[F](summonInline)) + inline given [F[_]]: Isomorphisms[F] = + Isomorphisms.invariant(summonInline[Applicative[F]]) + + inline def applicativeTests[F[_]]: ApplicativeTests[F] = + ApplicativeTests[F](summonInline) inline def testApplicative(inline context: String): Unit = checkAll( s"$context.Applicative[CaseClassWOption]", - applicativeTests[CaseClassWOption](_.applicative[Int, String, Long]) + applicativeTests[CaseClassWOption].applicative[Int, String, Long] ) - checkAll(s"$context.Applicative[OptList]", applicativeTests[OptList](_.applicative[Int, String, Long])) - checkAll(s"$context.Applicative[AndInt]", applicativeTests[AndInt](_.applicative[Int, String, Long])) - checkAll(s"$context.Applicative[Interleaved]", applicativeTests[Interleaved](_.applicative[Int, String, Long])) - checkAll(s"$context.Applicative[ListBox]", applicativeTests[ListBox](_.applicative[Int, String, Long])) + checkAll(s"$context.Applicative[OptList]", applicativeTests[OptList].applicative[Int, String, Long]) + checkAll(s"$context.Applicative[AndInt]", applicativeTests[AndInt].applicative[Int, String, Long]) + checkAll(s"$context.Applicative[Interleaved]", applicativeTests[Interleaved].applicative[Int, String, Long]) + checkAll(s"$context.Applicative[ListBox]", applicativeTests[ListBox].applicative[Int, String, Long]) checkAll( s"$context.Applicative is Serializable", SerializableTests.serializable(summonInline[Applicative[Interleaved]]) From fe6afce5c823c96ce4f0b6af14a578ac36c4acae Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 04:23:15 +0200 Subject: [PATCH 02/29] Extend ApplicativeSuite with derived cases --- .../cats/derived/ApplicativeSuite.scala | 47 ++++++++++++------- .../scala-3/cats/derived/KittensSuite.scala | 10 +++- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 32f63b9d..0eea2161 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -19,6 +19,7 @@ package cats.derived import cats.Applicative import cats.laws.discipline.* import cats.laws.discipline.SemigroupalTests.Isomorphisms +import org.scalacheck.Arbitrary import scala.compiletime.* @@ -29,31 +30,36 @@ class ApplicativeSuite extends KittensSuite: inline given [F[_]]: Isomorphisms[F] = Isomorphisms.invariant(summonInline[Applicative[F]]) - inline def applicativeTests[F[_]]: ApplicativeTests[F] = + inline def tests[F[_]]: ApplicativeTests[F] = ApplicativeTests[F](summonInline) - inline def testApplicative(inline context: String): Unit = - checkAll( - s"$context.Applicative[CaseClassWOption]", - applicativeTests[CaseClassWOption].applicative[Int, String, Long] - ) - checkAll(s"$context.Applicative[OptList]", applicativeTests[OptList].applicative[Int, String, Long]) - checkAll(s"$context.Applicative[AndInt]", applicativeTests[AndInt].applicative[Int, String, Long]) - checkAll(s"$context.Applicative[Interleaved]", applicativeTests[Interleaved].applicative[Int, String, Long]) - checkAll(s"$context.Applicative[ListBox]", applicativeTests[ListBox].applicative[Int, String, Long]) - checkAll( - s"$context.Applicative is Serializable", - SerializableTests.serializable(summonInline[Applicative[Interleaved]]) - ) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) + checkAll(s"$instance[OptList]", tests[OptList].applicative[Int, String, Long]) + checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].applicative[Int, String, Long]) + checkAll(s"$instance[ListBox]", tests[ListBox].applicative[Int, String, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Applicative[Interleaved]])) locally { import auto.applicative.given - testApplicative("auto") + validate("auto.applicative") } locally { - import semiInstances.given - testApplicative("semiauto") + import semiApplicative.given + validate("semiauto.applicative") + } + + locally { + import derivedApplicative.* + val instance = "derived.applicative" + + // Copy pasted from `validate` + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) + checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].applicative[Int, String, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Applicative[Interleaved]])) } end ApplicativeSuite @@ -65,7 +71,7 @@ object ApplicativeSuite: type AndInt[A] = (A, Int) type ListBox[A] = List[Box[A]] - object semiInstances: + object semiApplicative: given Applicative[Box] = semiauto.applicative given Applicative[CaseClassWOption] = semiauto.applicative given Applicative[OptList] = semiauto.applicative @@ -73,4 +79,9 @@ object ApplicativeSuite: given Applicative[Interleaved] = semiauto.applicative given Applicative[ListBox] = semiauto.applicative + object derivedApplicative: + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Applicative + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Applicative + case class AndInt[A](x: ApplicativeSuite.AndInt[A]) derives Applicative + end ApplicativeSuite diff --git a/core/src/test/scala-3/cats/derived/KittensSuite.scala b/core/src/test/scala-3/cats/derived/KittensSuite.scala index 672656be..fc8451bc 100644 --- a/core/src/test/scala-3/cats/derived/KittensSuite.scala +++ b/core/src/test/scala-3/cats/derived/KittensSuite.scala @@ -16,18 +16,23 @@ package cats.derived +import cats.Eq import cats.platform.Platform import cats.syntax.AllSyntax import munit.DisciplineSuite import org.scalacheck.Arbitrary import org.scalacheck.Test.Parameters +import scala.deriving.Mirror import scala.quoted.* /** An opinionated stack of traits to improve consistency and reduce boilerplate in Kittens tests. Note that unlike the * corresponding CatsSuite in the Cat project, this trait does not mix in any instances. */ -abstract class KittensSuite extends KittensSuite.WithoutEq, TestEqInstances +abstract class KittensSuite extends KittensSuite.WithoutEq, TestEqInstances: + given [A <: Product](using mirror: Mirror.ProductOf[A], via: Eq[mirror.MirroredElemTypes]): Eq[A] = + Eq.by(Tuple.fromProductTyped) + object KittensSuite: def deCapitalizeMacro(str: Expr[String])(using Quotes) = val value = str.valueOrAbort @@ -48,6 +53,9 @@ object KittensSuite: given [A: Arbitrary]: Arbitrary[List[A]] = Arbitrary.arbContainer + given [A <: Product](using mirror: Mirror.ProductOf[A], via: Arbitrary[mirror.MirroredElemTypes]): Arbitrary[A] = + Arbitrary(via.arbitrary.map(mirror.fromTuple)) + inline def testNoInstance(inline tc: String, target: String, message: String): Unit = val errors = compileErrors(tc + "[" + target + "]") test(s"No $tc for $target")(assert(errors.contains(message), s"$errors did not contain $message")) From 287eebd3f9e7f64215fa7459ea6662e7db48d8c8 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 04:35:40 +0200 Subject: [PATCH 03/29] Extend ApplySuite with derived cases --- .../cats/derived/ApplicativeSuite.scala | 1 - .../scala-3/cats/derived/ApplySuite.scala | 39 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 0eea2161..91b74069 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -54,7 +54,6 @@ class ApplicativeSuite extends KittensSuite: locally { import derivedApplicative.* val instance = "derived.applicative" - // Copy pasted from `validate` checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) diff --git a/core/src/test/scala-3/cats/derived/ApplySuite.scala b/core/src/test/scala-3/cats/derived/ApplySuite.scala index f75f2a42..81becf22 100644 --- a/core/src/test/scala-3/cats/derived/ApplySuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplySuite.scala @@ -28,25 +28,35 @@ class ApplySuite extends KittensSuite: inline given [F[_]]: Isomorphisms[F] = Isomorphisms.invariant(summonInline[Apply[F]]) - inline def applyTests[F[_]]: ApplyTests[F] = + inline def tests[F[_]]: ApplyTests[F] = ApplyTests[F](summonInline) - inline def testApply(inline context: String): Unit = - checkAll(s"$context.Apply[CaseClassWOption]", applyTests[CaseClassWOption].apply[Int, String, Long]) - checkAll(s"$context.Apply[OptList]", applyTests[OptList].apply[Int, String, Long]) - checkAll(s"$context.Apply[AndInt]", applyTests[AndInt].apply[Int, String, Long]) - checkAll(s"$context.Apply[Interleaved]", applyTests[Interleaved].apply[Int, String, Long]) - checkAll(s"$context.Apply[ListBox]", applyTests[ListBox].apply[Int, String, Long]) - checkAll(s"$context.Apply is Serializable", SerializableTests.serializable(summonInline[Apply[Interleaved]])) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].apply[Int, String, Long]) + checkAll(s"$instance[OptList]", tests[OptList].apply[Int, String, Long]) + checkAll(s"$instance[AndInt]", tests[AndInt].apply[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].apply[Int, String, Long]) + checkAll(s"$instance[ListBox]", tests[ListBox].apply[Int, String, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Apply[Interleaved]])) locally { import auto.apply.given - testApply("auto") + validate("auto.apply") } locally { - import semiInstances.given - testApply("semiauto") + import semiApply.given + validate("semiauto.apply") + } + + locally { + import derivedApply.* + val instance = "derived.apply" + // Copy pasted from `validate` + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].apply[Int, String, Long]) + checkAll(s"$instance[AndInt]", tests[AndInt].apply[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].apply[Int, String, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Apply[Interleaved]])) } end ApplySuite @@ -58,7 +68,7 @@ object ApplySuite: type AndInt[A] = (A, Int) type ListBox[A] = List[Box[A]] - object semiInstances: + object semiApply: given Apply[Box] = semiauto.apply given Apply[CaseClassWOption] = semiauto.apply given Apply[OptList] = semiauto.apply @@ -66,4 +76,9 @@ object ApplySuite: given Apply[Interleaved] = semiauto.apply given Apply[ListBox] = semiauto.apply + object derivedApply: + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Apply + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Apply + case class AndInt[A](x: ApplySuite.AndInt[A]) derives Apply + end ApplySuite From 24acf9d70067a0bf2baf784ec5cdb365162e7b17 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 04:45:04 +0200 Subject: [PATCH 04/29] Extends CommutativeMonoidSuite with derived cases --- .../cats/derived/CommutativeMonoidSuite.scala | 47 ++++++++++++++----- .../cats/derived/CommutativeMonoidTests.scala | 8 ---- 2 files changed, 35 insertions(+), 20 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/CommutativeMonoidTests.scala diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index c4e14cb5..ce3a0354 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -27,31 +27,48 @@ class CommutativeMonoidSuite extends KittensSuite: import CommutativeMonoidSuite.* import TestDefns.* - inline def commutativeMonoidTests[A]: CommutativeMonoidTests[A] = + inline def tests[A]: CommutativeMonoidTests[A] = CommutativeMonoidTests[A](summonInline) - inline def testCommutativeMonoid(inline context: String): Unit = - checkAll(s"$context.CommutativeMonoid[Foo]", commutativeMonoidTests[CommutativeFoo].commutativeMonoid) - checkAll(s"$context.CommutativeMonoid[Recursive]", commutativeMonoidTests[Recursive].commutativeMonoid) - checkAll(s"$context.CommutativeMonoid[Box[Mul]]", commutativeMonoidTests[Box[Mul]].commutativeMonoid) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeMonoid) + checkAll(s"$instance[Recursive]", tests[Recursive].commutativeMonoid) + checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeMonoid) checkAll( - s"$context.CommutativeMonoid is Serializable", + s"$instance is Serializable", SerializableTests.serializable(summonInline[CommutativeMonoid[CommutativeFoo]]) ) - test(s"$context.CommutativeMonoid respects existing instances") { - val box = summonInline[CommutativeMonoid[Box[Mul]]] + test(s"$instance respects existing instances") { + val box = summonInline[CommutativeMonoid[BoxMul]] assert(box.empty == Box(Mul(1))) assert(box.combine(Box(Mul(5)), Box(Mul(5))) == Box(Mul(25))) } locally { import auto.commutativeMonoid.given - testCommutativeMonoid("auto") + validate("auto.commutativeMonoid") } locally { - import semiInstances.given - testCommutativeMonoid("semiauto") + import semiCommutativeMonoid.given + validate("semiauto.commutativeMonoid") + } + + locally { + import derivedCommutativeMonoid.* + val instance = "derived.commutativeMonoid" + // Copy pasted from `validate` + checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeMonoid) + checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeMonoid) + checkAll( + s"$instance is Serializable", + SerializableTests.serializable(summonInline[CommutativeMonoid[CommutativeFoo]]) + ) + test(s"$instance respects existing instances") { + val box = summonInline[CommutativeMonoid[BoxMul]] + assert(box.empty == BoxMul(Box(Mul(1)))) + assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))) == BoxMul(Box(Mul(25)))) + } } end CommutativeMonoidSuite @@ -59,11 +76,17 @@ end CommutativeMonoidSuite object CommutativeMonoidSuite: import TestDefns.* - object semiInstances: + type BoxMul = Box[Mul] + + object semiCommutativeMonoid: given CommutativeMonoid[CommutativeFoo] = semiauto.commutativeMonoid given CommutativeMonoid[Recursive] = semiauto.commutativeMonoid given CommutativeMonoid[Box[Mul]] = semiauto.commutativeMonoid + object derivedCommutativeMonoid: + case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeMonoid + case class BoxMul(x: CommutativeMonoidSuite.BoxMul) derives CommutativeMonoid + final case class Mul(value: Int) object Mul: given Eq[Mul] = Eq.fromUniversalEquals diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidTests.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidTests.scala deleted file mode 100644 index 96c2914f..00000000 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidTests.scala +++ /dev/null @@ -1,8 +0,0 @@ -package cats.derived - -import cats.kernel.CommutativeMonoid -import cats.derived.* - -class CommutativeMonoidTests { // - case class Foo(i: Int, b: Option[Int]) derives CommutativeMonoid -} From fcb642d448d1bdf2eafee9ed9032a6933d0be794 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 04:51:22 +0200 Subject: [PATCH 05/29] Extends CommutativeSemigroupSuite with derived cases --- .../derived/CommutativeSemigroupSuite.scala | 51 +++++++++++++------ .../derived/CommutativeSemigroupTests.scala | 8 --- 2 files changed, 35 insertions(+), 24 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/CommutativeSemigroupTests.scala diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index 1ce03dc2..64fbcc0a 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -27,33 +27,46 @@ class CommutativeSemigroupSuite extends KittensSuite: import CommutativeSemigroupSuite.* import TestDefns.* - inline def commutativeSemigroupTests[A]: CommutativeSemigroupTests[A] = + inline def tests[A]: CommutativeSemigroupTests[A] = CommutativeSemigroupTests[A](summonInline) - inline def testCommutativeSemigroup(inline context: String): Unit = + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeSemigroup) + checkAll(s"$instance[Recursive]", tests[Recursive].commutativeSemigroup) + checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeSemigroup) checkAll( - s"$context.CommutativeSemigroup[CommutativeFoo]", - commutativeSemigroupTests[CommutativeFoo].commutativeSemigroup - ) - checkAll(s"$context.CommutativeSemigroup[Recursive]", commutativeSemigroupTests[Recursive].commutativeSemigroup) - checkAll(s"$context.CommutativeSemigroup[Box[Mul]]", commutativeSemigroupTests[Box[Mul]].commutativeSemigroup) - checkAll( - s"$context.CommutativeSemigroup is Serializable", + s"$instance is Serializable", SerializableTests.serializable(summonInline[CommutativeSemigroup[CommutativeFoo]]) ) - test(s"$context.CommutativeSemigroup respects existing instances") { - val box = summonInline[CommutativeSemigroup[Box[Mul]]] + test(s"$instance respects existing instances") { + val box = summonInline[CommutativeSemigroup[BoxMul]] assert(box.combine(Box(Mul(5)), Box(Mul(5))).content.value == 25) } locally { import auto.commutativeSemigroup.given - testCommutativeSemigroup("auto") + validate("auto.commutativeSemigroup") } locally { - import semiInstances.given - testCommutativeSemigroup("semiauto") + import semiCommutativeSemigroup.given + validate("semiauto.commutativeSemigroup") + } + + locally { + import derivedCommutativeSemigroup.* + val instance = "derived.commutativeSemigroup" + // Copy pasted from `validate` + checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeSemigroup) + checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeSemigroup) + checkAll( + s"$instance is Serializable", + SerializableTests.serializable(summonInline[CommutativeSemigroup[CommutativeFoo]]) + ) + test(s"$instance respects existing instances") { + val box = summonInline[CommutativeSemigroup[BoxMul]] + assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))).x.content.value == 25) + } } end CommutativeSemigroupSuite @@ -61,10 +74,16 @@ end CommutativeSemigroupSuite object CommutativeSemigroupSuite: import TestDefns.* - object semiInstances: + type BoxMul = Box[Mul] + + object semiCommutativeSemigroup: given CommutativeSemigroup[CommutativeFoo] = semiauto.commutativeSemigroup given CommutativeSemigroup[Recursive] = semiauto.commutativeSemigroup - given CommutativeSemigroup[Box[Mul]] = semiauto.commutativeSemigroup + given CommutativeSemigroup[BoxMul] = semiauto.commutativeSemigroup + + object derivedCommutativeSemigroup: + case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeSemigroup + case class BoxMul(x: CommutativeSemigroupSuite.BoxMul) derives CommutativeSemigroup final case class Mul(value: Int) object Mul: diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupTests.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupTests.scala deleted file mode 100644 index e790e0cf..00000000 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupTests.scala +++ /dev/null @@ -1,8 +0,0 @@ -package cats.derived - -import cats.kernel.CommutativeSemigroup -import cats.derived.* - -class CommutativeSemigroupTests { // - case class Foo(i: Int, b: Option[Int]) derives CommutativeSemigroup -} From 790fce5ad764d2e17544ad48998ee382310d6098 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 05:22:48 +0200 Subject: [PATCH 06/29] Extend ContravariantSuite with derived cases --- .../cats/derived/ContravariantSuite.scala | 79 ++++++++----------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index bcf5084c..2f466571 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -26,41 +26,22 @@ class ContravariantSuite extends KittensSuite: import ContravariantSuite.* import TestDefns.* - inline def contravariantTests[F[_]]: ContravariantTests[F] = + inline def tests[F[_]]: ContravariantTests[F] = ContravariantTests[F](summonInline) - inline def testContravariant(context: String): Unit = - checkAll(s"$context.Contravariant[OptPred]", contravariantTests[OptPred].contravariant[MiniInt, String, Boolean]) - checkAll(s"$context.Contravariant[TreePred]", contravariantTests[TreePred].contravariant[MiniInt, String, Boolean]) - checkAll(s"$context.Contravariant[ListPred]", contravariantTests[ListPred].contravariant[MiniInt, String, Boolean]) - checkAll( - s"$context.Contravariant[GenericAdtPred]", - contravariantTests[GenericAdtPred].contravariant[MiniInt, String, Boolean] - ) + inline def validate(instance: String): Unit = + checkAll(s"$instance[OptPred]", tests[OptPred].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[TreePred]", tests[TreePred].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[ListPred]", tests[ListPred].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[GenericAdtPred]", tests[GenericAdtPred].contravariant[MiniInt, String, Boolean]) // TODO https://github.com/typelevel/kittens/issues/473 - // checkAll( - // s"$context.Contravariant[InterleavedPred]", - // contravariantTests[InterleavedPred].contravariant[MiniInt, String, Boolean] - // ) - checkAll( - s"$context.Contravariant[AndCharPred]", - contravariantTests[AndCharPred].contravariant[MiniInt, String, Boolean] - ) - checkAll( - s"$context.Contravariant[ListSnocF]", - contravariantTests[ListSnocF].contravariant[MiniInt, String, Boolean] - ) - checkAll( - s"$context.Contravariant[EnumK1Contra]", - contravariantTests[EnumK1Contra].contravariant[MiniInt, String, Boolean] - ) - checkAll( - s"$context.Contravariant is Serializable", - SerializableTests.serializable(summonInline[Contravariant[TreePred]]) - ) - + // checkAll(s"instance[InterleavedPred]", tests[InterleavedPred].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AndCharPred]", tests[AndCharPred].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[ListSnocF]", tests[ListSnocF].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[TreePred]])) // TODO https://github.com/typelevel/kittens/issues/476 - // test(s"$context.Contravariant.contramap is stack safe") { + // test(s"instance.contramap is stack safe") { // val C = summonInline[Contravariant[ListSnocF]] // val n = 10000 // val largeBoxed = Snoc.fromSeq((1 until n).map((j: Int) => (i: Int) => i + j)) :: Nil @@ -71,12 +52,19 @@ class ContravariantSuite extends KittensSuite: locally { import auto.contravariant.given - testContravariant("auto") + validate("auto.contravariant") + } + + locally { + import semiContravariant.given + validate("semiauto.contravariant") } locally { - import semiInstances.given - testContravariant("semiauto") + import derivedContravariant.* + val instance = "derived.contravariant" + checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[EnumK1Contra]])) } end ContravariantSuite @@ -92,7 +80,7 @@ object ContravariantSuite: type AndCharPred[A] = (A => Boolean, Char) type TreePred[A] = Tree[A => Boolean] - object semiInstances: + object semiContravariant: given Contravariant[OptPred] = semiauto.contravariant given Contravariant[TreePred] = semiauto.contravariant given Contravariant[ListPred] = semiauto.contravariant @@ -102,18 +90,19 @@ object ContravariantSuite: given Contravariant[ListSnocF] = semiauto.contravariant given Contravariant[EnumK1Contra] = semiauto.contravariant - case class Single[A](value: A => Unit) derives Contravariant + object derivedContravariant: + case class EnumK1Contra[-A](x: TestDefns.EnumK1Contra[A]) derives Contravariant - enum Many[-A] derives Contravariant: - case Naught - case More(value: A => Unit, rest: Many[A]) + enum Many[-A] derives Contravariant: + case Naught + case More(value: A => Unit, rest: Many[A]) - enum AtMostOne[-A] derives Contravariant: - case Naught - case Single(value: A => Unit) + enum AtMostOne[-A] derives Contravariant: + case Naught + case Single(value: A => Unit) - enum AtLeastOne[-A] derives Contravariant: - case Single(value: A => Unit) - case More(value: A => Unit, rest: Option[AtLeastOne[A]]) + enum AtLeastOne[-A] derives Contravariant: + case Single(value: A => Unit) + case More(value: A => Unit, rest: Option[AtLeastOne[A]]) end ContravariantSuite From 0e0fdf2cd8866739a8655a12243444d833684318 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 05:28:20 +0200 Subject: [PATCH 07/29] Extend EmptyKSuite with derived cases --- .../scala-3/cats/derived/EmptyKSuite.scala | 39 ++++++++++++------- .../scala-3/cats/derived/EmptyKTests.scala | 10 ----- 2 files changed, 26 insertions(+), 23 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/EmptyKTests.scala diff --git a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala index f14a3221..43fb1ae5 100644 --- a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala @@ -33,24 +33,32 @@ class EmptyKSuite extends KittensSuite: inline def emptyK[F[_]] = summonInline[EmptyK[F]].empty - inline def testEmptyK(context: String): Unit = - test(s"$context.EmptyK[LOption]")(assert(emptyK[LOption] == Nil)) - test(s"$context.EmptyK[PList]")(assert(emptyK[PList] == (Nil, Nil))) - test(s"$context.EmptyK[CaseClassWOption]")(assert(emptyK[CaseClassWOption] == CaseClassWOption(None))) - test(s"$context.EmptyK[NelOption]")(assert(emptyK[NelOption] == NonEmptyList.one(None))) - test(s"$context.EmptyK[IList]")(assert(emptyK[IList] == INil())) - test(s"$context.EmptyK[Snoc]")(assert(emptyK[Snoc] == SNil())) - test(s"$context.EmptyK respects existing instances")(assert(emptyK[BoxColor] == Box(Color(255, 255, 255)))) - checkAll(s"$context.EmptyK is Serializable", SerializableTests.serializable(summonInline[EmptyK[LOption]])) + inline def validate(instance: String): Unit = + test(s"$instance[LOption]")(assert(emptyK[LOption] == Nil)) + test(s"$instance[PList]")(assert(emptyK[PList] == (Nil, Nil))) + test(s"$instance[CaseClassWOption]")(assert(emptyK[CaseClassWOption] == CaseClassWOption(None))) + test(s"$instance[NelOption]")(assert(emptyK[NelOption] == NonEmptyList.one(None))) + test(s"$instance[IList]")(assert(emptyK[IList] == INil())) + test(s"$instance[Snoc]")(assert(emptyK[Snoc] == SNil())) + test(s"$instance respects existing instances")(assert(emptyK[BoxColor] == Box(Color(255, 255, 255)))) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[EmptyK[LOption]])) locally { import auto.emptyK.given - testEmptyK("auto") + validate("auto.emptyK") } locally { - import semiInstances.given - testEmptyK("semiauto") + import semiEmptyK.given + validate("semiauto.emptyK") + } + + locally { + import derivedInstances.* + val instance = "derived.emptyK" + test(s"$instance[CaseClassWOption]")(assert(emptyK[CaseClassWOption].x.value.isEmpty)) + test(s"$instance[IList]")(assert(emptyK[IList].x == INil())) + test(s"$instance[Snoc]")(assert(emptyK[Snoc].x == SNil())) } end EmptyKSuite @@ -63,7 +71,7 @@ object EmptyKSuite: type NelOption[A] = NonEmptyList[Option[A]] type BoxColor[A] = Box[Color[A]] - object semiInstances: + object semiEmptyK: given EmptyK[LOption] = semiauto.emptyK given EmptyK[PList] = semiauto.emptyK given EmptyK[CaseClassWOption] = semiauto.emptyK @@ -72,6 +80,11 @@ object EmptyKSuite: given EmptyK[Snoc] = semiauto.emptyK given EmptyK[BoxColor] = semiauto.emptyK + object derivedInstances: + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives EmptyK + case class IList[A](x: TestDefns.IList[A]) derives EmptyK + case class Snoc[A](x: TestDefns.Snoc[A]) derives EmptyK + final case class Color[A](r: Int, g: Int, b: Int) object Color: given EmptyK[Color] with diff --git a/core/src/test/scala-3/cats/derived/EmptyKTests.scala b/core/src/test/scala-3/cats/derived/EmptyKTests.scala deleted file mode 100644 index 3234d74a..00000000 --- a/core/src/test/scala-3/cats/derived/EmptyKTests.scala +++ /dev/null @@ -1,10 +0,0 @@ -package cats.derived - -import alleycats.* -import alleycats.std.all.* -import cats.* -import cats.derived.* - -class EmptyKTests { // - case class Foo[A](i: String, l: List[A]) derives EmptyK -} From 89391f80625f13e127a6c5e507eb8a055f4208ec Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 08:13:36 +0200 Subject: [PATCH 08/29] Extend EmptySuite with derived cases --- .../scala-3/cats/derived/EmptySuite.scala | 48 ++++++++++++++----- .../scala-3/cats/derived/EmptyTests.scala | 11 ----- 2 files changed, 35 insertions(+), 24 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/EmptyTests.scala diff --git a/core/src/test/scala-3/cats/derived/EmptySuite.scala b/core/src/test/scala-3/cats/derived/EmptySuite.scala index 2886b13f..931c396f 100644 --- a/core/src/test/scala-3/cats/derived/EmptySuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptySuite.scala @@ -29,32 +29,45 @@ class EmptySuite extends KittensSuite: inline def empty[A]: A = summonInline[Empty[A]].empty - inline def testEmpty(inline context: String): Unit = - test(s"$context.Empty[Foo]")(assert(empty[Foo] == Foo(0, None))) - test(s"$context.Empty[Outer]")(assert(empty[Outer] == Outer(Inner(0)))) - test(s"$context.Empty[Interleaved[String]]")(assert(empty[Interleaved[String]] == Interleaved.empty(""))) - test(s"$context.Empty[Recursive]")(assert(empty[Recursive] == Recursive(0, None))) - test(s"$context.Empty[IList[Dummy]]")(assert(empty[IList[Dummy]] == INil())) - test(s"$context.Empty[Snoc[Dummy]]")(assert(empty[Snoc[Dummy]] == SNil())) - test(s"$context.Empty respects existing instances")(assert(empty[Box[Mask]] == Box(Mask(0xffffffff)))) - checkAll(s"$context.Empty is Serializable", SerializableTests.serializable(summonInline[Empty[Foo]])) + inline def validate(inline instance: String): Unit = + test(s"$instance[Foo]")(assert(empty[Foo] == Foo(0, None))) + test(s"$instance[Outer]")(assert(empty[Outer] == Outer(Inner(0)))) + test(s"$instance[Interleaved[String]]")(assert(empty[Interleaved[String]] == Interleaved.empty(""))) + test(s"$instance[Recursive]")(assert(empty[Recursive] == Recursive(0, None))) + test(s"$instance[IList[Dummy]]")(assert(empty[IList[Dummy]] == INil())) + test(s"$instance[Snoc[Dummy]]")(assert(empty[Snoc[Dummy]] == SNil())) + test(s"$instance respects existing instances")(assert(empty[Box[Mask]] == Box(Mask(0xffffffff)))) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Empty[Foo]])) locally { import auto.empty.given - testEmpty("auto") + validate("auto.empty") testNoAuto("Empty", "IList[Int]") testNoAuto("Empty", "Snoc[Int]") testNoAuto("Empty", "Rgb") } locally { - import semiInstances.given - testEmpty("semiauto") + import semiEmpty.given + validate("semiauto.empty") testNoSemi("Empty", "IList[Int]") testNoSemi("Empty", "Snoc[Int]") testNoSemi("Empty", "Rgb") } + locally { + import derivedEmpty.* + val instance = "derived.empty" + test(s"$instance[Foo]")(assert(empty[Foo].x == TestDefns.Foo(0, None))) + test(s"$instance[Outer]")(assert(empty[Outer].x == TestDefns.Outer(Inner(0)))) + test(s"$instance[Interleaved[String]]")(assert(empty[Interleaved[String]].x == TestDefns.Interleaved.empty(""))) + test(s"$instance[Recursive]")(assert(empty[Recursive].x == TestDefns.Recursive(0, None))) + test(s"$instance[IList[Dummy]]")(assert(empty[IList[Int]].x == INil())) + test(s"$instance[Snoc[Dummy]]")(assert(empty[Snoc[Int]].x == SNil())) + test(s"$instance respects existing instances")(assert(empty[BoxMask].x == Box(Mask(0xffffffff)))) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Empty[Foo]])) + } + end EmptySuite object EmptySuite: @@ -63,7 +76,7 @@ object EmptySuite: // `Monoid[Option[A]]` gives us `Empty[Option[A]]` but it requires a `Semigroup[A]`. given [A]: Empty[Option[A]] = Empty(None) - object semiInstances: + object semiEmpty: given Empty[Foo] = semiauto.empty given Empty[Outer] = semiauto.empty given Empty[Interleaved[String]] = semiauto.empty @@ -73,6 +86,15 @@ object EmptySuite: given Empty[Box[Mask]] = semiauto.empty given Empty[Chain] = semiauto.empty + object derivedEmpty: + case class Foo(x: TestDefns.Foo) derives Empty + case class Outer(x: TestDefns.Outer) derives Empty + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Empty + case class Recursive(x: TestDefns.Recursive) derives Empty + case class IList[A](x: TestDefns.IList[A]) derives Empty + case class Snoc[A](x: TestDefns.Snoc[A]) derives Empty + case class BoxMask(x: Box[Mask]) derives Empty + trait Dummy final case class Chain(head: Int, tail: Chain) final case class Mask(bits: Int) diff --git a/core/src/test/scala-3/cats/derived/EmptyTests.scala b/core/src/test/scala-3/cats/derived/EmptyTests.scala deleted file mode 100644 index cc1e6c83..00000000 --- a/core/src/test/scala-3/cats/derived/EmptyTests.scala +++ /dev/null @@ -1,11 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -object EmptyTests: - case class Foo(i: Int, b: IntTree) derives Empty - enum IntTree: - case Leaf - case Node(left: IntTree, value: Int, right: IntTree) From a8ada287db38375de1645749213035c49b2d78c8 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 08:30:03 +0200 Subject: [PATCH 09/29] Extend EqSuite with derived cases --- .../cats/derived/ApplicativeSuite.scala | 1 - .../scala-3/cats/derived/ApplySuite.scala | 1 - .../cats/derived/CommutativeMonoidSuite.scala | 1 - .../derived/CommutativeSemigroupSuite.scala | 1 - .../test/scala-3/cats/derived/EqSuite.scala | 50 +++++++++++++------ .../test/scala-3/cats/derived/EqTests.scala | 9 ---- .../scala-3/cats/derived/KittensSuite.scala | 5 +- 7 files changed, 40 insertions(+), 28 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/EqTests.scala diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 91b74069..b33e5992 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -54,7 +54,6 @@ class ApplicativeSuite extends KittensSuite: locally { import derivedApplicative.* val instance = "derived.applicative" - // Copy pasted from `validate` checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].applicative[Int, String, Long]) diff --git a/core/src/test/scala-3/cats/derived/ApplySuite.scala b/core/src/test/scala-3/cats/derived/ApplySuite.scala index 81becf22..c875c09a 100644 --- a/core/src/test/scala-3/cats/derived/ApplySuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplySuite.scala @@ -52,7 +52,6 @@ class ApplySuite extends KittensSuite: locally { import derivedApply.* val instance = "derived.apply" - // Copy pasted from `validate` checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].apply[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].apply[Int, String, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].apply[Int, String, Long]) diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index ce3a0354..854abfbe 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -57,7 +57,6 @@ class CommutativeMonoidSuite extends KittensSuite: locally { import derivedCommutativeMonoid.* val instance = "derived.commutativeMonoid" - // Copy pasted from `validate` checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeMonoid) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeMonoid) checkAll( diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index 64fbcc0a..e900276d 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -56,7 +56,6 @@ class CommutativeSemigroupSuite extends KittensSuite: locally { import derivedCommutativeSemigroup.* val instance = "derived.commutativeSemigroup" - // Copy pasted from `validate` checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeSemigroup) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeSemigroup) checkAll( diff --git a/core/src/test/scala-3/cats/derived/EqSuite.scala b/core/src/test/scala-3/cats/derived/EqSuite.scala index adf99d51..bf83a8a5 100644 --- a/core/src/test/scala-3/cats/derived/EqSuite.scala +++ b/core/src/test/scala-3/cats/derived/EqSuite.scala @@ -25,27 +25,40 @@ class EqSuite extends KittensSuite.WithoutEq: import EqSuite.* import TestDefns.* - inline def eqTests[A]: EqTests[A] = + inline def tests[A]: EqTests[A] = EqTests[A](summonInline) - inline def testEq(inline context: String): Unit = - checkAll(s"$context.Eq[Foo]]", eqTests[Foo].eqv) - checkAll(s"$context.Eq[IList[Int]]", eqTests[IList[Int]].eqv) - checkAll(s"$context.Eq[Inner]", eqTests[Inner].eqv) - checkAll(s"$context.Eq[Outer]", eqTests[Outer].eqv) - checkAll(s"$context.Eq[Interleaved[Int]]", eqTests[Interleaved[Int]].eqv) - checkAll(s"$context.Eq[Tree[Int]]", eqTests[Tree[Int]].eqv) - checkAll(s"$context.Eq[Recursive]", eqTests[Recursive].eqv) - checkAll(s"$context.Eq is Serializable", SerializableTests.serializable(summonInline[Eq[Foo]])) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[Foo]]", tests[Foo].eqv) + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].eqv) + checkAll(s"$instance[Inner]", tests[Inner].eqv) + checkAll(s"$instance[Outer]", tests[Outer].eqv) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].eqv) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].eqv) + checkAll(s"$instance[Recursive]", tests[Recursive].eqv) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Eq[Foo]])) locally { import auto.eq.given - testEq("auto") + validate("auto.eq") } locally { - import semiInstances.given - testEq("semiauto") + import semiEq.given + validate("semiauto.eq") + } + + locally { + import derivedEq.* + val instance = "derived.eq" + checkAll(s"$instance[Foo]]", tests[Foo].eqv) + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].eqv) + checkAll(s"$instance[Inner]", tests[Inner].eqv) + checkAll(s"$instance[Outer]", tests[Outer].eqv) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].eqv) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].eqv) + checkAll(s"$instance[Recursive]", tests[Recursive].eqv) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Eq[Foo]])) } end EqSuite @@ -53,7 +66,7 @@ end EqSuite object EqSuite: import TestDefns.* - object semiInstances: + object semiEq: given Eq[Foo] = semiauto.eq given Eq[IList[Int]] = semiauto.eq given Eq[Inner] = semiauto.eq @@ -62,4 +75,13 @@ object EqSuite: given Eq[Tree[Int]] = semiauto.eq given Eq[Recursive] = semiauto.eq + object derivedEq: + case class Foo(x: TestDefns.Foo) derives Eq + case class IList[A](x: TestDefns.IList[A]) derives Eq + case class Inner(x: TestDefns.Inner) derives Eq + case class Outer(x: TestDefns.Outer) derives Eq + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Eq + case class Tree[A](x: TestDefns.Tree[A]) derives Eq + case class Recursive(x: TestDefns.Recursive) derives Eq + end EqSuite diff --git a/core/src/test/scala-3/cats/derived/EqTests.scala b/core/src/test/scala-3/cats/derived/EqTests.scala deleted file mode 100644 index b9a128ce..00000000 --- a/core/src/test/scala-3/cats/derived/EqTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -class EqTests { // - case class Foo(i: Int, b: Option[String]) derives Eq -} diff --git a/core/src/test/scala-3/cats/derived/KittensSuite.scala b/core/src/test/scala-3/cats/derived/KittensSuite.scala index fc8451bc..922c2b3f 100644 --- a/core/src/test/scala-3/cats/derived/KittensSuite.scala +++ b/core/src/test/scala-3/cats/derived/KittensSuite.scala @@ -20,7 +20,7 @@ import cats.Eq import cats.platform.Platform import cats.syntax.AllSyntax import munit.DisciplineSuite -import org.scalacheck.Arbitrary +import org.scalacheck.{Arbitrary, Cogen} import org.scalacheck.Test.Parameters import scala.deriving.Mirror @@ -56,6 +56,9 @@ object KittensSuite: given [A <: Product](using mirror: Mirror.ProductOf[A], via: Arbitrary[mirror.MirroredElemTypes]): Arbitrary[A] = Arbitrary(via.arbitrary.map(mirror.fromTuple)) + given [A <: Product](using mirror: Mirror.ProductOf[A], via: Cogen[mirror.MirroredElemTypes]): Cogen[A] = + via.contramap(Tuple.fromProductTyped) + inline def testNoInstance(inline tc: String, target: String, message: String): Unit = val errors = compileErrors(tc + "[" + target + "]") test(s"No $tc for $target")(assert(errors.contains(message), s"$errors did not contain $message")) From 338d3d20812fea4c52d4e4446894577271311b99 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:08:25 +0200 Subject: [PATCH 10/29] Extend FoldableSuite with derived cases --- .../cats/derived/ContravariantSuite.scala | 2 + .../scala-3/cats/derived/FoldableSuite.scala | 107 +++++++++++++----- 2 files changed, 78 insertions(+), 31 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index 2f466571..93b0a641 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -64,6 +64,7 @@ class ContravariantSuite extends KittensSuite: import derivedContravariant.* val instance = "derived.contravariant" checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) + checkAll(s"$instance[Single]", tests[Single].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[EnumK1Contra]])) } @@ -92,6 +93,7 @@ object ContravariantSuite: object derivedContravariant: case class EnumK1Contra[-A](x: TestDefns.EnumK1Contra[A]) derives Contravariant + case class Single[-A](value: A => Unit) derives Contravariant enum Many[-A] derives Contravariant: case Naught diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 0b748f3a..334e1164 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -19,36 +19,53 @@ package derived import cats.laws.discipline.{FoldableTests, SerializableTests} import cats.syntax.all.* -import org.scalacheck.Arbitrary +import org.scalacheck.{Arbitrary, Gen} import scala.compiletime.* class FoldableSuite extends KittensSuite: import FoldableSuite.* import TestDefns.* - inline def foldableTests[F[_]]: FoldableTests[F] = + inline def tests[F[_]]: FoldableTests[F] = FoldableTests[F](summonInline) - inline def testFoldable(inline context: String): Unit = - checkAll(s"$context.Foldable[IList]", foldableTests[IList].foldable[Int, Long]) - checkAll(s"$context.Foldable[Tree]", foldableTests[Tree].foldable[Int, Long]) - checkAll(s"$context.Foldable[GenericAdt]", foldableTests[GenericAdt].foldable[Int, Long]) - checkAll(s"$context.Foldable[OptList]", foldableTests[OptList].foldable[Int, Long]) - checkAll(s"$context.Foldable[ListSnoc]", foldableTests[ListSnoc].foldable[Int, Long]) - checkAll(s"$context.Foldable[AndChar]", foldableTests[AndChar].foldable[Int, Long]) - checkAll(s"$context.Foldable[Interleaved]", foldableTests[Interleaved].foldable[Int, Long]) - checkAll(s"$context.Foldable[BoxNel]", foldableTests[BoxNel].foldable[Int, Long]) - checkAll(s"$context.Foldable[EnumK1]", foldableTests[EnumK1].foldable[Int, Long]) - checkAll(s"$context.Foldable is Serializable", SerializableTests.serializable(summonInline[Foldable[Tree]])) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[IList]", tests[IList].foldable[Int, Long]) + checkAll(s"$instance[Tree]", tests[Tree].foldable[Int, Long]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].foldable[Int, Long]) + checkAll(s"$instance[OptList]", tests[OptList].foldable[Int, Long]) + checkAll(s"$instance[ListSnoc]", tests[ListSnoc].foldable[Int, Long]) + checkAll(s"$instance[AndChar]", tests[AndChar].foldable[Int, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].foldable[Int, Long]) + checkAll(s"$instance[BoxNel]", tests[BoxNel].foldable[Int, Long]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].foldable[Int, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Foldable[Tree]])) locally { import auto.foldable.given - testFoldable("auto") + validate("auto.foldable") } locally { - import semiInstances.given - testFoldable("semiauto") + import semiFoldable.given + validate("semiauto.foldable") + } + + locally { + import derivedFoldable.* + import derivedFoldable.given + val instance = "derived.foldable" + checkAll(s"$instance[IList]", tests[IList].foldable[Int, Long]) + checkAll(s"$instance[Tree]", tests[Tree].foldable[Int, Long]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].foldable[Int, Long]) + checkAll(s"$instance[AndChar]", tests[AndChar].foldable[Int, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].foldable[Int, Long]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].foldable[Int, Long]) + checkAll(s"$instance[Single]", tests[Single].foldable[Int, Long]) + checkAll(s"$instance[Many]", tests[Many].foldable[Int, Long]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].foldable[Int, Long]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].foldable[Int, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Foldable[Tree]])) } end FoldableSuite @@ -61,7 +78,7 @@ object FoldableSuite: type AndChar[A] = (A, Char) type BoxNel[A] = Box[Nel[A]] - object semiInstances: + object semiFoldable: given Foldable[IList] = semiauto.foldable given Foldable[Tree] = semiauto.foldable given Foldable[GenericAdt] = semiauto.foldable @@ -72,6 +89,48 @@ object FoldableSuite: given Foldable[BoxNel] = semiauto.foldable given Foldable[EnumK1] = semiauto.foldable + object derivedFoldable: + case class IList[A](x: TestDefns.IList[A]) derives Foldable + case class Tree[A](x: TestDefns.Tree[A]) derives Foldable + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Foldable + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Foldable + case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Foldable + case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Foldable + case class Single[A](value: A) derives Foldable + + enum Many[+A] derives Foldable, Eq: + case Naught + case More(value: A, rest: Many[A]) + + enum AtMostOne[+A] derives Foldable, Eq: + case Naught + case Single(value: A) + + enum AtLeastOne[+A] derives Foldable, Eq: + case Single(value: A) + case More(value: A, rest: Option[AtLeastOne[A]]) + + given [A: Arbitrary]: Arbitrary[Many[A]] = Arbitrary( + Gen.oneOf( + Gen.const(Many.Naught), + Gen.lzy(Arbitrary.arbitrary[(A, Many[A])].map(Many.More.apply)) + ) + ) + + given [A: Arbitrary]: Arbitrary[AtMostOne[A]] = Arbitrary( + Gen.oneOf( + Gen.const(AtMostOne.Naught), + Arbitrary.arbitrary[A].map(AtMostOne.Single.apply) + ) + ) + + given [A: Arbitrary]: Arbitrary[AtLeastOne[A]] = Arbitrary( + Gen.oneOf( + Arbitrary.arbitrary[A].map(AtLeastOne.Single.apply), + Gen.lzy(Arbitrary.arbitrary[(A, Option[AtLeastOne[A]])].map(AtLeastOne.More.apply)) + ) + ) + final case class Nel[+A](head: A, tail: List[A]) object Nel: given [A: Eq]: Eq[Nel[A]] = @@ -87,18 +146,4 @@ object FoldableSuite: def foldLeft[A, B](fa: Nel[A], b: B)(f: (B, A) => B) = fa.tail.foldl(b)(f) def foldRight[A, B](fa: Nel[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]) = fa.tail.foldr(lb)(f) - case class Single[A](value: A) derives Foldable - - enum Many[+A] derives Foldable: - case Naught - case More(value: A, rest: Many[A]) - - enum AtMostOne[+A] derives Foldable: - case Naught - case Single(value: A) - - enum AtLeastOne[+A] derives Foldable: - case Single(value: A) - case More(value: A, rest: Option[AtLeastOne[A]]) - end FoldableSuite From 8d649f67afa4222bc5e3e3234c3d0a3129461add Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:23:34 +0200 Subject: [PATCH 11/29] Extend FunctorSuite with derived cases --- .../scala-3/cats/derived/FunctorSuite.scala | 104 +++++++++++++----- 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/FunctorSuite.scala b/core/src/test/scala-3/cats/derived/FunctorSuite.scala index c4d64abe..59f48e68 100644 --- a/core/src/test/scala-3/cats/derived/FunctorSuite.scala +++ b/core/src/test/scala-3/cats/derived/FunctorSuite.scala @@ -19,6 +19,7 @@ package derived import cats.laws.discipline.* import cats.laws.discipline.eq.* +import org.scalacheck.{Arbitrary, Gen} import scala.compiletime.* class FunctorSuite extends KittensSuite: @@ -28,29 +29,46 @@ class FunctorSuite extends KittensSuite: given ExhaustiveCheck[Predicate[Boolean]] = ExhaustiveCheck.instance(List(_ => true, _ => false, identity, !_)) - inline def functorTests[F[_]]: FunctorTests[F] = + inline def tests[F[_]]: FunctorTests[F] = FunctorTests[F](summonInline) - inline def testFunctor(inline context: String): Unit = - checkAll(s"$context.Functor[IList]", functorTests[IList].functor[Int, String, Long]) - checkAll(s"$context.Functor[Tree]", functorTests[Tree].functor[Int, String, Long]) - checkAll(s"$context.Functor[GenericAdt]", functorTests[GenericAdt].functor[Int, String, Long]) - checkAll(s"$context.Functor[OptList]", functorTests[OptList].functor[Int, String, Long]) - checkAll(s"$context.Functor[ListSnoc]", functorTests[ListSnoc].functor[Int, String, Long]) - checkAll(s"$context.Functor[AndChar]", functorTests[AndChar].functor[Int, String, Long]) - checkAll(s"$context.Functor[Interleaved]", functorTests[Interleaved].functor[Int, String, Long]) - checkAll(s"$context.Functor[NestedPred]", functorTests[NestedPred].functor[Boolean, Int, Boolean]) - checkAll(s"$context.Functor[EnumK1]", functorTests[EnumK1].functor[Boolean, Int, Boolean]) - checkAll(s"$context.Functor is Serializable", SerializableTests.serializable(summonInline[Functor[Tree]])) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[IList]", tests[IList].functor[Int, String, Long]) + checkAll(s"$instance[Tree]", tests[Tree].functor[Int, String, Long]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].functor[Int, String, Long]) + checkAll(s"$instance[OptList]", tests[OptList].functor[Int, String, Long]) + checkAll(s"$instance[ListSnoc]", tests[ListSnoc].functor[Int, String, Long]) + checkAll(s"$instance[AndChar]", tests[AndChar].functor[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].functor[Int, String, Long]) + checkAll(s"$instance[NestedPred]", tests[NestedPred].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].functor[Boolean, Int, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Functor[Tree]])) locally { import auto.functor.given - testFunctor("auto") + validate("auto.functor") } locally { - import semiInstances.given - testFunctor("semiauto") + import semiFunctor.given + validate("semiauto.functor") + } + + locally { + import derivedFunctor.* + import derivedFunctor.given + val instance = "derived.functor" + checkAll(s"$instance[IList]", tests[IList].functor[Int, String, Long]) + checkAll(s"$instance[Tree]", tests[Tree].functor[Int, String, Long]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].functor[Int, String, Long]) + checkAll(s"$instance[AndChar]", tests[AndChar].functor[Int, String, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].functor[Int, String, Long]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[Single]", tests[Single].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[Many]", tests[Many].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].functor[Boolean, Int, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Functor[Tree]])) } end FunctorSuite @@ -64,7 +82,7 @@ object FunctorSuite: type Predicate[A] = A => Boolean type NestedPred[A] = Predicate[Predicate[A]] - object semiInstances: + object semiFunctor: given Functor[IList] = semiauto.functor given Functor[Tree] = semiauto.functor given Functor[GenericAdt] = semiauto.functor @@ -75,18 +93,46 @@ object FunctorSuite: given Functor[NestedPred] = semiauto.functor given Functor[EnumK1] = semiauto.functor - case class Single[A](value: A) derives Functor - - enum Many[+A] derives Functor: - case Naught - case More(value: A, rest: Many[A]) - - enum AtMostOne[+A] derives Functor: - case Naught - case Single(value: A) - - enum AtLeastOne[+A] derives Functor: - case Single(value: A) - case More(value: A, rest: Option[AtLeastOne[A]]) + object derivedFunctor: + case class IList[A](x: TestDefns.IList[A]) derives Functor + case class Tree[A](x: TestDefns.Tree[A]) derives Functor + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Functor + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Functor + case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Functor + case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Functor + case class Single[A](value: A) derives Functor + + enum Many[+A] derives Functor, Eq: + case Naught + case More(value: A, rest: Many[A]) + + enum AtMostOne[+A] derives Functor, Eq: + case Naught + case Single(value: A) + + enum AtLeastOne[+A] derives Functor, Eq: + case Single(value: A) + case More(value: A, rest: Option[AtLeastOne[A]]) + + given [A: Arbitrary]: Arbitrary[Many[A]] = Arbitrary( + Gen.oneOf( + Gen.const(Many.Naught), + Gen.lzy(Arbitrary.arbitrary[(A, Many[A])].map(Many.More.apply)) + ) + ) + + given [A: Arbitrary]: Arbitrary[AtMostOne[A]] = Arbitrary( + Gen.oneOf( + Gen.const(AtMostOne.Naught), + Arbitrary.arbitrary[A].map(AtMostOne.Single.apply) + ) + ) + + given [A: Arbitrary]: Arbitrary[AtLeastOne[A]] = Arbitrary( + Gen.oneOf( + Arbitrary.arbitrary[A].map(AtLeastOne.Single.apply), + Gen.lzy(Arbitrary.arbitrary[(A, Option[AtLeastOne[A]])].map(AtLeastOne.More.apply)) + ) + ) end FunctorSuite From 0a13d78500e21ad27cd469f2ef3c4dda3f38c799 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:24:04 +0200 Subject: [PATCH 12/29] Remove large ADT definitions --- .../test/scala-3/cats/derived/adtdefns.scala | 118 ------------------ 1 file changed, 118 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/adtdefns.scala b/core/src/test/scala-3/cats/derived/adtdefns.scala index 5de94a4d..2cb0bb19 100644 --- a/core/src/test/scala-3/cats/derived/adtdefns.scala +++ b/core/src/test/scala-3/cats/derived/adtdefns.scala @@ -343,124 +343,6 @@ object TestDefns: final case class ListField(a: String, b: List[ListFieldChild]) final case class ListFieldChild(c: Int) - final case class Large( - bar1: String, - bar2: Int, - bar3: Boolean, - bar4: Large2, - bar5: List[String], - bar6: Set[Boolean], - bar7: Double, - bar8: Long, - bar9: Char, - bar10: Float, - bar11: String, - bar12: Map[String, Int], - bar13: Boolean, - bar14: Option[String], - bar15: List[String], - bar16: Set[Boolean], - bar17: Double, - bar18: Long, - bar19: Char, - bar20: Float - ) - - final case class Large2( - bar1: String, - bar2: Int, - bar3: Boolean, - bar4: Option[String], - bar5: List[String], - bar6: Set[Boolean], - bar7: Double, - bar8: Long, - bar9: Char, - bar10: Float, - bar11: String, - bar12: Map[String, Int], - bar13: Boolean, - bar14: Option[String], - bar15: List[String], - bar16: Set[Boolean], - bar17: Double, - bar18: Long, - bar19: Char, - bar20: Float, - bar21: String - ) - - final case class Large3( - bar1: String, - bar2: Int, - bar3: Boolean, - bar4: Option[String], - bar5: List[String], - bar6: Set[Boolean], - bar7: Double, - bar8: Long, - bar9: Char, - bar10: Float, - bar11: String, - bar12: Map[String, Int], - bar13: Boolean, - bar14: Option[String], - bar15: List[String], - bar16: Set[Boolean], - bar17: Double, - bar18: Long, - bar19: Char, - bar20: Float, - bar21: String - ) - - final case class Large4( - bar1: String, - bar2: Int, - bar3: Boolean, - bar4: Large5, - bar5: List[String], - bar6: List[Boolean], - bar7: Double, - bar8: Long, - bar9: Char, - bar10: Float, - bar11: String, - bar12: String, - bar13: Boolean, - bar14: Option[String], - bar15: List[String], - bar16: List[Boolean], - bar17: Double, - bar18: Long, - bar19: Char, - bar20: Float - ) - - final case class Large5( - bar1: String, - bar2: Int, - bar3: Boolean, - bar4: Option[String], - bar5: List[String], - bar6: List[Boolean], - bar7: Double, - bar8: Long, - bar9: Char, - bar10: Float, - bar11: String, - bar12: Int, - bar13: Boolean, - bar14: Option[String], - bar15: List[String], - bar16: List[Boolean], - bar17: Double, - bar18: Long, - bar19: Char, - bar20: Float, - bar21: String - ) - end TestDefns trait TestEqInstances: From 02886ebec42a55ec893f75aa8868857a1cb6b42e Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:34:38 +0200 Subject: [PATCH 13/29] Move some enums to ADT definitions --- .../scala-3/cats/derived/FoldableSuite.scala | 45 ++++-------------- .../scala-3/cats/derived/FunctorSuite.scala | 46 ++++--------------- .../test/scala-3/cats/derived/adtdefns.scala | 36 +++++++++++++++ 3 files changed, 54 insertions(+), 73 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 334e1164..33cc6b89 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -39,6 +39,9 @@ class FoldableSuite extends KittensSuite: checkAll(s"$instance[Interleaved]", tests[Interleaved].foldable[Int, Long]) checkAll(s"$instance[BoxNel]", tests[BoxNel].foldable[Int, Long]) checkAll(s"$instance[EnumK1]", tests[EnumK1].foldable[Int, Long]) + checkAll(s"$instance[Many]", tests[Many].foldable[Int, Long]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].foldable[Int, Long]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].foldable[Int, Long]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Foldable[Tree]])) locally { @@ -53,7 +56,6 @@ class FoldableSuite extends KittensSuite: locally { import derivedFoldable.* - import derivedFoldable.given val instance = "derived.foldable" checkAll(s"$instance[IList]", tests[IList].foldable[Int, Long]) checkAll(s"$instance[Tree]", tests[Tree].foldable[Int, Long]) @@ -61,7 +63,6 @@ class FoldableSuite extends KittensSuite: checkAll(s"$instance[AndChar]", tests[AndChar].foldable[Int, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].foldable[Int, Long]) checkAll(s"$instance[EnumK1]", tests[EnumK1].foldable[Int, Long]) - checkAll(s"$instance[Single]", tests[Single].foldable[Int, Long]) checkAll(s"$instance[Many]", tests[Many].foldable[Int, Long]) checkAll(s"$instance[AtMostOne]", tests[AtMostOne].foldable[Int, Long]) checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].foldable[Int, Long]) @@ -88,6 +89,9 @@ object FoldableSuite: given Foldable[Interleaved] = semiauto.foldable given Foldable[BoxNel] = semiauto.foldable given Foldable[EnumK1] = semiauto.foldable + given Foldable[Many] = semiauto.foldable + given Foldable[AtMostOne] = semiauto.foldable + given Foldable[AtLeastOne] = semiauto.foldable object derivedFoldable: case class IList[A](x: TestDefns.IList[A]) derives Foldable @@ -96,40 +100,9 @@ object FoldableSuite: case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Foldable case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Foldable case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Foldable - case class Single[A](value: A) derives Foldable - - enum Many[+A] derives Foldable, Eq: - case Naught - case More(value: A, rest: Many[A]) - - enum AtMostOne[+A] derives Foldable, Eq: - case Naught - case Single(value: A) - - enum AtLeastOne[+A] derives Foldable, Eq: - case Single(value: A) - case More(value: A, rest: Option[AtLeastOne[A]]) - - given [A: Arbitrary]: Arbitrary[Many[A]] = Arbitrary( - Gen.oneOf( - Gen.const(Many.Naught), - Gen.lzy(Arbitrary.arbitrary[(A, Many[A])].map(Many.More.apply)) - ) - ) - - given [A: Arbitrary]: Arbitrary[AtMostOne[A]] = Arbitrary( - Gen.oneOf( - Gen.const(AtMostOne.Naught), - Arbitrary.arbitrary[A].map(AtMostOne.Single.apply) - ) - ) - - given [A: Arbitrary]: Arbitrary[AtLeastOne[A]] = Arbitrary( - Gen.oneOf( - Arbitrary.arbitrary[A].map(AtLeastOne.Single.apply), - Gen.lzy(Arbitrary.arbitrary[(A, Option[AtLeastOne[A]])].map(AtLeastOne.More.apply)) - ) - ) + case class Many[+A](x: TestDefns.Many[A]) derives Foldable + case class AtMostOne[+A](x: TestDefns.AtMostOne[A]) derives Foldable + case class AtLeastOne[+A](x: TestDefns.AtLeastOne[A]) derives Foldable final case class Nel[+A](head: A, tail: List[A]) object Nel: diff --git a/core/src/test/scala-3/cats/derived/FunctorSuite.scala b/core/src/test/scala-3/cats/derived/FunctorSuite.scala index 59f48e68..51feeb0c 100644 --- a/core/src/test/scala-3/cats/derived/FunctorSuite.scala +++ b/core/src/test/scala-3/cats/derived/FunctorSuite.scala @@ -19,7 +19,6 @@ package derived import cats.laws.discipline.* import cats.laws.discipline.eq.* -import org.scalacheck.{Arbitrary, Gen} import scala.compiletime.* class FunctorSuite extends KittensSuite: @@ -42,6 +41,9 @@ class FunctorSuite extends KittensSuite: checkAll(s"$instance[Interleaved]", tests[Interleaved].functor[Int, String, Long]) checkAll(s"$instance[NestedPred]", tests[NestedPred].functor[Boolean, Int, Boolean]) checkAll(s"$instance[EnumK1]", tests[EnumK1].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[Many]", tests[Many].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].functor[Boolean, Int, Boolean]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].functor[Boolean, Int, Boolean]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Functor[Tree]])) locally { @@ -56,7 +58,6 @@ class FunctorSuite extends KittensSuite: locally { import derivedFunctor.* - import derivedFunctor.given val instance = "derived.functor" checkAll(s"$instance[IList]", tests[IList].functor[Int, String, Long]) checkAll(s"$instance[Tree]", tests[Tree].functor[Int, String, Long]) @@ -64,7 +65,6 @@ class FunctorSuite extends KittensSuite: checkAll(s"$instance[AndChar]", tests[AndChar].functor[Int, String, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].functor[Int, String, Long]) checkAll(s"$instance[EnumK1]", tests[EnumK1].functor[Boolean, Int, Boolean]) - checkAll(s"$instance[Single]", tests[Single].functor[Boolean, Int, Boolean]) checkAll(s"$instance[Many]", tests[Many].functor[Boolean, Int, Boolean]) checkAll(s"$instance[AtMostOne]", tests[AtMostOne].functor[Boolean, Int, Boolean]) checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].functor[Boolean, Int, Boolean]) @@ -92,6 +92,9 @@ object FunctorSuite: given Functor[Interleaved] = semiauto.functor given Functor[NestedPred] = semiauto.functor given Functor[EnumK1] = semiauto.functor + given Functor[Many] = semiauto.functor + given Functor[AtMostOne] = semiauto.functor + given Functor[AtLeastOne] = semiauto.functor object derivedFunctor: case class IList[A](x: TestDefns.IList[A]) derives Functor @@ -100,39 +103,8 @@ object FunctorSuite: case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Functor case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Functor case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Functor - case class Single[A](value: A) derives Functor - - enum Many[+A] derives Functor, Eq: - case Naught - case More(value: A, rest: Many[A]) - - enum AtMostOne[+A] derives Functor, Eq: - case Naught - case Single(value: A) - - enum AtLeastOne[+A] derives Functor, Eq: - case Single(value: A) - case More(value: A, rest: Option[AtLeastOne[A]]) - - given [A: Arbitrary]: Arbitrary[Many[A]] = Arbitrary( - Gen.oneOf( - Gen.const(Many.Naught), - Gen.lzy(Arbitrary.arbitrary[(A, Many[A])].map(Many.More.apply)) - ) - ) - - given [A: Arbitrary]: Arbitrary[AtMostOne[A]] = Arbitrary( - Gen.oneOf( - Gen.const(AtMostOne.Naught), - Arbitrary.arbitrary[A].map(AtMostOne.Single.apply) - ) - ) - - given [A: Arbitrary]: Arbitrary[AtLeastOne[A]] = Arbitrary( - Gen.oneOf( - Arbitrary.arbitrary[A].map(AtLeastOne.Single.apply), - Gen.lzy(Arbitrary.arbitrary[(A, Option[AtLeastOne[A]])].map(AtLeastOne.More.apply)) - ) - ) + case class Many[+A](x: TestDefns.Many[A]) derives Functor + case class AtMostOne[+A](x: TestDefns.AtMostOne[A]) derives Functor + case class AtLeastOne[+A](x: TestDefns.AtLeastOne[A]) derives Functor end FunctorSuite diff --git a/core/src/test/scala-3/cats/derived/adtdefns.scala b/core/src/test/scala-3/cats/derived/adtdefns.scala index 2cb0bb19..029216ac 100644 --- a/core/src/test/scala-3/cats/derived/adtdefns.scala +++ b/core/src/test/scala-3/cats/derived/adtdefns.scala @@ -343,6 +343,42 @@ object TestDefns: final case class ListField(a: String, b: List[ListFieldChild]) final case class ListFieldChild(c: Int) + enum Many[+A] derives Eq: + case Naught + case More(value: A, rest: Many[A]) + + enum AtMostOne[+A] derives Eq: + case Naught + case Single(value: A) + + enum AtLeastOne[+A] derives Eq: + case Single(value: A) + case More(value: A, rest: Option[AtLeastOne[A]]) + + object Many: + given [A: Arbitrary]: Arbitrary[Many[A]] = Arbitrary( + Gen.oneOf( + Gen.const(Many.Naught), + Gen.lzy(Arbitrary.arbitrary[(A, Many[A])].map(Many.More.apply)) + ) + ) + + object AtMostOne: + given [A: Arbitrary]: Arbitrary[AtMostOne[A]] = Arbitrary( + Gen.oneOf( + Gen.const(AtMostOne.Naught), + Arbitrary.arbitrary[A].map(AtMostOne.Single.apply) + ) + ) + + object AtLeastOne: + given [A: Arbitrary]: Arbitrary[AtLeastOne[A]] = Arbitrary( + Gen.oneOf( + Arbitrary.arbitrary[A].map(AtLeastOne.Single.apply), + Gen.lzy(Arbitrary.arbitrary[(A, Option[AtLeastOne[A]])].map(AtLeastOne.More.apply)) + ) + ) + end TestDefns trait TestEqInstances: From bc1ede4d55ec32be9586219484474838248894f9 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:41:16 +0200 Subject: [PATCH 14/29] Extend HashSuite with derived cases --- .../cats/derived/ContravariantSuite.scala | 5 +- .../test/scala-3/cats/derived/HashSuite.scala | 51 ++++++++++++++----- .../test/scala-3/cats/derived/HashTests.scala | 9 ---- 3 files changed, 40 insertions(+), 25 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/HashTests.scala diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index 93b0a641..3d2885fa 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -34,13 +34,13 @@ class ContravariantSuite extends KittensSuite: checkAll(s"$instance[TreePred]", tests[TreePred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[ListPred]", tests[ListPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[GenericAdtPred]", tests[GenericAdtPred].contravariant[MiniInt, String, Boolean]) - // TODO https://github.com/typelevel/kittens/issues/473 + // TODO: https://github.com/typelevel/kittens/issues/473 // checkAll(s"instance[InterleavedPred]", tests[InterleavedPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[AndCharPred]", tests[AndCharPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[ListSnocF]", tests[ListSnocF].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[TreePred]])) - // TODO https://github.com/typelevel/kittens/issues/476 + // TODO: https://github.com/typelevel/kittens/issues/476 // test(s"instance.contramap is stack safe") { // val C = summonInline[Contravariant[ListSnocF]] // val n = 10000 @@ -86,6 +86,7 @@ object ContravariantSuite: given Contravariant[TreePred] = semiauto.contravariant given Contravariant[ListPred] = semiauto.contravariant given Contravariant[GenericAdtPred] = semiauto.contravariant + // TODO: https://github.com/typelevel/kittens/issues/473 // given Contravariant[InterleavedPred] = semiauto.contravariant given Contravariant[AndCharPred] = semiauto.contravariant given Contravariant[ListSnocF] = semiauto.contravariant diff --git a/core/src/test/scala-3/cats/derived/HashSuite.scala b/core/src/test/scala-3/cats/derived/HashSuite.scala index d222fbb7..d9a06180 100644 --- a/core/src/test/scala-3/cats/derived/HashSuite.scala +++ b/core/src/test/scala-3/cats/derived/HashSuite.scala @@ -10,28 +10,42 @@ class HashSuite extends KittensSuite: import HashSuite.* import TestDefns.* - inline def hashTests[A]: HashTests[A] = + inline def tests[A]: HashTests[A] = HashTests[A](summonInline) - inline def testHash(inline context: String): Unit = - checkAll(s"$context.Hash[IList[Int]]", hashTests[IList[Int]].hash) - checkAll(s"$context.Hash[Inner]", hashTests[Inner].hash) - checkAll(s"$context.Hash[Outer]", hashTests[Outer].hash) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].hash) + checkAll(s"$instance[Inner]", tests[Inner].hash) + checkAll(s"$instance[Outer]", tests[Outer].hash) // FIXME: typelevel/cats#2878 - // checkAll(s"$context.Hash[Interleaved[Int]]", hashTests[Interleaved[Int]].hash) - checkAll(s"$context.Hash[Tree[Int]]", hashTests[Tree[Int]].hash) - checkAll(s"$context.Hash[Recursive]", hashTests[Recursive].hash) - checkAll(s"$context.Hash[EnumK0]", hashTests[EnumK0].hash) - checkAll(s"$context.Hash is Serializable", SerializableTests.serializable(summonInline[Hash[Inner]])) + // checkAll(s"$context[Interleaved[Int]]", tests[Interleaved[Int]].hash) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].hash) + checkAll(s"$instance[Recursive]", tests[Recursive].hash) + checkAll(s"$instance[EnumK0]", tests[EnumK0].hash) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Hash[Inner]])) locally { import auto.hash.given - testHash("auto") + validate("auto.hash") } locally { - import semiInstances.given - testHash("semiauto") + import semiHash.given + validate("semiauto.hash") + } + + locally { + import derivedHash.* + val instance = "derived.hash" + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].hash) + checkAll(s"$instance[Inner]", tests[Inner].hash) + checkAll(s"$instance[Outer]", tests[Outer].hash) + // FIXME: typelevel/cats#2878 + // checkAll(s"$context[Interleaved[Int]]", tests[Interleaved[Int]].hash) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].hash) + checkAll(s"$instance[Recursive]", tests[Recursive].hash) + checkAll(s"$instance[EnumK0]", tests[EnumK0].hash) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Hash[Inner]])) } end HashSuite @@ -39,7 +53,7 @@ end HashSuite object HashSuite: import TestDefns.* - object semiInstances: + object semiHash: given Hash[IList[Int]] = semiauto.hash given Hash[Inner] = semiauto.hash given Hash[Outer] = semiauto.hash @@ -48,4 +62,13 @@ object HashSuite: given Hash[Recursive] = semiauto.hash given Hash[EnumK0] = semiauto.hash + object derivedHash: + case class IList[A](x: TestDefns.IList[A]) derives Hash + case class Inner(x: TestDefns.Inner) derives Hash + case class Outer(x: TestDefns.Outer) derives Hash + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Hash + case class Tree[A](x: TestDefns.Tree[A]) derives Hash + case class Recursive(x: TestDefns.Recursive) derives Hash + case class EnumK0(x: TestDefns.EnumK0) derives Hash + end HashSuite diff --git a/core/src/test/scala-3/cats/derived/HashTests.scala b/core/src/test/scala-3/cats/derived/HashTests.scala deleted file mode 100644 index 49de408d..00000000 --- a/core/src/test/scala-3/cats/derived/HashTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -class HashTests { // - case class Foo(i: Int, b: Option[String]) derives Hash -} From 0ffbf9f1bad1daad74805857cd41f862034c5f85 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 09:54:03 +0200 Subject: [PATCH 15/29] Extend InvariantSuite with derived cases --- .../cats/derived/ContravariantSuite.scala | 11 +-- .../test/scala-3/cats/derived/HashSuite.scala | 2 +- .../scala-3/cats/derived/InvariantSuite.scala | 84 +++++++++---------- 3 files changed, 43 insertions(+), 54 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index 3d2885fa..7737ca50 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -35,20 +35,11 @@ class ContravariantSuite extends KittensSuite: checkAll(s"$instance[ListPred]", tests[ListPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[GenericAdtPred]", tests[GenericAdtPred].contravariant[MiniInt, String, Boolean]) // TODO: https://github.com/typelevel/kittens/issues/473 - // checkAll(s"instance[InterleavedPred]", tests[InterleavedPred].contravariant[MiniInt, String, Boolean]) + // checkAll(s"$instance[InterleavedPred]", tests[InterleavedPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[AndCharPred]", tests[AndCharPred].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[ListSnocF]", tests[ListSnocF].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[TreePred]])) - // TODO: https://github.com/typelevel/kittens/issues/476 - // test(s"instance.contramap is stack safe") { - // val C = summonInline[Contravariant[ListSnocF]] - // val n = 10000 - // val largeBoxed = Snoc.fromSeq((1 until n).map((j: Int) => (i: Int) => i + j)) :: Nil - // val actualBoxed = C.contramap[Int, Int](largeBoxed)((j: Int) => j + 1).flatMap(Snoc.toList) - // val expected = (3 until n + 2).toList - // assert(actualBoxed.map(_.apply(1)) == expected) - // } locally { import auto.contravariant.given diff --git a/core/src/test/scala-3/cats/derived/HashSuite.scala b/core/src/test/scala-3/cats/derived/HashSuite.scala index d9a06180..41abb392 100644 --- a/core/src/test/scala-3/cats/derived/HashSuite.scala +++ b/core/src/test/scala-3/cats/derived/HashSuite.scala @@ -18,7 +18,7 @@ class HashSuite extends KittensSuite: checkAll(s"$instance[Inner]", tests[Inner].hash) checkAll(s"$instance[Outer]", tests[Outer].hash) // FIXME: typelevel/cats#2878 - // checkAll(s"$context[Interleaved[Int]]", tests[Interleaved[Int]].hash) + // checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].hash) checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].hash) checkAll(s"$instance[Recursive]", tests[Recursive].hash) checkAll(s"$instance[EnumK0]", tests[EnumK0].hash) diff --git a/core/src/test/scala-3/cats/derived/InvariantSuite.scala b/core/src/test/scala-3/cats/derived/InvariantSuite.scala index 5a99b794..b95f09b8 100644 --- a/core/src/test/scala-3/cats/derived/InvariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/InvariantSuite.scala @@ -28,43 +28,43 @@ class InvariantSuite extends KittensSuite: import InvariantSuite.* import TestDefns.* - inline def invariantTests[F[_]]: InvariantTests[F] = + inline def tests[F[_]]: InvariantTests[F] = InvariantTests[F](summonInline) - inline def testInvariant(context: String): Unit = { - checkAll(s"$context.Invariant[TreeF]", invariantTests[TreeF].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant[GenAdtF]", invariantTests[GenericAdtF].invariant[MiniInt, String, Boolean]) - // TODO https://github.com/typelevel/kittens/issues/473 - // checkAll(s"$context.Invariant[InterleavedF]", invariantTests[InterleavedF].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant[AndCharF]", invariantTests[AndCharF].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant[ListSnoc", invariantTests[ListSnoc].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant[Bivariant]", invariantTests[Bivariant].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant[EnumK1Inv]", invariantTests[EnumK1Inv].invariant[MiniInt, String, Boolean]) - checkAll(s"$context.Invariant is Serializable", SerializableTests.serializable(summonInline[Invariant[TreeF]])) + inline def validate(instance: String): Unit = + checkAll(s"$instance[TreeF]", tests[TreeF].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[GenAdtF]", tests[GenericAdtF].invariant[MiniInt, String, Boolean]) + // TODO: https://github.com/typelevel/kittens/issues/473 + // checkAll(s"$instance[InterleavedF]", tests[InterleavedF].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AndCharF]", tests[AndCharF].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[ListSnoc]", tests[ListSnoc].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[IList]", tests[IList].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[Bivariant]", tests[Bivariant].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[EnumK1Inv]", tests[EnumK1Inv].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[Many]", tests[Many].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Invariant[TreeF]])) - // TODO https://github.com/typelevel/kittens/issues/476 - // test(s"$context.Invariant.imap is stack safe") { - // val I = summonInline[Invariant[ListSnoc]] - // val J = summonInline[Invariant[IList]] - // val n = 10000 - // val largeIList = IList.fromSeq(1 until n) - // val largeSnoc = Snoc.fromSeq(1 until n) :: Nil - // val actualIList = IList.toList(J.imap(largeIList)(_ + 1)(_ - 1)) - // val actualSnoc = I.imap(largeSnoc)(_ + 1)(_ - 1).flatMap(Snoc.toList) - // val expected = (2 until n + 1).toList - // assert(actualIList == expected) - // assert(actualSnoc == expected) - // } + locally { + import auto.invariant.given + validate("auto.invariant") } locally { - import auto.invariant.given - testInvariant("auto") + import semiInvariant.given + validate("semiauto.invariant") } locally { - import semiInstances.given - testInvariant("semiauto") + import derivedInvariant.* + val instance = "derived.invariant" + checkAll(s"$instance[IList]", tests[IList].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[Bivariant]", tests[Bivariant].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[EnumK1Inv]", tests[EnumK1Inv].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[Many]", tests[Many].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].invariant[MiniInt, String, Boolean]) } end InvariantSuite @@ -79,9 +79,10 @@ object InvariantSuite: type AndCharF[A] = (A => Boolean, Char) type TreeF[A] = Tree[A => Boolean] - object semiInstances: + object semiInvariant: given Invariant[GenericAdtF] = semiauto.invariant given Invariant[ListFToInt] = semiauto.invariant + // TODO: https://github.com/typelevel/kittens/issues/473 // given Invariant[InterleavedF] = semiauto.invariant given Invariant[AndCharF] = semiauto.invariant given Invariant[TreeF] = semiauto.invariant @@ -90,19 +91,16 @@ object InvariantSuite: given Invariant[Bivariant] = semiauto.invariant given Invariant[IList] = semiauto.invariant given Invariant[EnumK1Inv] = semiauto.invariant - - case class Single[A](value: A) derives Invariant - - enum Many[A] derives Invariant: - case Naught() - case More(value: A, rest: Many[A]) - - enum AtMostOne[A] derives Invariant: - case Naught() - case Single(value: A) - - enum AtLeastOne[A] derives Invariant: - case Single(value: A) - case More(value: A, rest: Option[AtLeastOne[A]]) + given Invariant[Many] = semiauto.invariant + given Invariant[AtMostOne] = semiauto.invariant + given Invariant[AtLeastOne] = semiauto.invariant + + object derivedInvariant: + case class Bivariant[A](x: TestDefns.Bivariant[A]) derives Invariant + case class IList[A](x: TestDefns.IList[A]) derives Invariant + case class EnumK1Inv[A](x: TestDefns.EnumK1Inv[A]) derives Invariant + case class Many[A](x: TestDefns.Many[A]) derives Invariant + case class AtMostOne[A](x: TestDefns.AtMostOne[A]) derives Invariant + case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Invariant end InvariantSuite From 6d11ce9f94e93dcf359038fd5659fbe9eb1e59e7 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:02:48 +0200 Subject: [PATCH 16/29] Extend MonoidKSuite with derived cases --- .../scala-3/cats/derived/MonoidKSuite.scala | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala index 84890097..778f45a1 100644 --- a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala @@ -10,15 +10,15 @@ class MonoidKSuite extends KittensSuite: import MonoidKSuite.* import TestDefns.* - inline def monoidKTests[F[_]]: MonoidKTests[F] = + inline def tests[F[_]]: MonoidKTests[F] = MonoidKTests[F](summonInline) - inline def testMonoidK(context: String): Unit = - checkAll(s"$context.MonoidK[ComplexProduct]", monoidKTests[ComplexProduct].monoidK[Char]) - checkAll(s"$context.MonoidK[CaseClassWOption]", monoidKTests[CaseClassWOption].monoidK[Char]) - checkAll(s"$context.MonoidK[BoxMul]", monoidKTests[BoxMul].monoidK[Char]) - checkAll(s"$context.MonoidK is Serializable", SerializableTests.serializable(summonInline[MonoidK[ComplexProduct]])) - test(s"$context.MonoidK respects existing instances") { + inline def validate(instance: String): Unit = + checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].monoidK[Char]) + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].monoidK[Char]) + checkAll(s"$instance[BoxMul]", tests[BoxMul].monoidK[Char]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[MonoidK[ComplexProduct]])) + test(s"$instance respects existing instances") { val M = summonInline[MonoidK[BoxMul]] assert(M.empty[Char] == Box(Mul[Char](1))) assert(M.combineK(Box(Mul[Char](5)), Box(Mul[Char](5))) == Box(Mul[Char](25))) @@ -26,12 +26,21 @@ class MonoidKSuite extends KittensSuite: locally { import auto.monoidK.given - testMonoidK("auto") + validate("auto.monoidK") } locally { - import monInstances.given - testMonoidK("semi") + import semiMonoidK.given + validate("semiauto.monoidK") + } + + locally { + import derivedMonoidK.* + val instance = "derived.monoidK" + checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].monoidK[Char]) + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].monoidK[Char]) + checkAll(s"$instance[Simple]", tests[Simple].monoidK[Char]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[MonoidK[ComplexProduct]])) } end MonoidKSuite @@ -41,22 +50,23 @@ object MonoidKSuite: type BoxMul[A] = Box[Mul[A]] - object monInstances: + object semiMonoidK: given MonoidK[ComplexProduct] = semiauto.monoidK given MonoidK[CaseClassWOption] = semiauto.monoidK given MonoidK[BoxMul] = semiauto.monoidK + object derivedMonoidK: + case class ComplexProduct[A](x: TestDefns.ComplexProduct[A]) derives MonoidK + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives MonoidK + case class Simple[A](value1: List[A], value2: Set[A]) derives MonoidK + case class Recursive[A](first: List[A], rest: Recursive[A]) derives MonoidK + final case class Mul[T](value: Int) object Mul: given [T]: Eq[Mul[T]] = Eq.by(_.value) - given [T]: Arbitrary[Mul[T]] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) - given MonoidK[Mul] with def empty[A] = Mul(1) def combineK[A](x: Mul[A], y: Mul[A]) = Mul(x.value * y.value) - case class Simple[A](value1: List[A], value2: Set[A]) derives MonoidK - case class Recursive[A](first: List[A], rest: Recursive[A]) derives MonoidK - end MonoidKSuite From 4409e8569e7358be8be4e7ec0d154dc7521965c4 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:07:49 +0200 Subject: [PATCH 17/29] Extend MonoidSuite with derived cases --- .../scala-3/cats/derived/MonoidSuite.scala | 43 +++++++++++++------ .../scala-3/cats/derived/MonoidTests.scala | 9 ---- 2 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/MonoidTests.scala diff --git a/core/src/test/scala-3/cats/derived/MonoidSuite.scala b/core/src/test/scala-3/cats/derived/MonoidSuite.scala index f19417f8..cf5459b5 100644 --- a/core/src/test/scala-3/cats/derived/MonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidSuite.scala @@ -26,16 +26,16 @@ class MonoidSuite extends KittensSuite: import MonoidSuite.* import TestDefns.* - inline def monoidTests[A]: MonoidTests[A] = + inline def tests[A]: MonoidTests[A] = MonoidTests[A](summonInline) - inline def testMonoid(inline context: String): Unit = - checkAll(s"$context.Monoid[Foo]", monoidTests[Foo].monoid) - checkAll(s"$context.Monoid[Interleaved[Int]]", monoidTests[Interleaved[Int]].monoid) - checkAll(s"$context.Monoid[Box[Mul]]", monoidTests[Box[Mul]].monoid) - checkAll(s"$context.Monoid[Recursive]", monoidTests[Recursive].monoid) - checkAll(s"$context.Monoid is Serializable", SerializableTests.serializable(summonInline[Monoid[Foo]])) - test(s"$context.Monoid respects existing instances") { + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[Foo]", tests[Foo].monoid) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].monoid) + checkAll(s"$instance[Box[Mul]]", tests[Box[Mul]].monoid) + checkAll(s"$instance[Recursive]", tests[Recursive].monoid) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Monoid[Foo]])) + test(s"$instance respects existing instances") { val box = summonInline[Monoid[Box[Mul]]] assert(box.empty == Box(Mul(1))) assert(box.combine(Box(Mul(5)), Box(Mul(5))) == Box(Mul(25))) @@ -43,12 +43,26 @@ class MonoidSuite extends KittensSuite: locally { import auto.monoid.given - testMonoid("auto") + validate("auto.monoid") } locally { - import semiInstances.given - testMonoid("semiauto") + import semiMonoid.given + validate("semiauto.monoid") + } + + locally { + import derivedMonoid.* + val instance = "derived.monoid" + checkAll(s"$instance[Foo]", tests[Foo].monoid) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].monoid) + checkAll(s"$instance[BoxMul]", tests[BoxMul].monoid) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Monoid[Foo]])) + test(s"$instance respects existing instances") { + val box = summonInline[Monoid[BoxMul]] + assert(box.empty == BoxMul(Box(Mul(1)))) + assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))) == BoxMul(Box(Mul(25)))) + } } end MonoidSuite @@ -56,12 +70,17 @@ end MonoidSuite object MonoidSuite: import TestDefns.* - object semiInstances: + object semiMonoid: given Monoid[Foo] = semiauto.monoid given Monoid[Recursive] = semiauto.monoid given Monoid[Interleaved[Int]] = semiauto.monoid given Monoid[Box[Mul]] = semiauto.monoid + object derivedMonoid: + case class Foo(x: TestDefns.Foo) derives Monoid + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Monoid + case class BoxMul(x: Box[Mul]) derives Monoid + final case class Mul(value: Int) object Mul: given Eq[Mul] = Eq.fromUniversalEquals diff --git a/core/src/test/scala-3/cats/derived/MonoidTests.scala b/core/src/test/scala-3/cats/derived/MonoidTests.scala deleted file mode 100644 index 412a36d1..00000000 --- a/core/src/test/scala-3/cats/derived/MonoidTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -class MonoidTests { // - case class Foo(i: Int, b: Option[String]) derives Monoid, Empty, Semigroup -} From 2ddb0327d6635006ab73b33ffa7f2a8355200fdb Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:15:35 +0200 Subject: [PATCH 18/29] Extend NonEmptyTraverseSuite with derived instances --- .../cats/derived/NonEmptyTraverseSuite.scala | 83 ++++++++++++++----- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala index b8a37cf4..6aef1d2b 100644 --- a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala @@ -29,51 +29,84 @@ class NonEmptyTraverseSuite extends KittensSuite: import NonEmptyTraverseSuite.* import TestDefns.* - inline def nonEmptyTraverseTests[F[_]]: NonEmptyTraverseTests[F] = + inline def tests[F[_]]: NonEmptyTraverseTests[F] = NonEmptyTraverseTests[F](summonInline) - inline def testReducible(inline context: String): Unit = + inline def validate(inline instance: String): Unit = checkAll( - s"$context.NonEmptyTraverse[ICons]", - nonEmptyTraverseTests[ICons].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[ICons]", + tests[ICons].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[Tree]", - nonEmptyTraverseTests[Tree].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[Tree]", + tests[Tree].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[NelSCons]", - nonEmptyTraverseTests[NelSCons].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[NelSCons]", + tests[NelSCons].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[NelAndOne]", - nonEmptyTraverseTests[NelAndOne].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[NelAndOne]", + tests[NelAndOne].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[VecAndNel]", - nonEmptyTraverseTests[VecAndNel].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[VecAndNel]", + tests[VecAndNel].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[Interleaved]", - nonEmptyTraverseTests[Interleaved].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[Interleaved]", + tests[Interleaved].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse[EnumK1]", - nonEmptyTraverseTests[EnumK1].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + s"$instance[EnumK1]", + tests[EnumK1].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) checkAll( - s"$context.NonEmptyTraverse is Serializable", + s"$instance[AtLeastOne]", + tests[AtLeastOne].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance is Serializable", SerializableTests.serializable(summonInline[NonEmptyTraverse[Tree]]) ) locally { import auto.nonEmptyTraverse.given - testReducible("auto") + validate("auto.nonEmptyTraverse") } locally { - import semiInstances.given - testReducible("semiauto") + import semiNonEmptyTraverse.given + validate("semiauto.nonEmptyTraverse") + } + + locally { + import derivedNonEmptyTraverse.* + val instance = "derived.nonEmptyTraverse" + checkAll( + s"$instance[ICons]", + tests[ICons].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance[Tree]", + tests[Tree].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance[Interleaved]", + tests[Interleaved].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance[EnumK1]", + tests[EnumK1].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance[AtLeastOne]", + tests[AtLeastOne].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] + ) + checkAll( + s"$instance is Serializable", + SerializableTests.serializable(summonInline[NonEmptyTraverse[Tree]]) + ) } end NonEmptyTraverseSuite @@ -85,7 +118,7 @@ object NonEmptyTraverseSuite: type NelAndOne[A] = NonEmptyList[OneAnd[Vector, A]] type VecAndNel[A] = (Vector[A], NonEmptyList[A]) - object semiInstances: + object semiNonEmptyTraverse: given NonEmptyTraverse[ICons] = semiauto.nonEmptyTraverse given NonEmptyTraverse[Tree] = semiauto.nonEmptyTraverse given NonEmptyTraverse[NelSCons] = semiauto.nonEmptyTraverse @@ -93,5 +126,13 @@ object NonEmptyTraverseSuite: given NonEmptyTraverse[VecAndNel] = semiauto.nonEmptyTraverse given NonEmptyTraverse[Interleaved] = semiauto.nonEmptyTraverse given NonEmptyTraverse[EnumK1] = semiauto.nonEmptyTraverse + given NonEmptyTraverse[AtLeastOne] = semiauto.nonEmptyTraverse + + object derivedNonEmptyTraverse: + case class ICons[A](x: TestDefns.ICons[A]) derives NonEmptyTraverse + case class Tree[A](x: TestDefns.Tree[A]) derives NonEmptyTraverse + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives NonEmptyTraverse + case class EnumK1[A](x: TestDefns.EnumK1[A]) derives NonEmptyTraverse + case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives NonEmptyTraverse end NonEmptyTraverseSuite From fa4ca488adbad1e31c7fb0b0989626034d0ee624 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:20:36 +0200 Subject: [PATCH 19/29] Extend OrderSuite with derived instances --- .../scala-3/cats/derived/OrderSuite.scala | 68 ++++++++++++------- .../scala-3/cats/derived/OrderTests.scala | 9 --- 2 files changed, 44 insertions(+), 33 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/OrderTests.scala diff --git a/core/src/test/scala-3/cats/derived/OrderSuite.scala b/core/src/test/scala-3/cats/derived/OrderSuite.scala index e0b7c031..bb5c5144 100644 --- a/core/src/test/scala-3/cats/derived/OrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/OrderSuite.scala @@ -21,43 +21,63 @@ import cats.kernel.laws.discipline.{OrderTests, SerializableTests} import org.scalacheck.Arbitrary import scala.compiletime.summonInline -class OrderSuite extends KittensSuite { - import OrderSuite._ - import TestDefns._ +class OrderSuite extends KittensSuite: + import OrderSuite.* + import TestDefns.* - inline def orderTests[A]: OrderTests[A] = + inline def tests[A]: OrderTests[A] = OrderTests[A](summonInline) - inline def testOrder(context: String): Unit = { - checkAll(s"$context.Order[Inner]", orderTests[Inner].order) - checkAll(s"$context.Order[Outer]", orderTests[Outer].order) - checkAll(s"$context.Order[Interleaved[Int]]", orderTests[Interleaved[Int]].order) - checkAll(s"$context.Order[Recursive]", orderTests[Recursive].order) - checkAll(s"$context.Order[GenericAdt[Int]]", orderTests[GenericAdt[Int]].order) - checkAll(s"$context.Order[EnumK0]", orderTests[EnumK0].order) - checkAll(s"$context.Order is Serializable", SerializableTests.serializable(summonInline[Order[Interleaved[Int]]])) - } + inline def validate(instance: String): Unit = + checkAll(s"$instance[Inner]", tests[Inner].order) + checkAll(s"$instance[Outer]", tests[Outer].order) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].order) + checkAll(s"$instance[Recursive]", tests[Recursive].order) + checkAll(s"$instance[GenericAdt[Int]]", tests[GenericAdt[Int]].order) + checkAll(s"$instance[EnumK0]", tests[EnumK0].order) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Order[Interleaved[Int]]])) - { + locally { import auto.order.given - testOrder("auto") + validate("auto.order") + } + + locally { + import semiOrder.given + validate("semiauto.order") } - { - import semiInstances.given - testOrder("semiauto") + locally { + import derivedOrder.* + val instance = "derived.order" + checkAll(s"$instance[Inner]", tests[Inner].order) + checkAll(s"$instance[Outer]", tests[Outer].order) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].order) + checkAll(s"$instance[Recursive]", tests[Recursive].order) + checkAll(s"$instance[GenericAdt[Int]]", tests[GenericAdt[Int]].order) + checkAll(s"$instance[EnumK0]", tests[EnumK0].order) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Order[Interleaved[Int]]])) } -} -object OrderSuite { - import TestDefns._ +end OrderSuite + +object OrderSuite: + import TestDefns.* - object semiInstances { + object semiOrder: given Order[Inner] = semiauto.order given Order[Outer] = semiauto.order given Order[Interleaved[Int]] = semiauto.order given Order[Recursive] = semiauto.order given Order[GenericAdt[Int]] = semiauto.order given Order[EnumK0] = semiauto.order - } -} + + object derivedOrder: + case class Inner(x: TestDefns.Inner) derives Order + case class Outer(x: TestDefns.Outer) derives Order + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Order + case class Recursive(x: TestDefns.Recursive) derives Order + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Order + case class EnumK0(x: TestDefns.EnumK0) derives Order + +end OrderSuite diff --git a/core/src/test/scala-3/cats/derived/OrderTests.scala b/core/src/test/scala-3/cats/derived/OrderTests.scala deleted file mode 100644 index 01e7d855..00000000 --- a/core/src/test/scala-3/cats/derived/OrderTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -class OrderTests { // - case class Foo(i: Int, b: Option[String]) derives Order -} From 43992b3049c67ec6e307527e8d4cb3e1b4b536f6 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:34:30 +0200 Subject: [PATCH 20/29] Extend PartialOrderSuite with derived instances --- .../cats/derived/CommutativeMonoidSuite.scala | 4 -- .../derived/CommutativeSemigroupSuite.scala | 4 -- .../scala-3/cats/derived/FoldableSuite.scala | 14 +--- .../scala-3/cats/derived/MonoidKSuite.scala | 6 +- .../scala-3/cats/derived/MonoidSuite.scala | 5 +- .../cats/derived/PartialOrderSuite.scala | 67 ++++++++++++------- 6 files changed, 45 insertions(+), 55 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index 854abfbe..1808e899 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -16,10 +16,8 @@ package cats.derived -import cats.Eq import cats.kernel.{CommutativeMonoid, CommutativeSemigroup} import cats.kernel.laws.discipline.{CommutativeMonoidTests, SerializableTests} -import org.scalacheck.Arbitrary import scala.compiletime.* @@ -88,8 +86,6 @@ object CommutativeMonoidSuite: final case class Mul(value: Int) object Mul: - given Eq[Mul] = Eq.fromUniversalEquals - given Arbitrary[Mul] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) given CommutativeMonoid[Mul] with val empty = Mul(1) def combine(x: Mul, y: Mul) = Mul(x.value * y.value) diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index e900276d..8916569f 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -16,10 +16,8 @@ package cats.derived -import cats.Eq import cats.kernel.CommutativeSemigroup import cats.kernel.laws.discipline.{CommutativeSemigroupTests, SerializableTests} -import org.scalacheck.Arbitrary import scala.compiletime.* @@ -86,8 +84,6 @@ object CommutativeSemigroupSuite: final case class Mul(value: Int) object Mul: - given Eq[Mul] = Eq.fromUniversalEquals - given Arbitrary[Mul] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) given CommutativeSemigroup[Mul] = (x, y) => Mul(x.value * y.value) end CommutativeSemigroupSuite diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 33cc6b89..097d9c72 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -14,12 +14,11 @@ * limitations under the License. */ -package cats -package derived +package cats.derived +import cats.{Eval, Foldable} import cats.laws.discipline.{FoldableTests, SerializableTests} import cats.syntax.all.* -import org.scalacheck.{Arbitrary, Gen} import scala.compiletime.* class FoldableSuite extends KittensSuite: @@ -106,15 +105,6 @@ object FoldableSuite: final case class Nel[+A](head: A, tail: List[A]) object Nel: - given [A: Eq]: Eq[Nel[A]] = - (x, y) => x.head === y.head && x.tail === y.tail - - given [A: Arbitrary]: Arbitrary[Nel[A]] = - Arbitrary(for - head <- Arbitrary.arbitrary[A] - tail <- Arbitrary.arbitrary[List[A]] - yield Nel(head, tail)) - given Foldable[Nel] with def foldLeft[A, B](fa: Nel[A], b: B)(f: (B, A) => B) = fa.tail.foldl(b)(f) def foldRight[A, B](fa: Nel[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]) = fa.tail.foldr(lb)(f) diff --git a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala index 778f45a1..8e6db5ca 100644 --- a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala @@ -1,9 +1,7 @@ package cats.derived -import alleycats.* -import cats.* +import cats.MonoidK import cats.laws.discipline.{MonoidKTests, SerializableTests} -import org.scalacheck.Arbitrary import scala.compiletime.* class MonoidKSuite extends KittensSuite: @@ -63,8 +61,6 @@ object MonoidKSuite: final case class Mul[T](value: Int) object Mul: - given [T]: Eq[Mul[T]] = Eq.by(_.value) - given [T]: Arbitrary[Mul[T]] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) given MonoidK[Mul] with def empty[A] = Mul(1) def combineK[A](x: Mul[A], y: Mul[A]) = Mul(x.value * y.value) diff --git a/core/src/test/scala-3/cats/derived/MonoidSuite.scala b/core/src/test/scala-3/cats/derived/MonoidSuite.scala index cf5459b5..5cd3db77 100644 --- a/core/src/test/scala-3/cats/derived/MonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidSuite.scala @@ -16,9 +16,8 @@ package cats.derived -import cats.{Eq, Monoid} +import cats.Monoid import cats.kernel.laws.discipline.{MonoidTests, SerializableTests} -import org.scalacheck.Arbitrary import scala.compiletime.* @@ -83,8 +82,6 @@ object MonoidSuite: final case class Mul(value: Int) object Mul: - given Eq[Mul] = Eq.fromUniversalEquals - given Arbitrary[Mul] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) given Monoid[Mul] with val empty = Mul(1) def combine(x: Mul, y: Mul) = Mul(x.value * y.value) diff --git a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala index af35587b..c19d582d 100644 --- a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala @@ -18,31 +18,26 @@ package cats package derived import cats.kernel.laws.discipline.{PartialOrderTests, SerializableTests} -import org.scalacheck.{Arbitrary, Cogen} import scala.compiletime.* class PartialOrderSuite extends KittensSuite: import PartialOrderSuite.* import TestDefns.* - inline def partialOrderTests[A]: PartialOrderTests[A] = + inline def tests[A]: PartialOrderTests[A] = PartialOrderTests[A](summonInline) - inline def testPartialOrder(context: String): Unit = - checkAll(s"$context.PartialOrder[IList[Int]]", partialOrderTests[IList[Int]].partialOrder) - checkAll(s"$context.PartialOrder[Inner]", partialOrderTests[Inner].partialOrder) - checkAll(s"$context.PartialOrder[Outer]", partialOrderTests[Outer].partialOrder) - checkAll(s"$context.PartialOrder[Interleaved[Int]]", partialOrderTests[Interleaved[Int]].partialOrder) - checkAll(s"$context.PartialOrder[Tree[Int]]", partialOrderTests[Tree[Int]].partialOrder) - checkAll(s"$context.PartialOrder[Recursive]", partialOrderTests[Recursive].partialOrder) - checkAll(s"$context.PartialOrder[Box[KeyValue]]", partialOrderTests[Box[KeyValue]].partialOrder) - checkAll(s"$context.PartialOrder[EnumK0]", partialOrderTests[EnumK0].partialOrder) - checkAll( - s"$context.PartialOrder is Serialiable", - SerializableTests.serializable(summonInline[PartialOrder[Tree[Int]]]) - ) - - test(s"$context.PartialOrder respects existing instances") { + inline def validate(instance: String): Unit = + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].partialOrder) + checkAll(s"$instance[Inner]", tests[Inner].partialOrder) + checkAll(s"$instance[Outer]", tests[Outer].partialOrder) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].partialOrder) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].partialOrder) + checkAll(s"$instance[Recursive]", tests[Recursive].partialOrder) + checkAll(s"$instance[Box[KeyValue]]", tests[Box[KeyValue]].partialOrder) + checkAll(s"$instance[EnumK0]", tests[EnumK0].partialOrder) + checkAll(s"$instance is Serialiable", SerializableTests.serializable(summonInline[PartialOrder[Tree[Int]]])) + test(s"$instance respects existing instances") { val boxKeyValue = summonInline[PartialOrder[Box[KeyValue]]] val x = Box(KeyValue("red", 1)) val y = Box(KeyValue("red", 2)) @@ -53,12 +48,26 @@ class PartialOrderSuite extends KittensSuite: locally { import auto.partialOrder.given - testPartialOrder("auto") + validate("auto.partialOrder") + } + + locally { + import semiPartialOrder.given + validate("semiauto.partialOrder") } locally { - import semiInstances.given - testPartialOrder("semiauto") + import derivedPartialOrder.* + val instance = "derived.partialOrder" + checkAll(s"$instance[IList[Int]]", tests[IList[Int]].partialOrder) + checkAll(s"$instance[Inner]", tests[Inner].partialOrder) + checkAll(s"$instance[Outer]", tests[Outer].partialOrder) + checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].partialOrder) + checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].partialOrder) + checkAll(s"$instance[Recursive]", tests[Recursive].partialOrder) + checkAll(s"$instance[BoxKV]", tests[BoxKV].partialOrder) + checkAll(s"$instance[EnumK0]", tests[EnumK0].partialOrder) + checkAll(s"$instance is Serialiable", SerializableTests.serializable(summonInline[PartialOrder[Tree[Int]]])) } end PartialOrderSuite @@ -66,7 +75,7 @@ end PartialOrderSuite object PartialOrderSuite: import TestDefns.* - object semiInstances: + object semiPartialOrder: given PartialOrder[IList[Int]] = semiauto.partialOrder given PartialOrder[Inner] = semiauto.partialOrder given PartialOrder[Outer] = semiauto.partialOrder @@ -76,12 +85,18 @@ object PartialOrderSuite: given PartialOrder[Box[KeyValue]] = semiauto.partialOrder given PartialOrder[EnumK0] = semiauto.partialOrder - final case class KeyValue(key: String, value: Int) - object KeyValue extends ((String, Int) => KeyValue): - given Arbitrary[KeyValue] = Arbitrary(Arbitrary.arbitrary[(String, Int)].map(tupled)) - - given Cogen[KeyValue] = Cogen[(String, Int)].contramap(kv => kv.key -> kv.value) + object derivedPartialOrder: + case class IList[A](x: TestDefns.IList[A]) derives PartialOrder + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives PartialOrder + case class Tree[A](x: TestDefns.Tree[A]) derives PartialOrder + case class Inner(x: TestDefns.Inner) derives PartialOrder + case class Outer(x: TestDefns.Outer) derives PartialOrder + case class Recursive(x: TestDefns.Recursive) derives PartialOrder + case class EnumK0(x: TestDefns.EnumK0) derives PartialOrder + case class BoxKV(x: Box[KeyValue]) derives PartialOrder + final case class KeyValue(key: String, value: Int) + object KeyValue: given PartialOrder[KeyValue] = PartialOrder.from((x, y) => if (x.key == y.key) x.value.toDouble - y.value.toDouble else Double.NaN) From 171073c4cb6161b28d09c78bfff41b4e4f370425 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:40:29 +0200 Subject: [PATCH 21/29] Extend PureSuite with derived cases --- .../test/scala-3/cats/derived/PureSuite.scala | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/PureSuite.scala b/core/src/test/scala-3/cats/derived/PureSuite.scala index 8c2c9145..5e100b6a 100644 --- a/core/src/test/scala-3/cats/derived/PureSuite.scala +++ b/core/src/test/scala-3/cats/derived/PureSuite.scala @@ -30,29 +30,41 @@ class PureSuite extends KittensSuite: inline def pure[F[_]] = summonInline[Pure[F]].pure(a) - inline def testPure(inline context: String): Unit = - test(s"$context.Pure[LOption]")(assert(42.pure[LOption] == Some(42) :: Nil)) - test(s"$context.Pure[PList]")(assert("Scala".pure[PList] == ("Scala" :: Nil, "Scala" :: Nil))) - test(s"$context.Pure[CaseClassWOption]")(assert(3.14.pure[CaseClassWOption] == CaseClassWOption(Some(3.14)))) - test(s"$context.Pure[NelOption]")(assert(42.pure[NelOption] == NonEmptyList.of(Some(42)))) - test(s"$context.Pure[Interleaved]")(assert('x'.pure[Interleaved] == Interleaved(0, 'x', 0, Vector('x'), ""))) - test(s"$context.Pure respects existing instances")(assert(().pure[BoxColor] == Box(Color(255, 255, 255)))) - checkAll(s"$context.Pure is Serializable", SerializableTests.serializable(summonInline[Pure[Interleaved]])) + inline def validate(inline instance: String): Unit = + test(s"$instance[LOption]")(assert(42.pure[LOption] == Some(42) :: Nil)) + test(s"$instance[PList]")(assert("Scala".pure[PList] == ("Scala" :: Nil, "Scala" :: Nil))) + test(s"$instance[CaseClassWOption]")(assert(3.14.pure[CaseClassWOption] == CaseClassWOption(Some(3.14)))) + test(s"$instance[NelOption]")(assert(42.pure[NelOption] == NonEmptyList.of(Some(42)))) + test(s"$instance[Interleaved]")(assert('x'.pure[Interleaved] == Interleaved(0, 'x', 0, Vector('x'), ""))) + test(s"$instance respects existing instances")(assert(().pure[BoxColor] == Box(Color(255, 255, 255)))) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Pure[Interleaved]])) locally { import auto.pure.given - testPure("auto") + validate("auto.pure") testNoAuto("Pure", "IList") testNoAuto("Pure", "Snoc") } locally { - import semiInstances.given - testPure("semiauto") + import semiPure.given + validate("semiauto.pure") testNoSemi("Pure", "IList") testNoSemi("Pure", "Snoc") } + locally { + import derivedPure.* + val instance = "derived.pure" + test(s"$instance[CaseClassWOption]")( + assert(3.14.pure[CaseClassWOption].x == TestDefns.CaseClassWOption(Some(3.14))) + ) + test(s"$instance[Interleaved]")( + assert('x'.pure[Interleaved].x == TestDefns.Interleaved(0, 'x', 0, Vector('x'), "")) + ) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Pure[Interleaved]])) + } + end PureSuite object PureSuite: @@ -63,7 +75,7 @@ object PureSuite: type NelOption[A] = NonEmptyList[Option[A]] type BoxColor[A] = Box[Color[A]] - object semiInstances: + object semiPure: given Pure[LOption] = semiauto.pure given Pure[PList] = semiauto.pure given Pure[CaseClassWOption] = semiauto.pure @@ -71,6 +83,10 @@ object PureSuite: given Pure[Interleaved] = semiauto.pure given Pure[BoxColor] = semiauto.pure + object derivedPure: + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Pure + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Pure + final case class Color[A](r: Int, g: Int, b: Int) object Color: given Pure[Color] with From 02f00dd52ecd089c35de565252e8c9439b5da472 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 10:46:35 +0200 Subject: [PATCH 22/29] Extend ReducibleSuite with derived instances --- .../scala-3/cats/derived/ReducibleSuite.scala | 61 ++++++++++--------- .../scala-3/cats/derived/ReducibleTests.scala | 38 ------------ 2 files changed, 33 insertions(+), 66 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/ReducibleTests.scala diff --git a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala index b3b6f8cf..c82b07ef 100644 --- a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala +++ b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala @@ -14,42 +14,51 @@ * limitations under the License. */ -package cats -package derived +package cats.derived +import cats.{Eval, Reducible} import cats.data.{NonEmptyList, OneAnd} import cats.laws.discipline.arbitrary.* import cats.laws.discipline.{ReducibleTests, SerializableTests} import cats.syntax.all.* -import org.scalacheck.Arbitrary import scala.compiletime.* class ReducibleSuite extends KittensSuite: import ReducibleSuite.* import TestDefns.* - inline def reducibleTests[F[_]]: ReducibleTests[F] = + inline def tests[F[_]]: ReducibleTests[F] = ReducibleTests[F](summonInline) - inline def testReducible(context: String): Unit = - checkAll(s"$context.Reducible[ICons]", reducibleTests[ICons].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[Tree]", reducibleTests[Tree].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[NelSCons]", reducibleTests[NelSCons].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[NelAndOne]", reducibleTests[NelAndOne].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[VecAndNel]", reducibleTests[VecAndNel].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[Interleaved]", reducibleTests[Interleaved].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[BoxZipper]", reducibleTests[BoxZipper].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible[EnumK1]", reducibleTests[EnumK1].reducible[Option, Int, Long]) - checkAll(s"$context.Reducible is Serializable", SerializableTests.serializable(summonInline[Reducible[Tree]])) + inline def validate(instance: String): Unit = + checkAll(s"$instance[ICons]", tests[ICons].reducible[Option, Int, Long]) + checkAll(s"$instance[Tree]", tests[Tree].reducible[Option, Int, Long]) + checkAll(s"$instance[NelSCons]", tests[NelSCons].reducible[Option, Int, Long]) + checkAll(s"$instance[NelAndOne]", tests[NelAndOne].reducible[Option, Int, Long]) + checkAll(s"$instance[VecAndNel]", tests[VecAndNel].reducible[Option, Int, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].reducible[Option, Int, Long]) + checkAll(s"$instance[BoxZipper]", tests[BoxZipper].reducible[Option, Int, Long]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].reducible[Option, Int, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Reducible[Tree]])) locally { import auto.reducible.given - testReducible("auto") + validate("auto.reducible") } locally { - import semiInstances.given - testReducible("semiauto") + import semiReducible.given + validate("semiauto.reducible") + } + + locally { + import derivedReducible.* + val instance = "derived.reducible" + checkAll(s"$instance[ICons]", tests[ICons].reducible[Option, Int, Long]) + checkAll(s"$instance[Tree]", tests[Tree].reducible[Option, Int, Long]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].reducible[Option, Int, Long]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].reducible[Option, Int, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Reducible[Tree]])) } end ReducibleSuite @@ -62,7 +71,7 @@ object ReducibleSuite: type VecAndNel[A] = (Vector[A], NonEmptyList[A]) type BoxZipper[A] = Box[Zipper[A]] - object semiInstances: + object semiReducible: given Reducible[ICons] = semiauto.reducible given Reducible[Tree] = semiauto.reducible given Reducible[NelSCons] = semiauto.reducible @@ -72,18 +81,14 @@ object ReducibleSuite: given Reducible[BoxZipper] = semiauto.reducible given Reducible[EnumK1] = semiauto.reducible + object derivedReducible: + case class ICons[A](x: TestDefns.ICons[A]) derives Reducible + case class Tree[A](x: TestDefns.Tree[A]) derives Reducible + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Reducible + case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Reducible + final case class Zipper[+A](left: List[A], focus: A, right: List[A]) object Zipper: - given [A: Eq]: Eq[Zipper[A]] = - (x, y) => x.focus === y.focus && x.left === y.left && x.right === y.right - - given [A: Arbitrary]: Arbitrary[Zipper[A]] = - Arbitrary(for - left <- Arbitrary.arbitrary[List[A]] - focus <- Arbitrary.arbitrary[A] - right <- Arbitrary.arbitrary[List[A]] - yield Zipper(left, focus, right)) - given Reducible[Zipper] with def reduceLeftTo[A, B](fa: Zipper[A])(f: A => B)(g: (B, A) => B) = NonEmptyList(fa.focus, fa.right).reduceLeftTo(f)(g) diff --git a/core/src/test/scala-3/cats/derived/ReducibleTests.scala b/core/src/test/scala-3/cats/derived/ReducibleTests.scala deleted file mode 100644 index b0595b3e..00000000 --- a/core/src/test/scala-3/cats/derived/ReducibleTests.scala +++ /dev/null @@ -1,38 +0,0 @@ -package cats.derived - -import cats.Reducible -import cats.data.NonEmptyList -import cats.instances.all.* -import cats.derived.* -import cats.derived.semiauto.given - -object ReducibleTests: - case class Box[A](value: A) derives Reducible - - sealed trait OneOrMany[+A] derives Reducible - case class One[+A](value: A) extends OneOrMany[A] - case class Many[+A](values: NonEmptyList[A]) extends OneOrMany[A] - - sealed trait CList[A] derives Reducible - case class COne[A](value: A) extends CList[A] - case class CCons[A](head: A, tail: CList[A]) extends CList[A] - - case class NonEmptyTree[A](size: Int, value: A, tree: Tree[A]) - enum Tree[+A]: - case Leaf - case Node(left: Tree[A], value: A, right: Tree[A]) - - case class Foo[A](value: A, xs: List[A]) - enum MyList[+A]: - case Non - case Con(v: A, r: MyList[A]) - - import cats._ - - DerivedFunctor[MyList] - DerivedReducible[NonEmptyTree] - -@main def run() = - println( - DerivedFunctor[ReducibleTests.MyList].map(ReducibleTests.MyList.Con(42, ReducibleTests.MyList.Non))(_.toString) - ) From 8b100ae868237ab222bf2e122d7fd7ec8d3dbf42 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 11:06:12 +0200 Subject: [PATCH 23/29] Extend SemigroupKSuite with derived cases --- .../cats/derived/ApplicativeSuite.scala | 9 ++-- .../scala-3/cats/derived/ApplySuite.scala | 10 ++-- .../cats/derived/CommutativeMonoidSuite.scala | 9 ++-- .../derived/CommutativeSemigroupSuite.scala | 9 ++-- .../cats/derived/ContravariantSuite.scala | 12 ++--- .../scala-3/cats/derived/EmptyKSuite.scala | 5 +- .../scala-3/cats/derived/EmptySuite.scala | 9 ++-- .../test/scala-3/cats/derived/EqSuite.scala | 11 ++--- .../scala-3/cats/derived/FoldableSuite.scala | 10 ++-- .../scala-3/cats/derived/FunctorSuite.scala | 12 ++--- .../test/scala-3/cats/derived/HashSuite.scala | 11 ++--- .../scala-3/cats/derived/InvariantSuite.scala | 14 +++--- .../scala-3/cats/derived/MonoidKSuite.scala | 8 ++-- .../scala-3/cats/derived/MonoidSuite.scala | 9 ++-- .../cats/derived/NonEmptyTraverseSuite.scala | 12 ++--- .../scala-3/cats/derived/OrderSuite.scala | 13 +++-- .../cats/derived/PartialOrderSuite.scala | 14 +++--- .../test/scala-3/cats/derived/PureSuite.scala | 11 ++--- .../scala-3/cats/derived/ReducibleSuite.scala | 10 ++-- .../cats/derived/SemigroupKSuite.scala | 48 ++++++++++--------- 20 files changed, 117 insertions(+), 129 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index b33e5992..44e8cdf5 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -20,7 +20,6 @@ import cats.Applicative import cats.laws.discipline.* import cats.laws.discipline.SemigroupalTests.Isomorphisms import org.scalacheck.Arbitrary - import scala.compiletime.* class ApplicativeSuite extends KittensSuite: @@ -47,12 +46,12 @@ class ApplicativeSuite extends KittensSuite: } locally { - import semiApplicative.given + import semiInstances.given validate("semiauto.applicative") } locally { - import derivedApplicative.* + import derivedInstances.* val instance = "derived.applicative" checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) @@ -69,7 +68,7 @@ object ApplicativeSuite: type AndInt[A] = (A, Int) type ListBox[A] = List[Box[A]] - object semiApplicative: + object semiInstances: given Applicative[Box] = semiauto.applicative given Applicative[CaseClassWOption] = semiauto.applicative given Applicative[OptList] = semiauto.applicative @@ -77,7 +76,7 @@ object ApplicativeSuite: given Applicative[Interleaved] = semiauto.applicative given Applicative[ListBox] = semiauto.applicative - object derivedApplicative: + object derivedInstances: case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Applicative case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Applicative case class AndInt[A](x: ApplicativeSuite.AndInt[A]) derives Applicative diff --git a/core/src/test/scala-3/cats/derived/ApplySuite.scala b/core/src/test/scala-3/cats/derived/ApplySuite.scala index c875c09a..8193ccb5 100644 --- a/core/src/test/scala-3/cats/derived/ApplySuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplySuite.scala @@ -17,7 +17,7 @@ package cats.derived import cats.Apply -import cats.laws.discipline.{ApplyTests, SerializableTests} +import cats.laws.discipline.* import cats.laws.discipline.SemigroupalTests.Isomorphisms import scala.compiletime.* @@ -45,12 +45,12 @@ class ApplySuite extends KittensSuite: } locally { - import semiApply.given + import semiInstances.given validate("semiauto.apply") } locally { - import derivedApply.* + import derivedInstances.* val instance = "derived.apply" checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].apply[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].apply[Int, String, Long]) @@ -67,7 +67,7 @@ object ApplySuite: type AndInt[A] = (A, Int) type ListBox[A] = List[Box[A]] - object semiApply: + object semiInstances: given Apply[Box] = semiauto.apply given Apply[CaseClassWOption] = semiauto.apply given Apply[OptList] = semiauto.apply @@ -75,7 +75,7 @@ object ApplySuite: given Apply[Interleaved] = semiauto.apply given Apply[ListBox] = semiauto.apply - object derivedApply: + object derivedInstances: case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Apply case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Apply case class AndInt[A](x: ApplySuite.AndInt[A]) derives Apply diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index 1808e899..a91571e2 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -18,7 +18,6 @@ package cats.derived import cats.kernel.{CommutativeMonoid, CommutativeSemigroup} import cats.kernel.laws.discipline.{CommutativeMonoidTests, SerializableTests} - import scala.compiletime.* class CommutativeMonoidSuite extends KittensSuite: @@ -48,12 +47,12 @@ class CommutativeMonoidSuite extends KittensSuite: } locally { - import semiCommutativeMonoid.given + import semiInstances.given validate("semiauto.commutativeMonoid") } locally { - import derivedCommutativeMonoid.* + import derivedInstances.* val instance = "derived.commutativeMonoid" checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeMonoid) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeMonoid) @@ -75,12 +74,12 @@ object CommutativeMonoidSuite: type BoxMul = Box[Mul] - object semiCommutativeMonoid: + object semiInstances: given CommutativeMonoid[CommutativeFoo] = semiauto.commutativeMonoid given CommutativeMonoid[Recursive] = semiauto.commutativeMonoid given CommutativeMonoid[Box[Mul]] = semiauto.commutativeMonoid - object derivedCommutativeMonoid: + object derivedInstances: case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeMonoid case class BoxMul(x: CommutativeMonoidSuite.BoxMul) derives CommutativeMonoid diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index 8916569f..4e1e7165 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -18,7 +18,6 @@ package cats.derived import cats.kernel.CommutativeSemigroup import cats.kernel.laws.discipline.{CommutativeSemigroupTests, SerializableTests} - import scala.compiletime.* class CommutativeSemigroupSuite extends KittensSuite: @@ -47,12 +46,12 @@ class CommutativeSemigroupSuite extends KittensSuite: } locally { - import semiCommutativeSemigroup.given + import semiInstances.given validate("semiauto.commutativeSemigroup") } locally { - import derivedCommutativeSemigroup.* + import derivedInstances.* val instance = "derived.commutativeSemigroup" checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeSemigroup) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeSemigroup) @@ -73,12 +72,12 @@ object CommutativeSemigroupSuite: type BoxMul = Box[Mul] - object semiCommutativeSemigroup: + object semiInstances: given CommutativeSemigroup[CommutativeFoo] = semiauto.commutativeSemigroup given CommutativeSemigroup[Recursive] = semiauto.commutativeSemigroup given CommutativeSemigroup[BoxMul] = semiauto.commutativeSemigroup - object derivedCommutativeSemigroup: + object derivedInstances: case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeSemigroup case class BoxMul(x: CommutativeSemigroupSuite.BoxMul) derives CommutativeSemigroup diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index 7737ca50..f6d211a5 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -14,9 +14,9 @@ * limitations under the License. */ -package cats -package derived +package cats.derived +import cats.Contravariant import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* import cats.laws.discipline.eq.* @@ -47,12 +47,12 @@ class ContravariantSuite extends KittensSuite: } locally { - import semiContravariant.given + import semiInstances.given validate("semiauto.contravariant") } locally { - import derivedContravariant.* + import derivedInstances.* val instance = "derived.contravariant" checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[Single]", tests[Single].contravariant[MiniInt, String, Boolean]) @@ -72,7 +72,7 @@ object ContravariantSuite: type AndCharPred[A] = (A => Boolean, Char) type TreePred[A] = Tree[A => Boolean] - object semiContravariant: + object semiInstances: given Contravariant[OptPred] = semiauto.contravariant given Contravariant[TreePred] = semiauto.contravariant given Contravariant[ListPred] = semiauto.contravariant @@ -83,7 +83,7 @@ object ContravariantSuite: given Contravariant[ListSnocF] = semiauto.contravariant given Contravariant[EnumK1Contra] = semiauto.contravariant - object derivedContravariant: + object derivedInstances: case class EnumK1Contra[-A](x: TestDefns.EnumK1Contra[A]) derives Contravariant case class Single[-A](value: A => Unit) derives Contravariant diff --git a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala index 43fb1ae5..236de348 100644 --- a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala @@ -20,7 +20,6 @@ import alleycats.{EmptyK, Pure} import alleycats.std.all.* import cats.data.NonEmptyList import cats.laws.discipline.SerializableTests - import scala.compiletime.summonInline class EmptyKSuite extends KittensSuite: @@ -49,7 +48,7 @@ class EmptyKSuite extends KittensSuite: } locally { - import semiEmptyK.given + import semiInstances.given validate("semiauto.emptyK") } @@ -71,7 +70,7 @@ object EmptyKSuite: type NelOption[A] = NonEmptyList[Option[A]] type BoxColor[A] = Box[Color[A]] - object semiEmptyK: + object semiInstances: given EmptyK[LOption] = semiauto.emptyK given EmptyK[PList] = semiauto.emptyK given EmptyK[CaseClassWOption] = semiauto.emptyK diff --git a/core/src/test/scala-3/cats/derived/EmptySuite.scala b/core/src/test/scala-3/cats/derived/EmptySuite.scala index 931c396f..8470e19f 100644 --- a/core/src/test/scala-3/cats/derived/EmptySuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptySuite.scala @@ -18,7 +18,6 @@ package cats.derived import alleycats.Empty import cats.laws.discipline.SerializableTests - import scala.compiletime.* class EmptySuite extends KittensSuite: @@ -48,7 +47,7 @@ class EmptySuite extends KittensSuite: } locally { - import semiEmpty.given + import semiInstances.given validate("semiauto.empty") testNoSemi("Empty", "IList[Int]") testNoSemi("Empty", "Snoc[Int]") @@ -56,7 +55,7 @@ class EmptySuite extends KittensSuite: } locally { - import derivedEmpty.* + import derivedInstances.* val instance = "derived.empty" test(s"$instance[Foo]")(assert(empty[Foo].x == TestDefns.Foo(0, None))) test(s"$instance[Outer]")(assert(empty[Outer].x == TestDefns.Outer(Inner(0)))) @@ -76,7 +75,7 @@ object EmptySuite: // `Monoid[Option[A]]` gives us `Empty[Option[A]]` but it requires a `Semigroup[A]`. given [A]: Empty[Option[A]] = Empty(None) - object semiEmpty: + object semiInstances: given Empty[Foo] = semiauto.empty given Empty[Outer] = semiauto.empty given Empty[Interleaved[String]] = semiauto.empty @@ -86,7 +85,7 @@ object EmptySuite: given Empty[Box[Mask]] = semiauto.empty given Empty[Chain] = semiauto.empty - object derivedEmpty: + object derivedInstances: case class Foo(x: TestDefns.Foo) derives Empty case class Outer(x: TestDefns.Outer) derives Empty case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Empty diff --git a/core/src/test/scala-3/cats/derived/EqSuite.scala b/core/src/test/scala-3/cats/derived/EqSuite.scala index bf83a8a5..0f66d2a5 100644 --- a/core/src/test/scala-3/cats/derived/EqSuite.scala +++ b/core/src/test/scala-3/cats/derived/EqSuite.scala @@ -17,8 +17,7 @@ package cats.derived import cats.Eq -import cats.kernel.laws.discipline.{EqTests, SerializableTests} - +import cats.kernel.laws.discipline.* import scala.compiletime.* class EqSuite extends KittensSuite.WithoutEq: @@ -44,12 +43,12 @@ class EqSuite extends KittensSuite.WithoutEq: } locally { - import semiEq.given + import semiInstances.given validate("semiauto.eq") } locally { - import derivedEq.* + import derivedInstances.* val instance = "derived.eq" checkAll(s"$instance[Foo]]", tests[Foo].eqv) checkAll(s"$instance[IList[Int]]", tests[IList[Int]].eqv) @@ -66,7 +65,7 @@ end EqSuite object EqSuite: import TestDefns.* - object semiEq: + object semiInstances: given Eq[Foo] = semiauto.eq given Eq[IList[Int]] = semiauto.eq given Eq[Inner] = semiauto.eq @@ -75,7 +74,7 @@ object EqSuite: given Eq[Tree[Int]] = semiauto.eq given Eq[Recursive] = semiauto.eq - object derivedEq: + object derivedInstances: case class Foo(x: TestDefns.Foo) derives Eq case class IList[A](x: TestDefns.IList[A]) derives Eq case class Inner(x: TestDefns.Inner) derives Eq diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 097d9c72..504f4ed9 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -17,7 +17,7 @@ package cats.derived import cats.{Eval, Foldable} -import cats.laws.discipline.{FoldableTests, SerializableTests} +import cats.laws.discipline.* import cats.syntax.all.* import scala.compiletime.* @@ -49,12 +49,12 @@ class FoldableSuite extends KittensSuite: } locally { - import semiFoldable.given + import semiInstances.given validate("semiauto.foldable") } locally { - import derivedFoldable.* + import derivedInstances.* val instance = "derived.foldable" checkAll(s"$instance[IList]", tests[IList].foldable[Int, Long]) checkAll(s"$instance[Tree]", tests[Tree].foldable[Int, Long]) @@ -78,7 +78,7 @@ object FoldableSuite: type AndChar[A] = (A, Char) type BoxNel[A] = Box[Nel[A]] - object semiFoldable: + object semiInstances: given Foldable[IList] = semiauto.foldable given Foldable[Tree] = semiauto.foldable given Foldable[GenericAdt] = semiauto.foldable @@ -92,7 +92,7 @@ object FoldableSuite: given Foldable[AtMostOne] = semiauto.foldable given Foldable[AtLeastOne] = semiauto.foldable - object derivedFoldable: + object derivedInstances: case class IList[A](x: TestDefns.IList[A]) derives Foldable case class Tree[A](x: TestDefns.Tree[A]) derives Foldable case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Foldable diff --git a/core/src/test/scala-3/cats/derived/FunctorSuite.scala b/core/src/test/scala-3/cats/derived/FunctorSuite.scala index 51feeb0c..6fdf1b03 100644 --- a/core/src/test/scala-3/cats/derived/FunctorSuite.scala +++ b/core/src/test/scala-3/cats/derived/FunctorSuite.scala @@ -14,9 +14,9 @@ * limitations under the License. */ -package cats -package derived +package cats.derived +import cats.Functor import cats.laws.discipline.* import cats.laws.discipline.eq.* import scala.compiletime.* @@ -52,12 +52,12 @@ class FunctorSuite extends KittensSuite: } locally { - import semiFunctor.given + import semiInstances.given validate("semiauto.functor") } locally { - import derivedFunctor.* + import derivedInstances.* val instance = "derived.functor" checkAll(s"$instance[IList]", tests[IList].functor[Int, String, Long]) checkAll(s"$instance[Tree]", tests[Tree].functor[Int, String, Long]) @@ -82,7 +82,7 @@ object FunctorSuite: type Predicate[A] = A => Boolean type NestedPred[A] = Predicate[Predicate[A]] - object semiFunctor: + object semiInstances: given Functor[IList] = semiauto.functor given Functor[Tree] = semiauto.functor given Functor[GenericAdt] = semiauto.functor @@ -96,7 +96,7 @@ object FunctorSuite: given Functor[AtMostOne] = semiauto.functor given Functor[AtLeastOne] = semiauto.functor - object derivedFunctor: + object derivedInstances: case class IList[A](x: TestDefns.IList[A]) derives Functor case class Tree[A](x: TestDefns.Tree[A]) derives Functor case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Functor diff --git a/core/src/test/scala-3/cats/derived/HashSuite.scala b/core/src/test/scala-3/cats/derived/HashSuite.scala index 41abb392..2a4ee162 100644 --- a/core/src/test/scala-3/cats/derived/HashSuite.scala +++ b/core/src/test/scala-3/cats/derived/HashSuite.scala @@ -1,8 +1,7 @@ package cats.derived import cats.Hash -import cats.kernel.laws.discipline.{HashTests, SerializableTests} - +import cats.kernel.laws.discipline.* import scala.compiletime.* import scala.util.hashing.MurmurHash3 @@ -30,12 +29,12 @@ class HashSuite extends KittensSuite: } locally { - import semiHash.given + import semiInstances.given validate("semiauto.hash") } locally { - import derivedHash.* + import derivedInstances.* val instance = "derived.hash" checkAll(s"$instance[IList[Int]]", tests[IList[Int]].hash) checkAll(s"$instance[Inner]", tests[Inner].hash) @@ -53,7 +52,7 @@ end HashSuite object HashSuite: import TestDefns.* - object semiHash: + object semiInstances: given Hash[IList[Int]] = semiauto.hash given Hash[Inner] = semiauto.hash given Hash[Outer] = semiauto.hash @@ -62,7 +61,7 @@ object HashSuite: given Hash[Recursive] = semiauto.hash given Hash[EnumK0] = semiauto.hash - object derivedHash: + object derivedInstances: case class IList[A](x: TestDefns.IList[A]) derives Hash case class Inner(x: TestDefns.Inner) derives Hash case class Outer(x: TestDefns.Outer) derives Hash diff --git a/core/src/test/scala-3/cats/derived/InvariantSuite.scala b/core/src/test/scala-3/cats/derived/InvariantSuite.scala index b95f09b8..44755250 100644 --- a/core/src/test/scala-3/cats/derived/InvariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/InvariantSuite.scala @@ -14,14 +14,12 @@ * limitations under the License. */ -package cats -package derived +package cats.derived +import cats.Invariant import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* import cats.laws.discipline.eq.* -import cats.laws.discipline.* - import scala.compiletime.* class InvariantSuite extends KittensSuite: @@ -52,12 +50,12 @@ class InvariantSuite extends KittensSuite: } locally { - import semiInvariant.given + import semiInstances.given validate("semiauto.invariant") } locally { - import derivedInvariant.* + import derivedInstances.* val instance = "derived.invariant" checkAll(s"$instance[IList]", tests[IList].invariant[MiniInt, String, Boolean]) checkAll(s"$instance[Bivariant]", tests[Bivariant].invariant[MiniInt, String, Boolean]) @@ -79,7 +77,7 @@ object InvariantSuite: type AndCharF[A] = (A => Boolean, Char) type TreeF[A] = Tree[A => Boolean] - object semiInvariant: + object semiInstances: given Invariant[GenericAdtF] = semiauto.invariant given Invariant[ListFToInt] = semiauto.invariant // TODO: https://github.com/typelevel/kittens/issues/473 @@ -95,7 +93,7 @@ object InvariantSuite: given Invariant[AtMostOne] = semiauto.invariant given Invariant[AtLeastOne] = semiauto.invariant - object derivedInvariant: + object derivedInstances: case class Bivariant[A](x: TestDefns.Bivariant[A]) derives Invariant case class IList[A](x: TestDefns.IList[A]) derives Invariant case class EnumK1Inv[A](x: TestDefns.EnumK1Inv[A]) derives Invariant diff --git a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala index 8e6db5ca..f4c751d8 100644 --- a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala @@ -28,12 +28,12 @@ class MonoidKSuite extends KittensSuite: } locally { - import semiMonoidK.given + import semiInstances.given validate("semiauto.monoidK") } locally { - import derivedMonoidK.* + import derivedInstances.* val instance = "derived.monoidK" checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].monoidK[Char]) checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].monoidK[Char]) @@ -48,12 +48,12 @@ object MonoidKSuite: type BoxMul[A] = Box[Mul[A]] - object semiMonoidK: + object semiInstances: given MonoidK[ComplexProduct] = semiauto.monoidK given MonoidK[CaseClassWOption] = semiauto.monoidK given MonoidK[BoxMul] = semiauto.monoidK - object derivedMonoidK: + object derivedInstances: case class ComplexProduct[A](x: TestDefns.ComplexProduct[A]) derives MonoidK case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives MonoidK case class Simple[A](value1: List[A], value2: Set[A]) derives MonoidK diff --git a/core/src/test/scala-3/cats/derived/MonoidSuite.scala b/core/src/test/scala-3/cats/derived/MonoidSuite.scala index 5cd3db77..38a06c8a 100644 --- a/core/src/test/scala-3/cats/derived/MonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidSuite.scala @@ -18,7 +18,6 @@ package cats.derived import cats.Monoid import cats.kernel.laws.discipline.{MonoidTests, SerializableTests} - import scala.compiletime.* class MonoidSuite extends KittensSuite: @@ -46,12 +45,12 @@ class MonoidSuite extends KittensSuite: } locally { - import semiMonoid.given + import semiInstances.given validate("semiauto.monoid") } locally { - import derivedMonoid.* + import derivedInstances.* val instance = "derived.monoid" checkAll(s"$instance[Foo]", tests[Foo].monoid) checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].monoid) @@ -69,13 +68,13 @@ end MonoidSuite object MonoidSuite: import TestDefns.* - object semiMonoid: + object semiInstances: given Monoid[Foo] = semiauto.monoid given Monoid[Recursive] = semiauto.monoid given Monoid[Interleaved[Int]] = semiauto.monoid given Monoid[Box[Mul]] = semiauto.monoid - object derivedMonoid: + object derivedInstances: case class Foo(x: TestDefns.Foo) derives Monoid case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Monoid case class BoxMul(x: Box[Mul]) derives Monoid diff --git a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala index 6aef1d2b..2a1df181 100644 --- a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala @@ -18,11 +18,9 @@ package cats.derived import cats.{Eq, NonEmptyTraverse} import cats.data.{NonEmptyList, NonEmptyVector, OneAnd} +import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* -import cats.laws.discipline.{NonEmptyTraverseTests, SerializableTests} import cats.syntax.all.* -import org.scalacheck.Arbitrary - import scala.compiletime.* class NonEmptyTraverseSuite extends KittensSuite: @@ -76,12 +74,12 @@ class NonEmptyTraverseSuite extends KittensSuite: } locally { - import semiNonEmptyTraverse.given + import semiInstances.given validate("semiauto.nonEmptyTraverse") } locally { - import derivedNonEmptyTraverse.* + import derivedInstances.* val instance = "derived.nonEmptyTraverse" checkAll( s"$instance[ICons]", @@ -118,7 +116,7 @@ object NonEmptyTraverseSuite: type NelAndOne[A] = NonEmptyList[OneAnd[Vector, A]] type VecAndNel[A] = (Vector[A], NonEmptyList[A]) - object semiNonEmptyTraverse: + object semiInstances: given NonEmptyTraverse[ICons] = semiauto.nonEmptyTraverse given NonEmptyTraverse[Tree] = semiauto.nonEmptyTraverse given NonEmptyTraverse[NelSCons] = semiauto.nonEmptyTraverse @@ -128,7 +126,7 @@ object NonEmptyTraverseSuite: given NonEmptyTraverse[EnumK1] = semiauto.nonEmptyTraverse given NonEmptyTraverse[AtLeastOne] = semiauto.nonEmptyTraverse - object derivedNonEmptyTraverse: + object derivedInstances: case class ICons[A](x: TestDefns.ICons[A]) derives NonEmptyTraverse case class Tree[A](x: TestDefns.Tree[A]) derives NonEmptyTraverse case class Interleaved[A](x: TestDefns.Interleaved[A]) derives NonEmptyTraverse diff --git a/core/src/test/scala-3/cats/derived/OrderSuite.scala b/core/src/test/scala-3/cats/derived/OrderSuite.scala index bb5c5144..4dbe7ed3 100644 --- a/core/src/test/scala-3/cats/derived/OrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/OrderSuite.scala @@ -17,9 +17,8 @@ package cats.derived import cats.Order -import cats.kernel.laws.discipline.{OrderTests, SerializableTests} -import org.scalacheck.Arbitrary -import scala.compiletime.summonInline +import cats.kernel.laws.discipline.* +import scala.compiletime.* class OrderSuite extends KittensSuite: import OrderSuite.* @@ -43,12 +42,12 @@ class OrderSuite extends KittensSuite: } locally { - import semiOrder.given + import semiInstances.given validate("semiauto.order") } locally { - import derivedOrder.* + import derivedInstances.* val instance = "derived.order" checkAll(s"$instance[Inner]", tests[Inner].order) checkAll(s"$instance[Outer]", tests[Outer].order) @@ -64,7 +63,7 @@ end OrderSuite object OrderSuite: import TestDefns.* - object semiOrder: + object semiInstances: given Order[Inner] = semiauto.order given Order[Outer] = semiauto.order given Order[Interleaved[Int]] = semiauto.order @@ -72,7 +71,7 @@ object OrderSuite: given Order[GenericAdt[Int]] = semiauto.order given Order[EnumK0] = semiauto.order - object derivedOrder: + object derivedInstances: case class Inner(x: TestDefns.Inner) derives Order case class Outer(x: TestDefns.Outer) derives Order case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Order diff --git a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala index c19d582d..5e08d526 100644 --- a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala @@ -14,10 +14,10 @@ * limitations under the License. */ -package cats -package derived +package cats.derived -import cats.kernel.laws.discipline.{PartialOrderTests, SerializableTests} +import cats.PartialOrder +import cats.kernel.laws.discipline.* import scala.compiletime.* class PartialOrderSuite extends KittensSuite: @@ -52,12 +52,12 @@ class PartialOrderSuite extends KittensSuite: } locally { - import semiPartialOrder.given + import semiInstances.given validate("semiauto.partialOrder") } locally { - import derivedPartialOrder.* + import derivedInstances.* val instance = "derived.partialOrder" checkAll(s"$instance[IList[Int]]", tests[IList[Int]].partialOrder) checkAll(s"$instance[Inner]", tests[Inner].partialOrder) @@ -75,7 +75,7 @@ end PartialOrderSuite object PartialOrderSuite: import TestDefns.* - object semiPartialOrder: + object semiInstances: given PartialOrder[IList[Int]] = semiauto.partialOrder given PartialOrder[Inner] = semiauto.partialOrder given PartialOrder[Outer] = semiauto.partialOrder @@ -85,7 +85,7 @@ object PartialOrderSuite: given PartialOrder[Box[KeyValue]] = semiauto.partialOrder given PartialOrder[EnumK0] = semiauto.partialOrder - object derivedPartialOrder: + object derivedInstances: case class IList[A](x: TestDefns.IList[A]) derives PartialOrder case class Interleaved[A](x: TestDefns.Interleaved[A]) derives PartialOrder case class Tree[A](x: TestDefns.Tree[A]) derives PartialOrder diff --git a/core/src/test/scala-3/cats/derived/PureSuite.scala b/core/src/test/scala-3/cats/derived/PureSuite.scala index 5e100b6a..07302c92 100644 --- a/core/src/test/scala-3/cats/derived/PureSuite.scala +++ b/core/src/test/scala-3/cats/derived/PureSuite.scala @@ -19,8 +19,7 @@ package cats.derived import alleycats.Pure import cats.data.NonEmptyList import cats.laws.discipline.SerializableTests - -import scala.compiletime.summonInline +import scala.compiletime.* class PureSuite extends KittensSuite: import PureSuite.* @@ -47,14 +46,14 @@ class PureSuite extends KittensSuite: } locally { - import semiPure.given + import semiInstances.given validate("semiauto.pure") testNoSemi("Pure", "IList") testNoSemi("Pure", "Snoc") } locally { - import derivedPure.* + import derivedInstances.* val instance = "derived.pure" test(s"$instance[CaseClassWOption]")( assert(3.14.pure[CaseClassWOption].x == TestDefns.CaseClassWOption(Some(3.14))) @@ -75,7 +74,7 @@ object PureSuite: type NelOption[A] = NonEmptyList[Option[A]] type BoxColor[A] = Box[Color[A]] - object semiPure: + object semiInstances: given Pure[LOption] = semiauto.pure given Pure[PList] = semiauto.pure given Pure[CaseClassWOption] = semiauto.pure @@ -83,7 +82,7 @@ object PureSuite: given Pure[Interleaved] = semiauto.pure given Pure[BoxColor] = semiauto.pure - object derivedPure: + object derivedInstances: case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Pure case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Pure diff --git a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala index c82b07ef..1df11df4 100644 --- a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala +++ b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala @@ -18,8 +18,8 @@ package cats.derived import cats.{Eval, Reducible} import cats.data.{NonEmptyList, OneAnd} +import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* -import cats.laws.discipline.{ReducibleTests, SerializableTests} import cats.syntax.all.* import scala.compiletime.* @@ -47,12 +47,12 @@ class ReducibleSuite extends KittensSuite: } locally { - import semiReducible.given + import semiInstances.given validate("semiauto.reducible") } locally { - import derivedReducible.* + import derivedInstances.* val instance = "derived.reducible" checkAll(s"$instance[ICons]", tests[ICons].reducible[Option, Int, Long]) checkAll(s"$instance[Tree]", tests[Tree].reducible[Option, Int, Long]) @@ -71,7 +71,7 @@ object ReducibleSuite: type VecAndNel[A] = (Vector[A], NonEmptyList[A]) type BoxZipper[A] = Box[Zipper[A]] - object semiReducible: + object semiInstances: given Reducible[ICons] = semiauto.reducible given Reducible[Tree] = semiauto.reducible given Reducible[NelSCons] = semiauto.reducible @@ -81,7 +81,7 @@ object ReducibleSuite: given Reducible[BoxZipper] = semiauto.reducible given Reducible[EnumK1] = semiauto.reducible - object derivedReducible: + object derivedInstances: case class ICons[A](x: TestDefns.ICons[A]) derives Reducible case class Tree[A](x: TestDefns.Tree[A]) derives Reducible case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Reducible diff --git a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala index 2dd7db73..1e3a28c0 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala @@ -1,38 +1,42 @@ package cats.derived -import cats.* +import cats.SemigroupK import cats.laws.discipline.{SemigroupKTests, SerializableTests} -import org.scalacheck.Arbitrary import scala.compiletime.* class SemigroupKSuite extends KittensSuite: import SemigroupKSuite.* import TestDefns.* - inline def semigroupKTests[F[_]]: SemigroupKTests[F] = + inline def tests[F[_]]: SemigroupKTests[F] = SemigroupKTests[F](summonInline) - inline def testSemigroupK(context: String): Unit = - checkAll(s"$context.SemigroupK[ComplexProduct]", semigroupKTests[ComplexProduct].semigroupK[Char]) - checkAll(s"$context.SemigroupK[CaseClassWOption]", semigroupKTests[CaseClassWOption].semigroupK[Char]) - checkAll(s"$context.SemigroupK[BoxMul]", semigroupKTests[BoxMul].semigroupK[Char]) - checkAll( - s"$context.SemigroupK is Serializable", - SerializableTests.serializable(summonInline[SemigroupK[ComplexProduct]]) - ) - - test(s"$context.SemigroupK respects existing instances") { + inline def validate(instance: String): Unit = + checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].semigroupK[Char]) + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].semigroupK[Char]) + checkAll(s"$instance[BoxMul]", tests[BoxMul].semigroupK[Char]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[SemigroupK[ComplexProduct]])) + test(s"$instance respects existing instances") { assert(summonInline[SemigroupK[BoxMul]].combineK(Box(Mul[Char](5)), Box(Mul[Char](5))) == Box(Mul[Char](25))) } locally { import auto.semigroupK.given - testSemigroupK("auto") + validate("auto.semigroupK") } locally { import semiInstances.given - testSemigroupK("semiauto") + validate("semiauto.semigroupK") + } + + locally { + import derivedInstances.* + val instance = "derived.semigroupK" + checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].semigroupK[Char]) + checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].semigroupK[Char]) + checkAll(s"$instance[Simple]", tests[Simple].semigroupK[Char]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[SemigroupK[ComplexProduct]])) } end SemigroupKSuite @@ -47,17 +51,15 @@ object SemigroupKSuite: given SemigroupK[CaseClassWOption] = semiauto.semigroupK given SemigroupK[BoxMul] = semiauto.semigroupK + object derivedInstances: + case class ComplexProduct[A](x: TestDefns.ComplexProduct[A]) derives SemigroupK + case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives SemigroupK + case class Simple[A](value1: List[A], value2: Set[A]) derives SemigroupK + case class Recursive[A](first: List[A], rest: Recursive[A]) derives SemigroupK + final case class Mul[T](value: Int) object Mul: - given [T]: Eq[Mul[T]] = Eq.by(_.value) - - given [T]: Arbitrary[Mul[T]] = - Arbitrary(Arbitrary.arbitrary[Int].map(apply)) - given SemigroupK[Mul] with def combineK[A](x: Mul[A], y: Mul[A]) = Mul(x.value * y.value) - case class Simple[A](value1: List[A], value2: Set[A]) derives SemigroupK - case class Recursive[A](first: List[A], rest: Recursive[A]) derives SemigroupK - end SemigroupKSuite From 17e9f0f529064a557940c7c8c630429b0f4e08e7 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 11:10:25 +0200 Subject: [PATCH 24/29] Extend SemigroupSuite with derived instances --- .../scala-3/cats/derived/SemigroupSuite.scala | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala index 5190dba8..6a55d5c4 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala @@ -17,7 +17,7 @@ package cats.derived import cats.{Eq, Semigroup} -import cats.kernel.laws.discipline.{SemigroupTests, SerializableTests} +import cats.kernel.laws.discipline.* import org.scalacheck.Arbitrary import scala.compiletime.* @@ -26,28 +26,37 @@ class SemigroupSuite extends KittensSuite: import SemigroupSuite.* import TestDefns.* - inline def semigroupTests[A]: SemigroupTests[A] = + inline def tests[A]: SemigroupTests[A] = SemigroupTests[A](summonInline) - inline def testSemigroup(inline context: String): Unit = - checkAll(s"$context.Semigroup[Foo]", semigroupTests[Foo].semigroup) - checkAll(s"$context.Semigroup[Interleaved[Int]]", semigroupTests[Interleaved[Int]].semigroup) - checkAll(s"$context.Semigroup[Box[Mul]]", semigroupTests[Box[Mul]].semigroup) - checkAll(s"$context.Semigroup[Recursive]", semigroupTests[Recursive].semigroup) - checkAll(s"$context.Semigroup is Serializable", SerializableTests.serializable(summonInline[Semigroup[Foo]])) - test(s"$context.Semigroup respects existing instances") { + inline def validate(inline instances: String): Unit = + checkAll(s"$instances[Foo]", tests[Foo].semigroup) + checkAll(s"$instances[Interleaved[Int]]", tests[Interleaved[Int]].semigroup) + checkAll(s"$instances[Box[Mul]]", tests[Box[Mul]].semigroup) + checkAll(s"$instances[Recursive]", tests[Recursive].semigroup) + checkAll(s"$instances is Serializable", SerializableTests.serializable(summonInline[Semigroup[Foo]])) + test(s"$instances respects existing instances") { val box = summonInline[Semigroup[Box[Mul]]] assert(box.combine(Box(Mul(5)), Box(Mul(5))).content.value == 25) } locally { import auto.semigroup.given - testSemigroup("auto") + validate("auto.semigroup") } locally { import semiInstances.given - testSemigroup("semiauto") + validate("semiauto.semigroup") + } + + locally { + import derivedInstances.* + val instances = "derived.semigroup" + checkAll(s"$instances[Foo]", tests[Foo].semigroup) + checkAll(s"$instances[Interleaved[Int]]", tests[Interleaved[Int]].semigroup) + checkAll(s"$instances[BoxMul]", tests[BoxMul].semigroup) + checkAll(s"$instances is Serializable", SerializableTests.serializable(summonInline[Semigroup[Foo]])) } end SemigroupSuite @@ -61,10 +70,13 @@ object SemigroupSuite: given Semigroup[Interleaved[Int]] = semiauto.semigroup given Semigroup[Box[Mul]] = semiauto.semigroup + object derivedInstances: + case class Foo(x: TestDefns.Foo) derives Semigroup + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Semigroup + case class BoxMul(x: Box[Mul]) derives Semigroup + final case class Mul(value: Int) object Mul: - given Eq[Mul] = Eq.fromUniversalEquals - given Arbitrary[Mul] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) given Semigroup[Mul] = (x, y) => Mul(x.value * y.value) end SemigroupSuite From 1b0e8c75ac803d8c18ceea6ab9be2fe6cf5837b0 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 11:15:08 +0200 Subject: [PATCH 25/29] Extend ShowPrettySuite with derived instances --- .../cats/derived/ShowPrettySuite.scala | 71 +++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala index 8d51de3a..7c87f5a2 100644 --- a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala +++ b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala @@ -1,6 +1,6 @@ -package cats -package derived +package cats.derived +import cats.Show import cats.laws.discipline.SerializableTests import scala.compiletime.* @@ -9,13 +9,13 @@ class ShowPrettySuite extends KittensSuite: import ShowPrettySuite.given import TestDefns.* - inline def showPretty[A](value: A): String = + inline def show[A](value: A): String = summonInline[ShowPretty[A]].show(value) - inline def testShowPretty(context: String): Unit = { - checkAll(s"$context.ShowPretty is Serializable", SerializableTests.serializable(summonInline[ShowPretty[IntTree]])) + inline def validate(instance: String): Unit = { + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[ShowPretty[IntTree]])) - test(s"$context.ShowPretty[Foo]") { + test(s"$instance[Foo]") { val value = Foo(42, Option("Hello")) val pretty = """ |Foo( @@ -24,10 +24,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[Outer]") { + test(s"$instance[Outer]") { val value = Outer(Inner(3)) val pretty = """ |Outer( @@ -37,10 +37,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[IntTree]") { + test(s"$instance[IntTree]") { val value: IntTree = IntNode(IntLeaf(1), IntNode(IntNode(IntLeaf(2), IntLeaf(3)), IntLeaf(4))) val pretty = """ |IntNode( @@ -63,10 +63,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[GenericAdt[Int]]") { + test(s"$instance[GenericAdt[Int]]") { val value: GenericAdt[Int] = GenericAdtCase(Some(1)) val pretty = """ |GenericAdtCase( @@ -74,10 +74,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[People]") { + test(s"$instance[People]") { val value = People("Kai", ContactInfo("303-123-4567", Address("123 1st St", "New York", "NY"))) val pretty = """ |People( @@ -89,10 +89,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[ListField]") { + test(s"$instance[ListField]") { val value = ListField("a", List(ListFieldChild(1))) val pretty = """ |ListField( @@ -103,10 +103,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[Interleaved[Int]]") { + test(s"$instance[Interleaved[Int]]") { val value = Interleaved(1, 2, 3, Vector(4, 5, 6), "789") val pretty = """ |Interleaved( @@ -118,10 +118,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty[Tree[Int]]") { + test(s"$instance[Tree[Int]]") { val value: Tree[Int] = Node(Leaf(1), Node(Node(Leaf(2), Leaf(3)), Leaf(4))) val pretty = """ |Node( @@ -144,10 +144,10 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } - test(s"$context.ShowPretty respects existing instances") { + test(s"$instance respects existing instances") { val value = Box(Bogus(42)) val pretty = """ |Box( @@ -155,26 +155,27 @@ class ShowPrettySuite extends KittensSuite: |) """.stripMargin.trim - assertEquals(showPretty(value), pretty) + assertEquals(show(value), pretty) } } locally { import auto.showPretty.given - testShowPretty("auto") + validate("auto.showPretty") } locally { import semiInstances.given - testShowPretty("semiauto") + validate("semiauto.showPretty") } +end ShowPrettySuite + object ShowPrettySuite: import TestDefns.* - given Show[Address] = Show.show { a => - List(a.street, a.city, a.state).mkString(" ") - } + given Show[Address] = + Show.show(a => List(a.street, a.city, a.state).mkString(" ")) final case class Bogus(value: Int) object Bogus: @@ -191,3 +192,17 @@ object ShowPrettySuite: given ShowPretty[Interleaved[Int]] = semiauto.showPretty given ShowPretty[Tree[Int]] = semiauto.showPretty given ShowPretty[Box[Bogus]] = semiauto.showPretty + + object derivedInstances: + case class Foo(x: TestDefns.Foo) derives ShowPretty + case class Outer(x: TestDefns.Outer) derives ShowPretty + case class IntTree(x: TestDefns.IntTree) derives ShowPretty + case class People(x: TestDefns.People) derives ShowPretty + case class ListFieldChild(x: TestDefns.ListFieldChild) derives ShowPretty + case class ListField(x: TestDefns.ListField) derives ShowPretty + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives ShowPretty + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives ShowPretty + case class Tree[A](x: TestDefns.Tree[A]) derives ShowPretty + case class BoxBogus(x: Box[Bogus]) derives ShowPretty + +end ShowPrettySuite From 321def5fa48280842c37092a715c2112cb526e37 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 11:19:21 +0200 Subject: [PATCH 26/29] Extend ShowSuite with derived instances --- .../cats/derived/ShowPrettySuite.scala | 5 +- .../test/scala-3/cats/derived/ShowSuite.scala | 52 ++++++++++++------- .../test/scala-3/cats/derived/ShowTests.scala | 9 ---- 3 files changed, 35 insertions(+), 31 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/ShowTests.scala diff --git a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala index 7c87f5a2..5ab2c556 100644 --- a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala +++ b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala @@ -12,7 +12,7 @@ class ShowPrettySuite extends KittensSuite: inline def show[A](value: A): String = summonInline[ShowPretty[A]].show(value) - inline def validate(instance: String): Unit = { + inline def validate(instance: String): Unit = checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[ShowPretty[IntTree]])) test(s"$instance[Foo]") { @@ -157,7 +157,8 @@ class ShowPrettySuite extends KittensSuite: assertEquals(show(value), pretty) } - } + + end validate locally { import auto.showPretty.given diff --git a/core/src/test/scala-3/cats/derived/ShowSuite.scala b/core/src/test/scala-3/cats/derived/ShowSuite.scala index 10ba0d53..4fc36c10 100644 --- a/core/src/test/scala-3/cats/derived/ShowSuite.scala +++ b/core/src/test/scala-3/cats/derived/ShowSuite.scala @@ -1,6 +1,6 @@ -package cats -package derived +package cats.derived +import cats.Show import cats.laws.discipline.SerializableTests import scala.compiletime.* @@ -12,83 +12,83 @@ class ShowSuite extends KittensSuite: inline def show[A](value: A): String = summonInline[Show[A]].show(value) - inline def testShow(context: String): Unit = - checkAll(s"$context.Show is Serializable", SerializableTests.serializable(summonInline[Show[Foo]])) + inline def validate(instance: String): Unit = + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Show[Foo]])) - test(s"$context.Show[Foo]") { + test(s"$instance[Foo]") { val value = Foo(42, Option("Hello")) val shown = "Foo(i = 42, b = Some(Hello))" assertEquals(show(value), shown) } - test(s"$context.Show[Outer]") { + test(s"$instance[Outer]") { val value = Outer(Inner(3)) val shown = "Outer(in = Inner(i = 3))" assertEquals(show(value), shown) } - test(s"$context.Show[IntTree]") { + test(s"$instance[IntTree]") { val value: IntTree = IntNode(IntLeaf(1), IntNode(IntNode(IntLeaf(2), IntLeaf(3)), IntLeaf(4))) val shown = "IntNode(l = IntLeaf(t = 1), r = IntNode(l = IntNode(l = IntLeaf(t = 2), r = IntLeaf(t = 3)), r = IntLeaf(t = 4)))" assertEquals(show(value), shown) } - test(s"$context.Show[GenericAdt[Int]]") { + test(s"$instance[GenericAdt[Int]]") { val value: GenericAdt[Int] = GenericAdtCase(Some(1)) val shown = "GenericAdtCase(value = Some(1))" assertEquals(show(value), shown) } - test(s"$context.Show[People]") { + test(s"$instance[People]") { val value = People("Kai", ContactInfo("303-123-4567", Address("123 1st St", "New York", "NY"))) val shown = "People(name = Kai, contactInfo = ContactInfo(phoneNumber = 303-123-4567, address = 123 1st St New York NY))" assertEquals(show(value), shown) } - test(s"$context.Show[ListField]") { + test(s"$instance[ListField]") { val value = ListField("a", List(ListFieldChild(1))) val shown = "ListField(a = a, b = List(ListFieldChild(c = 1)))" assertEquals(show(value), shown) } - test(s"$context.Show[Interleaved[Int]]") { + test(s"$instance[Interleaved[Int]]") { val value = Interleaved(1, 2, 3, Vector(4, 5, 6), "789") val shown = "Interleaved(i = 1, t = 2, l = 3, tt = Vector(4, 5, 6), s = 789)" assertEquals(show(value), shown) } - test(s"$context.Show[Tree[Int]]") { + test(s"$instance[Tree[Int]]") { val value: Tree[Int] = Node(Leaf(1), Node(Node(Leaf(2), Leaf(3)), Leaf(4))) val shown = "Node(left = Leaf(value = 1), right = Node(left = Node(left = Leaf(value = 2), right = Leaf(value = 3)), right = Leaf(value = 4)))" assertEquals(show(value), shown) } - test(s"$context.Show[EnumK0]") { + test(s"$instance[EnumK0]") { val value: EnumK0 = EnumK0.LeafI(3) val shown = "LeafI(value = 3)" assertEquals(show(value), shown) } - test(s"$context.Show respects existing instances") { + test(s"$instance respects existing instances") { val value = Box(Bogus(42)) val shown = "Box(content = Blah)" assertEquals(show(value), shown) } - end testShow + end validate locally { import auto.show.given - testShow("auto") + validate("auto.show") } locally { import semiInstances.given - testShow("semiauto") + validate("semiauto.show") } end ShowSuite @@ -96,9 +96,8 @@ end ShowSuite object ShowSuite: import TestDefns.* - given Show[Address] = Show.show { a => - List(a.street, a.city, a.state).mkString(" ") - } + given Show[Address] = + Show.show(a => List(a.street, a.city, a.state).mkString(" ")) final case class Bogus(value: Int) object Bogus: @@ -117,4 +116,17 @@ object ShowSuite: given Show[Box[Bogus]] = semiauto.show given Show[EnumK0] = semiauto.show + object derivedInstances: + case class Foo(x: TestDefns.Foo) derives Show + case class Outer(x: TestDefns.Outer) derives Show + case class IntTree(x: TestDefns.IntTree) derives Show + case class People(x: TestDefns.People) derives Show + case class ListFieldChild(x: TestDefns.ListFieldChild) derives Show + case class ListField(x: TestDefns.ListField) derives Show + case class EnumK0(x: TestDefns.EnumK0) derives Show + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Show + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Show + case class Tree[A](x: TestDefns.Tree[A]) derives Show + case class BoxBogus(x: Box[Bogus]) derives Show + end ShowSuite diff --git a/core/src/test/scala-3/cats/derived/ShowTests.scala b/core/src/test/scala-3/cats/derived/ShowTests.scala deleted file mode 100644 index 1328404c..00000000 --- a/core/src/test/scala-3/cats/derived/ShowTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cats.derived - -import alleycats.* -import cats.* -import cats.derived.* - -class ShowTests { // - case class Foo(i: Int, b: Option[String]) derives Show -} From ac34f8937b475eea2a9c07d49ac9fe225570289b Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 11:34:00 +0200 Subject: [PATCH 27/29] Extend TraverseSuite with derived instances --- .../cats/derived/ApplicativeSuite.scala | 2 +- .../scala-3/cats/derived/ApplySuite.scala | 2 +- .../cats/derived/CommutativeMonoidSuite.scala | 12 +--- .../derived/CommutativeSemigroupSuite.scala | 11 +-- .../cats/derived/ContravariantSuite.scala | 2 +- .../scala-3/cats/derived/EmptyKSuite.scala | 1 + .../scala-3/cats/derived/EmptySuite.scala | 2 +- .../test/scala-3/cats/derived/EqSuite.scala | 2 +- .../scala-3/cats/derived/FoldableSuite.scala | 2 +- .../scala-3/cats/derived/FunctorSuite.scala | 2 +- .../test/scala-3/cats/derived/HashSuite.scala | 2 +- .../scala-3/cats/derived/InvariantSuite.scala | 1 + .../scala-3/cats/derived/MonoidKSuite.scala | 2 +- .../scala-3/cats/derived/MonoidSuite.scala | 7 +- .../cats/derived/NonEmptyTraverseSuite.scala | 5 +- .../scala-3/cats/derived/OrderSuite.scala | 2 +- .../cats/derived/PartialOrderSuite.scala | 2 +- .../test/scala-3/cats/derived/PureSuite.scala | 2 +- .../scala-3/cats/derived/ReducibleSuite.scala | 6 +- .../cats/derived/SemigroupKSuite.scala | 2 +- .../scala-3/cats/derived/SemigroupSuite.scala | 2 +- .../scala-3/cats/derived/TraverseSuite.scala | 72 +++++++++++-------- .../scala-3/cats/derived/TraverseTests.scala | 17 ----- 23 files changed, 71 insertions(+), 89 deletions(-) delete mode 100644 core/src/test/scala-3/cats/derived/TraverseTests.scala diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 44e8cdf5..9bcfcb29 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -56,7 +56,7 @@ class ApplicativeSuite extends KittensSuite: checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].applicative[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].applicative[Int, String, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].applicative[Int, String, Long]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Applicative[Interleaved]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Applicative[Interleaved])) } end ApplicativeSuite diff --git a/core/src/test/scala-3/cats/derived/ApplySuite.scala b/core/src/test/scala-3/cats/derived/ApplySuite.scala index 8193ccb5..15a9af6d 100644 --- a/core/src/test/scala-3/cats/derived/ApplySuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplySuite.scala @@ -55,7 +55,7 @@ class ApplySuite extends KittensSuite: checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].apply[Int, String, Long]) checkAll(s"$instance[AndInt]", tests[AndInt].apply[Int, String, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].apply[Int, String, Long]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Apply[Interleaved]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Apply[Interleaved])) } end ApplySuite diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index a91571e2..b50cbc11 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -17,7 +17,7 @@ package cats.derived import cats.kernel.{CommutativeMonoid, CommutativeSemigroup} -import cats.kernel.laws.discipline.{CommutativeMonoidTests, SerializableTests} +import cats.kernel.laws.discipline.* import scala.compiletime.* class CommutativeMonoidSuite extends KittensSuite: @@ -56,15 +56,7 @@ class CommutativeMonoidSuite extends KittensSuite: val instance = "derived.commutativeMonoid" checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeMonoid) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeMonoid) - checkAll( - s"$instance is Serializable", - SerializableTests.serializable(summonInline[CommutativeMonoid[CommutativeFoo]]) - ) - test(s"$instance respects existing instances") { - val box = summonInline[CommutativeMonoid[BoxMul]] - assert(box.empty == BoxMul(Box(Mul(1)))) - assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))) == BoxMul(Box(Mul(25)))) - } + checkAll(s"$instance is Serializable", SerializableTests.serializable(CommutativeMonoid[CommutativeFoo])) } end CommutativeMonoidSuite diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index 4e1e7165..1670fdd4 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -17,7 +17,7 @@ package cats.derived import cats.kernel.CommutativeSemigroup -import cats.kernel.laws.discipline.{CommutativeSemigroupTests, SerializableTests} +import cats.kernel.laws.discipline.* import scala.compiletime.* class CommutativeSemigroupSuite extends KittensSuite: @@ -55,14 +55,7 @@ class CommutativeSemigroupSuite extends KittensSuite: val instance = "derived.commutativeSemigroup" checkAll(s"$instance[CommutativeFoo]", tests[CommutativeFoo].commutativeSemigroup) checkAll(s"$instance[BoxMul]", tests[BoxMul].commutativeSemigroup) - checkAll( - s"$instance is Serializable", - SerializableTests.serializable(summonInline[CommutativeSemigroup[CommutativeFoo]]) - ) - test(s"$instance respects existing instances") { - val box = summonInline[CommutativeSemigroup[BoxMul]] - assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))).x.content.value == 25) - } + checkAll(s"$instance is Serializable", SerializableTests.serializable(CommutativeSemigroup[CommutativeFoo])) } end CommutativeSemigroupSuite diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index f6d211a5..57e0b706 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -56,7 +56,7 @@ class ContravariantSuite extends KittensSuite: val instance = "derived.contravariant" checkAll(s"$instance[EnumK1Contra]", tests[EnumK1Contra].contravariant[MiniInt, String, Boolean]) checkAll(s"$instance[Single]", tests[Single].contravariant[MiniInt, String, Boolean]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Contravariant[EnumK1Contra]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Contravariant[EnumK1Contra])) } end ContravariantSuite diff --git a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala index 236de348..d76fd24a 100644 --- a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala @@ -58,6 +58,7 @@ class EmptyKSuite extends KittensSuite: test(s"$instance[CaseClassWOption]")(assert(emptyK[CaseClassWOption].x.value.isEmpty)) test(s"$instance[IList]")(assert(emptyK[IList].x == INil())) test(s"$instance[Snoc]")(assert(emptyK[Snoc].x == SNil())) + checkAll(s"$instance is Serializable", SerializableTests.serializable(EmptyK[Snoc])) } end EmptyKSuite diff --git a/core/src/test/scala-3/cats/derived/EmptySuite.scala b/core/src/test/scala-3/cats/derived/EmptySuite.scala index 8470e19f..c8966a75 100644 --- a/core/src/test/scala-3/cats/derived/EmptySuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptySuite.scala @@ -64,7 +64,7 @@ class EmptySuite extends KittensSuite: test(s"$instance[IList[Dummy]]")(assert(empty[IList[Int]].x == INil())) test(s"$instance[Snoc[Dummy]]")(assert(empty[Snoc[Int]].x == SNil())) test(s"$instance respects existing instances")(assert(empty[BoxMask].x == Box(Mask(0xffffffff)))) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Empty[Foo]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Empty[Foo])) } end EmptySuite diff --git a/core/src/test/scala-3/cats/derived/EqSuite.scala b/core/src/test/scala-3/cats/derived/EqSuite.scala index 0f66d2a5..9f7a01b3 100644 --- a/core/src/test/scala-3/cats/derived/EqSuite.scala +++ b/core/src/test/scala-3/cats/derived/EqSuite.scala @@ -57,7 +57,7 @@ class EqSuite extends KittensSuite.WithoutEq: checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].eqv) checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].eqv) checkAll(s"$instance[Recursive]", tests[Recursive].eqv) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Eq[Foo]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Eq[Foo])) } end EqSuite diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 504f4ed9..528a005c 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -65,7 +65,7 @@ class FoldableSuite extends KittensSuite: checkAll(s"$instance[Many]", tests[Many].foldable[Int, Long]) checkAll(s"$instance[AtMostOne]", tests[AtMostOne].foldable[Int, Long]) checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].foldable[Int, Long]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Foldable[Tree]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Foldable[Tree])) } end FoldableSuite diff --git a/core/src/test/scala-3/cats/derived/FunctorSuite.scala b/core/src/test/scala-3/cats/derived/FunctorSuite.scala index 6fdf1b03..a45e9862 100644 --- a/core/src/test/scala-3/cats/derived/FunctorSuite.scala +++ b/core/src/test/scala-3/cats/derived/FunctorSuite.scala @@ -68,7 +68,7 @@ class FunctorSuite extends KittensSuite: checkAll(s"$instance[Many]", tests[Many].functor[Boolean, Int, Boolean]) checkAll(s"$instance[AtMostOne]", tests[AtMostOne].functor[Boolean, Int, Boolean]) checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].functor[Boolean, Int, Boolean]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Functor[Tree]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Functor[Tree])) } end FunctorSuite diff --git a/core/src/test/scala-3/cats/derived/HashSuite.scala b/core/src/test/scala-3/cats/derived/HashSuite.scala index 2a4ee162..ad81a28e 100644 --- a/core/src/test/scala-3/cats/derived/HashSuite.scala +++ b/core/src/test/scala-3/cats/derived/HashSuite.scala @@ -44,7 +44,7 @@ class HashSuite extends KittensSuite: checkAll(s"$instance[Tree[Int]]", tests[Tree[Int]].hash) checkAll(s"$instance[Recursive]", tests[Recursive].hash) checkAll(s"$instance[EnumK0]", tests[EnumK0].hash) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Hash[Inner]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Hash[Inner])) } end HashSuite diff --git a/core/src/test/scala-3/cats/derived/InvariantSuite.scala b/core/src/test/scala-3/cats/derived/InvariantSuite.scala index 44755250..e4abab12 100644 --- a/core/src/test/scala-3/cats/derived/InvariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/InvariantSuite.scala @@ -63,6 +63,7 @@ class InvariantSuite extends KittensSuite: checkAll(s"$instance[Many]", tests[Many].invariant[MiniInt, String, Boolean]) checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].invariant[MiniInt, String, Boolean]) checkAll(s"$instance[AtMostOne]", tests[AtMostOne].invariant[MiniInt, String, Boolean]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Invariant[AtMostOne])) } end InvariantSuite diff --git a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala index f4c751d8..3ff5692f 100644 --- a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala @@ -38,7 +38,7 @@ class MonoidKSuite extends KittensSuite: checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].monoidK[Char]) checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].monoidK[Char]) checkAll(s"$instance[Simple]", tests[Simple].monoidK[Char]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[MonoidK[ComplexProduct]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(MonoidK[ComplexProduct])) } end MonoidKSuite diff --git a/core/src/test/scala-3/cats/derived/MonoidSuite.scala b/core/src/test/scala-3/cats/derived/MonoidSuite.scala index 38a06c8a..f6324d64 100644 --- a/core/src/test/scala-3/cats/derived/MonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidSuite.scala @@ -55,12 +55,7 @@ class MonoidSuite extends KittensSuite: checkAll(s"$instance[Foo]", tests[Foo].monoid) checkAll(s"$instance[Interleaved[Int]]", tests[Interleaved[Int]].monoid) checkAll(s"$instance[BoxMul]", tests[BoxMul].monoid) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Monoid[Foo]])) - test(s"$instance respects existing instances") { - val box = summonInline[Monoid[BoxMul]] - assert(box.empty == BoxMul(Box(Mul(1)))) - assert(box.combine(BoxMul(Box(Mul(5))), BoxMul(Box(Mul(5)))) == BoxMul(Box(Mul(25)))) - } + checkAll(s"$instance is Serializable", SerializableTests.serializable(Monoid[Foo])) } end MonoidSuite diff --git a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala index 2a1df181..1d0fdc74 100644 --- a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala @@ -101,10 +101,7 @@ class NonEmptyTraverseSuite extends KittensSuite: s"$instance[AtLeastOne]", tests[AtLeastOne].nonEmptyTraverse[Option, Int, Int, Int, Int, Option, Option] ) - checkAll( - s"$instance is Serializable", - SerializableTests.serializable(summonInline[NonEmptyTraverse[Tree]]) - ) + checkAll(s"$instance is Serializable", SerializableTests.serializable(NonEmptyTraverse[Tree])) } end NonEmptyTraverseSuite diff --git a/core/src/test/scala-3/cats/derived/OrderSuite.scala b/core/src/test/scala-3/cats/derived/OrderSuite.scala index 4dbe7ed3..14a29a3f 100644 --- a/core/src/test/scala-3/cats/derived/OrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/OrderSuite.scala @@ -55,7 +55,7 @@ class OrderSuite extends KittensSuite: checkAll(s"$instance[Recursive]", tests[Recursive].order) checkAll(s"$instance[GenericAdt[Int]]", tests[GenericAdt[Int]].order) checkAll(s"$instance[EnumK0]", tests[EnumK0].order) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Order[Interleaved[Int]]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Order[Interleaved[Int]])) } end OrderSuite diff --git a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala index 5e08d526..b25286ee 100644 --- a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala @@ -67,7 +67,7 @@ class PartialOrderSuite extends KittensSuite: checkAll(s"$instance[Recursive]", tests[Recursive].partialOrder) checkAll(s"$instance[BoxKV]", tests[BoxKV].partialOrder) checkAll(s"$instance[EnumK0]", tests[EnumK0].partialOrder) - checkAll(s"$instance is Serialiable", SerializableTests.serializable(summonInline[PartialOrder[Tree[Int]]])) + checkAll(s"$instance is Serialiable", SerializableTests.serializable(PartialOrder[Tree[Int]])) } end PartialOrderSuite diff --git a/core/src/test/scala-3/cats/derived/PureSuite.scala b/core/src/test/scala-3/cats/derived/PureSuite.scala index 07302c92..72fd7e59 100644 --- a/core/src/test/scala-3/cats/derived/PureSuite.scala +++ b/core/src/test/scala-3/cats/derived/PureSuite.scala @@ -55,13 +55,13 @@ class PureSuite extends KittensSuite: locally { import derivedInstances.* val instance = "derived.pure" + checkAll(s"$instance is Serializable", SerializableTests.serializable(Pure[Interleaved])) test(s"$instance[CaseClassWOption]")( assert(3.14.pure[CaseClassWOption].x == TestDefns.CaseClassWOption(Some(3.14))) ) test(s"$instance[Interleaved]")( assert('x'.pure[Interleaved].x == TestDefns.Interleaved(0, 'x', 0, Vector('x'), "")) ) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Pure[Interleaved]])) } end PureSuite diff --git a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala index 1df11df4..582e20d0 100644 --- a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala +++ b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala @@ -39,6 +39,7 @@ class ReducibleSuite extends KittensSuite: checkAll(s"$instance[Interleaved]", tests[Interleaved].reducible[Option, Int, Long]) checkAll(s"$instance[BoxZipper]", tests[BoxZipper].reducible[Option, Int, Long]) checkAll(s"$instance[EnumK1]", tests[EnumK1].reducible[Option, Int, Long]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].reducible[Option, Int, Long]) checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Reducible[Tree]])) locally { @@ -58,7 +59,8 @@ class ReducibleSuite extends KittensSuite: checkAll(s"$instance[Tree]", tests[Tree].reducible[Option, Int, Long]) checkAll(s"$instance[Interleaved]", tests[Interleaved].reducible[Option, Int, Long]) checkAll(s"$instance[EnumK1]", tests[EnumK1].reducible[Option, Int, Long]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Reducible[Tree]])) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].reducible[Option, Int, Long]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Reducible[Tree])) } end ReducibleSuite @@ -80,12 +82,14 @@ object ReducibleSuite: given Reducible[Interleaved] = semiauto.reducible given Reducible[BoxZipper] = semiauto.reducible given Reducible[EnumK1] = semiauto.reducible + given Reducible[AtLeastOne] = semiauto.reducible object derivedInstances: case class ICons[A](x: TestDefns.ICons[A]) derives Reducible case class Tree[A](x: TestDefns.Tree[A]) derives Reducible case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Reducible case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Reducible + case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Reducible final case class Zipper[+A](left: List[A], focus: A, right: List[A]) object Zipper: diff --git a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala index 1e3a28c0..5c2743cb 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala @@ -36,7 +36,7 @@ class SemigroupKSuite extends KittensSuite: checkAll(s"$instance[ComplexProduct]", tests[ComplexProduct].semigroupK[Char]) checkAll(s"$instance[CaseClassWOption]", tests[CaseClassWOption].semigroupK[Char]) checkAll(s"$instance[Simple]", tests[Simple].semigroupK[Char]) - checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[SemigroupK[ComplexProduct]])) + checkAll(s"$instance is Serializable", SerializableTests.serializable(SemigroupK[ComplexProduct])) } end SemigroupKSuite diff --git a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala index 6a55d5c4..581192a5 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala @@ -56,7 +56,7 @@ class SemigroupSuite extends KittensSuite: checkAll(s"$instances[Foo]", tests[Foo].semigroup) checkAll(s"$instances[Interleaved[Int]]", tests[Interleaved[Int]].semigroup) checkAll(s"$instances[BoxMul]", tests[BoxMul].semigroup) - checkAll(s"$instances is Serializable", SerializableTests.serializable(summonInline[Semigroup[Foo]])) + checkAll(s"$instances is Serializable", SerializableTests.serializable(Semigroup[Foo])) } end SemigroupSuite diff --git a/core/src/test/scala-3/cats/derived/TraverseSuite.scala b/core/src/test/scala-3/cats/derived/TraverseSuite.scala index 27e66c96..b0254b8e 100644 --- a/core/src/test/scala-3/cats/derived/TraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/TraverseSuite.scala @@ -1,49 +1,52 @@ package cats.derived import cats.{Eq, Traverse} -import cats.laws.discipline.{SerializableTests, TraverseTests} -import org.scalacheck.Arbitrary - +import cats.laws.discipline.* import scala.compiletime.* class TraverseSuite extends KittensSuite: import TestDefns.* import TraverseSuite.* - inline def traverseTests[F[_]]: TraverseTests[F] = + inline def tests[F[_]]: TraverseTests[F] = TraverseTests[F](summonInline) - inline def testTraverse(inline context: String): Unit = - checkAll(s"$context.Traverse[IList]", traverseTests[IList].traverse[Int, Double, String, Long, Option, Option]) - checkAll(s"$context.Traverse[Tree]", traverseTests[Tree].traverse[Int, Double, String, Long, Option, Option]) - checkAll( - s"$context.Traverse[GenericAdt]", - traverseTests[GenericAdt].traverse[Int, Double, String, Long, Option, Option] - ) - checkAll(s"$context.Traverse[OptList]", traverseTests[OptList].traverse[Int, Double, String, Long, Option, Option]) - checkAll( - s"$context.Traverse[ListSnoc]", - traverseTests[ListSnoc].traverse[Int, Double, String, Long, Option, Option] - ) - checkAll(s"$context.Traverse[AndChar]", traverseTests[AndChar].traverse[Int, Double, String, Long, Option, Option]) - checkAll( - s"$context.Traverse[Interleaved]", - traverseTests[Interleaved].traverse[Int, Double, String, Long, Option, Option] - ) - checkAll( - s"$context.Traverse[EnumK1]", - traverseTests[EnumK1].traverse[Int, Double, String, Long, Option, Option] - ) - checkAll(s"$context.Traverse is Serializable", SerializableTests.serializable(summonInline[Traverse[Tree]])) + inline def validate(inline instance: String): Unit = + checkAll(s"$instance[IList]", tests[IList].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Tree]", tests[Tree].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[OptList]", tests[OptList].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[ListSnoc]", tests[ListSnoc].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[AndChar]", tests[AndChar].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Many]", tests[Many].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(summonInline[Traverse[Tree]])) locally { import auto.traverse.given - testTraverse("auto") + validate("auto.traverse") } locally { import semiInstances.given - testTraverse("semiauto") + validate("semiauto.traverse") + } + + locally { + import derivedInstances.* + val instance = "derived.traverse" + checkAll(s"$instance[IList]", tests[IList].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Tree]", tests[Tree].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[GenericAdt]", tests[GenericAdt].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Interleaved]", tests[Interleaved].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[EnumK1]", tests[EnumK1].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[Many]", tests[Many].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[AtMostOne]", tests[AtMostOne].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance[AtLeastOne]", tests[AtLeastOne].traverse[Int, Double, String, Long, Option, Option]) + checkAll(s"$instance is Serializable", SerializableTests.serializable(Traverse[Tree])) } end TraverseSuite @@ -64,5 +67,18 @@ object TraverseSuite: given Traverse[AndChar] = semiauto.traverse given Traverse[Interleaved] = semiauto.traverse given Traverse[EnumK1] = semiauto.traverse + given Traverse[Many] = semiauto.traverse + given Traverse[AtLeastOne] = semiauto.traverse + given Traverse[AtMostOne] = semiauto.traverse + + object derivedInstances: + case class IList[A](x: TestDefns.IList[A]) derives Traverse + case class Tree[A](x: TestDefns.Tree[A]) derives Traverse + case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Traverse + case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Traverse + case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Traverse + case class Many[A](x: TestDefns.Many[A]) derives Traverse + case class AtMostOne[A](x: TestDefns.AtMostOne[A]) derives Traverse + case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Traverse end TraverseSuite diff --git a/core/src/test/scala-3/cats/derived/TraverseTests.scala b/core/src/test/scala-3/cats/derived/TraverseTests.scala deleted file mode 100644 index d6c410ff..00000000 --- a/core/src/test/scala-3/cats/derived/TraverseTests.scala +++ /dev/null @@ -1,17 +0,0 @@ -package cats.derived - -import cats.Traverse -import cats.derived.* - -class TraverseTests { - - case class Box[A](value: A) derives Traverse - - sealed trait Maybe[+A] derives Traverse - case object Nufin extends Maybe[Nothing] - case class Just[A](value: A) extends Maybe[A] - - sealed trait CList[A] derives Traverse - case object CNil extends CList[Nothing] - case class CCons[A](head: A, tail: CList[A]) extends CList[A] -} From 5acedf05b53f81b777b11ce2f3e79c3a66964069 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 12:18:12 +0200 Subject: [PATCH 28/29] Refactor and rename ADT definitions --- .../derived/{adtdefns.scala => ADTs.scala} | 293 ++++++------------ .../cats/derived/ApplicativeSuite.scala | 8 +- .../scala-3/cats/derived/ApplySuite.scala | 8 +- .../cats/derived/CommutativeMonoidSuite.scala | 6 +- .../derived/CommutativeSemigroupSuite.scala | 6 +- .../cats/derived/ContravariantSuite.scala | 6 +- .../scala-3/cats/derived/EmptyKSuite.scala | 10 +- .../scala-3/cats/derived/EmptySuite.scala | 24 +- .../test/scala-3/cats/derived/EqSuite.scala | 18 +- .../scala-3/cats/derived/FoldableSuite.scala | 22 +- .../scala-3/cats/derived/FunctorSuite.scala | 20 +- .../test/scala-3/cats/derived/HashSuite.scala | 18 +- .../scala-3/cats/derived/InvariantSuite.scala | 16 +- .../scala-3/cats/derived/KittensSuite.scala | 2 +- .../scala-3/cats/derived/MonoidKSuite.scala | 8 +- .../scala-3/cats/derived/MonoidSuite.scala | 8 +- .../cats/derived/NonEmptyTraverseSuite.scala | 16 +- .../scala-3/cats/derived/OrderSuite.scala | 16 +- .../cats/derived/PartialOrderSuite.scala | 18 +- .../test/scala-3/cats/derived/PureSuite.scala | 12 +- .../scala-3/cats/derived/ReducibleSuite.scala | 16 +- .../cats/derived/SemigroupKSuite.scala | 8 +- .../scala-3/cats/derived/SemigroupSuite.scala | 8 +- .../cats/derived/ShowPrettySuite.scala | 24 +- .../test/scala-3/cats/derived/ShowSuite.scala | 24 +- .../scala-3/cats/derived/TraverseSuite.scala | 20 +- 26 files changed, 267 insertions(+), 368 deletions(-) rename core/src/test/scala-3/cats/derived/{adtdefns.scala => ADTs.scala} (60%) diff --git a/core/src/test/scala-3/cats/derived/adtdefns.scala b/core/src/test/scala-3/cats/derived/ADTs.scala similarity index 60% rename from core/src/test/scala-3/cats/derived/adtdefns.scala rename to core/src/test/scala-3/cats/derived/ADTs.scala index 029216ac..aac23d15 100644 --- a/core/src/test/scala-3/cats/derived/adtdefns.scala +++ b/core/src/test/scala-3/cats/derived/ADTs.scala @@ -20,11 +20,9 @@ import cats.{Eq, Eval} import cats.syntax.all.given import org.scalacheck.rng.Seed import org.scalacheck.{Arbitrary, Cogen, Gen} - import scala.annotation.tailrec -object TestDefns: - +object ADTs: enum EnumK0: case LeafS(value: String) case LeafI(value: Int) @@ -47,79 +45,45 @@ object TestDefns: case Rec(l: EnumK1[A], r: EnumK1[A]) object EnumK1: - given [A](using Arbitrary[A]): Arbitrary[EnumK1[A]] = Arbitrary( - Gen.recursive(rec => - Gen.sized(size => + given [A: Arbitrary]: Arbitrary[EnumK1[A]] = + Arbitrary(Gen.recursive { rec => + Gen.sized { size => val leaf = Arbitrary.arbitrary[A].map(Leaf.apply) if size == 0 then leaf - else - Gen.resize( - size / 2, - Gen.oneOf( - leaf, - for - l <- rec - r <- rec - yield Rec(l, r) - ) - ) - ) - ) - ) + else Gen.resize(size / 2, Gen.oneOf(leaf, Gen.zip(rec, rec).map(Rec.apply))) + } + }) enum EnumK1Contra[-A]: case Leaf(value: A => Unit) case Rec(l: EnumK1Contra[A], r: EnumK1Contra[A]) object EnumK1Contra: - given [A](using Arbitrary[A => Unit]): Arbitrary[EnumK1Contra[A]] = Arbitrary( - Gen.recursive(rec => - Gen.sized(size => + given [A](using Arbitrary[A => Unit]): Arbitrary[EnumK1Contra[A]] = + Arbitrary(Gen.recursive { rec => + Gen.sized { size => val leaf = Arbitrary.arbitrary[A => Unit].map(Leaf.apply) if size == 0 then leaf - else - Gen.resize( - size / 2, - Gen.oneOf( - leaf, - for - l <- rec - r <- rec - yield Rec(l, r) - ) - ) - ) - ) - ) + else Gen.resize(size / 2, Gen.oneOf(leaf, Gen.zip(rec, rec).map(Rec.apply))) + } + }) enum EnumK1Inv[A]: case Leaf(cov: A, contra: A => Unit) case Rec(l: EnumK1Inv[A], r: EnumK1Inv[A]) object EnumK1Inv: - given [A](using Arbitrary[A], Arbitrary[A => Unit]): Arbitrary[EnumK1Inv[A]] = Arbitrary( - Gen.recursive(rec => - Gen.sized(size => - val leaf = - for - cov <- Arbitrary.arbitrary[A] - contra <- Arbitrary.arbitrary[A => Unit] - yield Leaf(cov, contra) + given [A: Arbitrary](using Arbitrary[A => Unit]): Arbitrary[EnumK1Inv[A]] = + Arbitrary(Gen.recursive { rec => + Gen.sized { size => + val leaf = for + cov <- Arbitrary.arbitrary[A] + contra <- Arbitrary.arbitrary[A => Unit] + yield Leaf(cov, contra) if size == 0 then leaf - else - Gen.resize( - size / 2, - Gen.oneOf( - leaf, - for - l <- rec - r <- rec - yield Rec(l, r) - ) - ) - ) - ) - ) + else Gen.resize(size / 2, Gen.oneOf(leaf, Gen.zip(rec, rec).map(Rec.apply))) + } + }) sealed trait Rgb object Rgb: @@ -163,21 +127,17 @@ object TestDefns: object Interleaved: def empty[T](t: T): Interleaved[T] = Interleaved(0, t, 0, Vector.empty, "") - given [T: Arbitrary]: Arbitrary[Interleaved[T]] = - Arbitrary(Arbitrary.arbitrary[(Int, T, Long, Vector[T], String)].map((apply[T] _).tupled)) - + Arbitrary(Arbitrary.arbitrary[(Int, T, Long, Vector[T], String)].map(apply)) given [T: Cogen]: Cogen[Interleaved[T]] = Cogen[(Int, T, Long, Vector[T], String)].contramap(x => (x.i, x.t, x.l, x.tt, x.s)) case class Bivariant[A](run: A => Boolean, store: A) object Bivariant: - given [A: Arbitrary]: Arbitrary[Bivariant[A]] = Arbitrary( - for - a <- Arbitrary.arbitrary[A] - f <- Arbitrary.arbitrary[Boolean].map(Function.const[Boolean, A]) - yield Bivariant[A](f, a) - ) + given [A: Arbitrary]: Arbitrary[Bivariant[A]] = Arbitrary(for + a <- Arbitrary.arbitrary[A] + f <- Arbitrary.arbitrary[Boolean].map(Function.const[Boolean, A]) + yield Bivariant[A](f, a)) case class Pred[A](run: A => Boolean) @@ -186,24 +146,18 @@ object TestDefns: final case class INil[A]() extends IList[A] object ICons: - - given [A: Arbitrary]: Arbitrary[ICons[A]] = - Arbitrary(for - head <- Arbitrary.arbitrary[A] - tail <- Arbitrary.arbitrary[IList[A]] - yield ICons(head, tail)) + given [A: Arbitrary]: Arbitrary[ICons[A]] = Arbitrary(for + head <- Arbitrary.arbitrary[A] + tail <- Arbitrary.arbitrary[IList[A]] + yield ICons(head, tail)) object IList: - given [A: Arbitrary]: Arbitrary[IList[A]] = Arbitrary(Arbitrary.arbitrary[Seq[A]].map(fromSeq)) - given [A: Cogen]: Cogen[IList[A]] = Cogen[Seq[A]].contramap(toList) - def fromSeq[T](ts: Seq[T]): IList[T] = ts.foldRight[IList[T]](INil())(ICons.apply) - def toList[T](list: IList[T]): List[T] = @tailrec def loop(list: IList[T], acc: List[T]): List[T] = list match case INil() => acc.reverse @@ -215,13 +169,10 @@ object TestDefns: final case class SNil[A]() extends Snoc[A] object Snoc: - given [A: Arbitrary]: Arbitrary[Snoc[A]] = Arbitrary(Arbitrary.arbitrary[Seq[A]].map(fromSeq)) - def fromSeq[T](ts: Seq[T]): Snoc[T] = ts.foldLeft[Snoc[T]](SNil())(SCons.apply) - def toList[T](snoc: Snoc[T]): List[T] = @tailrec def loop(snoc: Snoc[T], acc: List[T]): List[T] = snoc match case SNil() => acc @@ -229,12 +180,10 @@ object TestDefns: loop(snoc, Nil) object SCons: - - given [A: Arbitrary]: Arbitrary[SCons[A]] = - Arbitrary(for - init <- Arbitrary.arbitrary[Snoc[A]] - last <- Arbitrary.arbitrary[A] - yield SCons(init, last)) + given [A: Arbitrary]: Arbitrary[SCons[A]] = Arbitrary(for + init <- Arbitrary.arbitrary[Snoc[A]] + last <- Arbitrary.arbitrary[A] + yield SCons(init, last)) sealed trait Tree[A] final case class Leaf[A](value: A) extends Tree[A] @@ -243,18 +192,15 @@ object TestDefns: object Tree: given [A: Arbitrary]: Arbitrary[Tree[A]] = val leaf = Arbitrary.arbitrary[A].map(Leaf.apply) - def tree(maxDepth: Int): Gen[Tree[A]] = if (maxDepth <= 0) leaf else Gen.oneOf(leaf, node(maxDepth)) - def node(maxDepth: Int): Gen[Tree[A]] = for depthL <- Gen.choose(0, maxDepth - 1) depthR <- Gen.choose(0, maxDepth - 1) left <- tree(depthL) right <- tree(depthR) yield Node(left, right) - Arbitrary(Gen.sized(tree)) given [A: Cogen]: Cogen[Tree[A]] = @@ -268,46 +214,31 @@ object TestDefns: final case class Foo(i: Int, b: Option[String]) object Foo: - - given Cogen[Foo] = - Cogen[Int].contramap(_.i) - - given Arbitrary[Foo] = - Arbitrary(for - i <- Arbitrary.arbitrary[Int] - b <- Arbitrary.arbitrary[Option[String]] - yield Foo(i, b)) + given Cogen[Foo] = Cogen[Int].contramap(_.i) + given Arbitrary[Foo] = Arbitrary(for + i <- Arbitrary.arbitrary[Int] + b <- Arbitrary.arbitrary[Option[String]] + yield Foo(i, b)) final case class CommutativeFoo(i: Int, b: Option[Long]) object CommutativeFoo: - given Cogen[CommutativeFoo] = Cogen[(Int, Option[Long])].contramap(x => (x.i, x.b)) - - given Arbitrary[CommutativeFoo] = - Arbitrary(for - i <- Arbitrary.arbitrary[Int] - b <- Arbitrary.arbitrary[Option[Long]] - yield CommutativeFoo(i, b)) + given Arbitrary[CommutativeFoo] = Arbitrary(for + i <- Arbitrary.arbitrary[Int] + b <- Arbitrary.arbitrary[Option[Long]] + yield CommutativeFoo(i, b)) case class Inner(i: Int) case class Outer(in: Inner) object Inner: - - given Arbitrary[Inner] = - Arbitrary(Arbitrary.arbitrary[Int].map(apply)) - - given Cogen[Inner] = - Cogen[Int].contramap(_.i) + given Arbitrary[Inner] = Arbitrary(Arbitrary.arbitrary[Int].map(apply)) + given Cogen[Inner] = Cogen[Int].contramap(_.i) object Outer: - - given Arbitrary[Outer] = - Arbitrary(Arbitrary.arbitrary[Inner].map(apply)) - - given Cogen[Outer] = - Cogen[Inner].contramap(_.in) + given Arbitrary[Outer] = Arbitrary(Arbitrary.arbitrary[Inner].map(apply)) + given Cogen[Outer] = Cogen[Inner].contramap(_.in) sealed trait IntTree final case class IntLeaf(t: Int) extends IntTree @@ -319,10 +250,8 @@ object TestDefns: final case class GenericAdtCase[A](value: Option[A]) extends GenericAdt[A] object GenericAdt: - given [A: Arbitrary]: Arbitrary[GenericAdt[A]] = Arbitrary(Arbitrary.arbitrary[Option[A]].map(GenericAdtCase.apply)) - given [A: Cogen]: Cogen[GenericAdt[A]] = Cogen[Option[A]].contramap { case GenericAdtCase(value) => value } @@ -379,101 +308,71 @@ object TestDefns: ) ) -end TestDefns - -trait TestEqInstances: - import TestDefns.* + trait EqInstances: + import ADTs.* - given [T: Eq]: Eq[ComplexProduct[T]] with - val eqSet = Eq[Set[T]] - val eqVec = Eq[Vector[T]] - val eqOpt = Eq[Eval[Option[T]]] + given [T: Eq]: Eq[ComplexProduct[T]] = (x, y) => + x.lbl == y.lbl && x.set === y.set && x.fns.map(_()) === y.fns.map(_()) && x.opt === y.opt - def eqv(x: ComplexProduct[T], y: ComplexProduct[T]) = - x.lbl == y.lbl && - eqSet.eqv(x.set, y.set) && - eqVec.eqv(x.fns.map(_()), y.fns.map(_())) && - eqOpt.eqv(x.opt, y.opt) + given [A: Eq]: Eq[Box[A]] = Eq.by(_.content) + given Eq[Recursive] = Eq.fromUniversalEquals + given [T: Eq]: Eq[Interleaved[T]] = Eq.by(i => (i.i, i.t, i.l, i.tt, i.s)) - given [A: Eq]: Eq[Box[A]] = - Eq.by(_.content) + given [A: Eq]: Eq[IList[A]] with + @tailrec final def eqv(x: IList[A], y: IList[A]): Boolean = (x, y) match + case (ICons(hx, tx), ICons(hy, ty)) => hx === hy && eqv(tx, ty) + case (INil(), INil()) => true + case _ => false - given Eq[Recursive] = - Eq.fromUniversalEquals + given [A: Eq]: Eq[Snoc[A]] with + @tailrec final def eqv(x: Snoc[A], y: Snoc[A]): Boolean = (x, y) match + case (SCons(ix, lx), SCons(iy, ly)) => lx === ly && eqv(ix, iy) + case (SNil(), SNil()) => true + case _ => false - given [T: Eq]: Eq[Interleaved[T]] = - Eq.by(i => (i.i, i.t, i.l, i.tt, i.s)) + given [A: Eq]: Eq[ICons[A]] = Eq.by(identity[IList[A]]) + given [A: Eq]: Eq[SCons[A]] = Eq.by(identity[Snoc[A]]) - given [A](using A: Eq[A]): Eq[IList[A]] = new Eq[IList[A]]: - @tailrec def eqv(x: IList[A], y: IList[A]): Boolean = (x, y) match - case (ICons(hx, tx), ICons(hy, ty)) => A.eqv(hx, hy) && eqv(tx, ty) - case (INil(), INil()) => true - case _ => false - - given [A](using A: Eq[A]): Eq[Snoc[A]] = new Eq[Snoc[A]]: - @tailrec def eqv(x: Snoc[A], y: Snoc[A]): Boolean = (x, y) match - case (SCons(ix, lx), SCons(iy, ly)) => A.eqv(lx, ly) && eqv(ix, iy) - case (SNil(), SNil()) => true - case _ => false - - given [A: Eq]: Eq[ICons[A]] = Eq.by(identity[IList[A]]) - given [A: Eq]: Eq[SCons[A]] = Eq.by(identity[Snoc[A]]) - - given [A](using A: Eq[A]): Eq[Tree[A]] with - def eqv(x: Tree[A], y: Tree[A]): Boolean = (x, y) match - case (Leaf(vx), Leaf(vy)) => A.eqv(vx, vy) - case (Node(lx, rx), Node(ly, ry)) => eqv(lx, ly) && eqv(rx, ry) - case _ => false + given [A: Eq]: Eq[Tree[A]] with + def eqv(x: Tree[A], y: Tree[A]): Boolean = (x, y) match + case (Leaf(vx), Leaf(vy)) => vx === vy + case (Node(lx, rx), Node(ly, ry)) => eqv(lx, ly) && eqv(rx, ry) + case _ => false - given [A](using A: Eq[A]): Eq[Bivariant[A]] with - def eqv(x: Bivariant[A], y: Bivariant[A]): Boolean = (x, y) match - case (Bivariant(runX, storeX), Bivariant(runY, storeY)) => - A.eqv(storeX, storeY) && Eq[Boolean].eqv(runX(storeX), runY(storeY)) - - given Eq[Foo] = Eq.fromUniversalEquals - - given Eq[CommutativeFoo] = Eq.fromUniversalEquals - - given [A: Eq]: Eq[GenericAdt[A]] = - val eqvOpt = Eq[Option[A]] - Eq.instance { case (GenericAdtCase(vx), GenericAdtCase(vy)) => eqvOpt.eqv(vx, vy) } - - given [A: Eq]: Eq[CaseClassWOption[A]] = Eq.by(_.value) - - given Eq[Inner] = Eq.fromUniversalEquals + given [A: Eq]: Eq[Bivariant[A]] = { case (Bivariant(runX, storeX), Bivariant(runY, storeY)) => + storeX === storeY && runX(storeX) == runY(storeY) + } - given Eq[Outer] = Eq.fromUniversalEquals + given Eq[Foo] = Eq.fromUniversalEquals + given Eq[CommutativeFoo] = Eq.fromUniversalEquals + given [A: Eq]: Eq[GenericAdt[A]] = Eq.by { case GenericAdtCase(v) => v } + given [A: Eq]: Eq[CaseClassWOption[A]] = Eq.by(_.value) + given Eq[Inner] = Eq.fromUniversalEquals + given Eq[Outer] = Eq.fromUniversalEquals - given Eq[EnumK0] = - import EnumK0.* - Eq.instance { - case (LeafS(s1), LeafS(s2)) => s1 === s2 - case (LeafI(i1), LeafI(i2)) => i1 === i2 + given Eq[EnumK0] = { + case (EnumK0.LeafS(s1), EnumK0.LeafS(s2)) => s1 === s2 + case (EnumK0.LeafI(i1), EnumK0.LeafI(i2)) => i1 === i2 case _ => false } - given [A](using Eq[A]): Eq[EnumK1[A]] = - import EnumK1.* - Eq.instance { - case (Leaf(v1), Leaf(v2)) => v1 === v2 - case (Rec(l1, r1), Rec(l2, r2)) => l1 === l2 && r1 === r2 + given [A: Eq]: Eq[EnumK1[A]] = { + case (EnumK1.Leaf(v1), EnumK1.Leaf(v2)) => v1 === v2 + case (EnumK1.Rec(l1, r1), EnumK1.Rec(l2, r2)) => l1 === l2 && r1 === r2 case _ => false } - given [A](using Eq[A => Unit]): Eq[EnumK1Contra[A]] = - import EnumK1Contra.* - Eq.instance { - case (Leaf(v1), Leaf(v2)) => v1 === v2 - case (Rec(l1, r1), Rec(l2, r2)) => l1 === l2 && r1 === r2 + given [A](using Eq[A => Unit]): Eq[EnumK1Contra[A]] = { + case (EnumK1Contra.Leaf(v1), EnumK1Contra.Leaf(v2)) => v1 === v2 + case (EnumK1Contra.Rec(l1, r1), EnumK1Contra.Rec(l2, r2)) => l1 === l2 && r1 === r2 case _ => false } - given [A](using Eq[A], Eq[A => Unit]): Eq[EnumK1Inv[A]] = - import EnumK1Inv.* - Eq.instance { - case (Leaf(cov1, contra1), Leaf(cov2, contra2)) => cov1 === cov2 && contra1 === contra2 - case (Rec(l1, r1), Rec(l2, r2)) => l1 === l2 && r1 === r2 + given [A: Eq](using Eq[A => Unit]): Eq[EnumK1Inv[A]] = { + case (EnumK1Inv.Leaf(cov1, contra1), EnumK1Inv.Leaf(cov2, contra2)) => cov1 === cov2 && contra1 === contra2 + case (EnumK1Inv.Rec(l1, r1), EnumK1Inv.Rec(l2, r2)) => l1 === l2 && r1 === r2 case _ => false } -end TestEqInstances + end EqInstances +end ADTs diff --git a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala index 9bcfcb29..a326bd86 100644 --- a/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplicativeSuite.scala @@ -24,7 +24,7 @@ import scala.compiletime.* class ApplicativeSuite extends KittensSuite: import ApplicativeSuite.* - import TestDefns.* + import ADTs.* inline given [F[_]]: Isomorphisms[F] = Isomorphisms.invariant(summonInline[Applicative[F]]) @@ -62,7 +62,7 @@ class ApplicativeSuite extends KittensSuite: end ApplicativeSuite object ApplicativeSuite: - import TestDefns.* + import ADTs.* type OptList[A] = Option[List[A]] type AndInt[A] = (A, Int) @@ -77,8 +77,8 @@ object ApplicativeSuite: given Applicative[ListBox] = semiauto.applicative object derivedInstances: - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Applicative - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Applicative + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives Applicative + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Applicative case class AndInt[A](x: ApplicativeSuite.AndInt[A]) derives Applicative end ApplicativeSuite diff --git a/core/src/test/scala-3/cats/derived/ApplySuite.scala b/core/src/test/scala-3/cats/derived/ApplySuite.scala index 15a9af6d..bb066b65 100644 --- a/core/src/test/scala-3/cats/derived/ApplySuite.scala +++ b/core/src/test/scala-3/cats/derived/ApplySuite.scala @@ -23,7 +23,7 @@ import scala.compiletime.* class ApplySuite extends KittensSuite: import ApplySuite.* - import TestDefns.* + import ADTs.* inline given [F[_]]: Isomorphisms[F] = Isomorphisms.invariant(summonInline[Apply[F]]) @@ -61,7 +61,7 @@ class ApplySuite extends KittensSuite: end ApplySuite object ApplySuite: - import TestDefns.* + import ADTs.* type OptList[A] = Option[List[A]] type AndInt[A] = (A, Int) @@ -76,8 +76,8 @@ object ApplySuite: given Apply[ListBox] = semiauto.apply object derivedInstances: - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Apply - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Apply + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives Apply + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Apply case class AndInt[A](x: ApplySuite.AndInt[A]) derives Apply end ApplySuite diff --git a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala index b50cbc11..7418b3ba 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeMonoidSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class CommutativeMonoidSuite extends KittensSuite: import CommutativeMonoidSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: CommutativeMonoidTests[A] = CommutativeMonoidTests[A](summonInline) @@ -62,7 +62,7 @@ class CommutativeMonoidSuite extends KittensSuite: end CommutativeMonoidSuite object CommutativeMonoidSuite: - import TestDefns.* + import ADTs.* type BoxMul = Box[Mul] @@ -72,7 +72,7 @@ object CommutativeMonoidSuite: given CommutativeMonoid[Box[Mul]] = semiauto.commutativeMonoid object derivedInstances: - case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeMonoid + case class CommutativeFoo(x: ADTs.CommutativeFoo) derives CommutativeMonoid case class BoxMul(x: CommutativeMonoidSuite.BoxMul) derives CommutativeMonoid final case class Mul(value: Int) diff --git a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala index 1670fdd4..e4b4d86c 100644 --- a/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/CommutativeSemigroupSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class CommutativeSemigroupSuite extends KittensSuite: import CommutativeSemigroupSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: CommutativeSemigroupTests[A] = CommutativeSemigroupTests[A](summonInline) @@ -61,7 +61,7 @@ class CommutativeSemigroupSuite extends KittensSuite: end CommutativeSemigroupSuite object CommutativeSemigroupSuite: - import TestDefns.* + import ADTs.* type BoxMul = Box[Mul] @@ -71,7 +71,7 @@ object CommutativeSemigroupSuite: given CommutativeSemigroup[BoxMul] = semiauto.commutativeSemigroup object derivedInstances: - case class CommutativeFoo(x: TestDefns.CommutativeFoo) derives CommutativeSemigroup + case class CommutativeFoo(x: ADTs.CommutativeFoo) derives CommutativeSemigroup case class BoxMul(x: CommutativeSemigroupSuite.BoxMul) derives CommutativeSemigroup final case class Mul(value: Int) diff --git a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala index 57e0b706..c9c8f700 100644 --- a/core/src/test/scala-3/cats/derived/ContravariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/ContravariantSuite.scala @@ -24,7 +24,7 @@ import scala.compiletime.* class ContravariantSuite extends KittensSuite: import ContravariantSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: ContravariantTests[F] = ContravariantTests[F](summonInline) @@ -62,7 +62,7 @@ class ContravariantSuite extends KittensSuite: end ContravariantSuite object ContravariantSuite: - import TestDefns.* + import ADTs.* type OptPred[A] = Option[A => Boolean] type ListPred[A] = List[A => Boolean] @@ -84,7 +84,7 @@ object ContravariantSuite: given Contravariant[EnumK1Contra] = semiauto.contravariant object derivedInstances: - case class EnumK1Contra[-A](x: TestDefns.EnumK1Contra[A]) derives Contravariant + case class EnumK1Contra[-A](x: ADTs.EnumK1Contra[A]) derives Contravariant case class Single[-A](value: A => Unit) derives Contravariant enum Many[-A] derives Contravariant: diff --git a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala index d76fd24a..f01fc1eb 100644 --- a/core/src/test/scala-3/cats/derived/EmptyKSuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptyKSuite.scala @@ -24,7 +24,7 @@ import scala.compiletime.summonInline class EmptyKSuite extends KittensSuite: import EmptyKSuite.* - import TestDefns.* + import ADTs.* given Pure[Box] with def pure[A](a: A) = Box(a) @@ -64,7 +64,7 @@ class EmptyKSuite extends KittensSuite: end EmptyKSuite object EmptyKSuite: - import TestDefns.* + import ADTs.* type LOption[A] = List[Option[A]] type PList[A] = (List[A], List[A]) @@ -81,9 +81,9 @@ object EmptyKSuite: given EmptyK[BoxColor] = semiauto.emptyK object derivedInstances: - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives EmptyK - case class IList[A](x: TestDefns.IList[A]) derives EmptyK - case class Snoc[A](x: TestDefns.Snoc[A]) derives EmptyK + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives EmptyK + case class IList[A](x: ADTs.IList[A]) derives EmptyK + case class Snoc[A](x: ADTs.Snoc[A]) derives EmptyK final case class Color[A](r: Int, g: Int, b: Int) object Color: diff --git a/core/src/test/scala-3/cats/derived/EmptySuite.scala b/core/src/test/scala-3/cats/derived/EmptySuite.scala index c8966a75..46040a34 100644 --- a/core/src/test/scala-3/cats/derived/EmptySuite.scala +++ b/core/src/test/scala-3/cats/derived/EmptySuite.scala @@ -23,7 +23,7 @@ import scala.compiletime.* class EmptySuite extends KittensSuite: import EmptySuite.given import EmptySuite.* - import TestDefns.* + import ADTs.* inline def empty[A]: A = summonInline[Empty[A]].empty @@ -57,10 +57,10 @@ class EmptySuite extends KittensSuite: locally { import derivedInstances.* val instance = "derived.empty" - test(s"$instance[Foo]")(assert(empty[Foo].x == TestDefns.Foo(0, None))) - test(s"$instance[Outer]")(assert(empty[Outer].x == TestDefns.Outer(Inner(0)))) - test(s"$instance[Interleaved[String]]")(assert(empty[Interleaved[String]].x == TestDefns.Interleaved.empty(""))) - test(s"$instance[Recursive]")(assert(empty[Recursive].x == TestDefns.Recursive(0, None))) + test(s"$instance[Foo]")(assert(empty[Foo].x == ADTs.Foo(0, None))) + test(s"$instance[Outer]")(assert(empty[Outer].x == ADTs.Outer(Inner(0)))) + test(s"$instance[Interleaved[String]]")(assert(empty[Interleaved[String]].x == ADTs.Interleaved.empty(""))) + test(s"$instance[Recursive]")(assert(empty[Recursive].x == ADTs.Recursive(0, None))) test(s"$instance[IList[Dummy]]")(assert(empty[IList[Int]].x == INil())) test(s"$instance[Snoc[Dummy]]")(assert(empty[Snoc[Int]].x == SNil())) test(s"$instance respects existing instances")(assert(empty[BoxMask].x == Box(Mask(0xffffffff)))) @@ -70,7 +70,7 @@ class EmptySuite extends KittensSuite: end EmptySuite object EmptySuite: - import TestDefns.* + import ADTs.* // `Monoid[Option[A]]` gives us `Empty[Option[A]]` but it requires a `Semigroup[A]`. given [A]: Empty[Option[A]] = Empty(None) @@ -86,12 +86,12 @@ object EmptySuite: given Empty[Chain] = semiauto.empty object derivedInstances: - case class Foo(x: TestDefns.Foo) derives Empty - case class Outer(x: TestDefns.Outer) derives Empty - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Empty - case class Recursive(x: TestDefns.Recursive) derives Empty - case class IList[A](x: TestDefns.IList[A]) derives Empty - case class Snoc[A](x: TestDefns.Snoc[A]) derives Empty + case class Foo(x: ADTs.Foo) derives Empty + case class Outer(x: ADTs.Outer) derives Empty + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Empty + case class Recursive(x: ADTs.Recursive) derives Empty + case class IList[A](x: ADTs.IList[A]) derives Empty + case class Snoc[A](x: ADTs.Snoc[A]) derives Empty case class BoxMask(x: Box[Mask]) derives Empty trait Dummy diff --git a/core/src/test/scala-3/cats/derived/EqSuite.scala b/core/src/test/scala-3/cats/derived/EqSuite.scala index 9f7a01b3..bce4a3ee 100644 --- a/core/src/test/scala-3/cats/derived/EqSuite.scala +++ b/core/src/test/scala-3/cats/derived/EqSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class EqSuite extends KittensSuite.WithoutEq: import EqSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: EqTests[A] = EqTests[A](summonInline) @@ -63,7 +63,7 @@ class EqSuite extends KittensSuite.WithoutEq: end EqSuite object EqSuite: - import TestDefns.* + import ADTs.* object semiInstances: given Eq[Foo] = semiauto.eq @@ -75,12 +75,12 @@ object EqSuite: given Eq[Recursive] = semiauto.eq object derivedInstances: - case class Foo(x: TestDefns.Foo) derives Eq - case class IList[A](x: TestDefns.IList[A]) derives Eq - case class Inner(x: TestDefns.Inner) derives Eq - case class Outer(x: TestDefns.Outer) derives Eq - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Eq - case class Tree[A](x: TestDefns.Tree[A]) derives Eq - case class Recursive(x: TestDefns.Recursive) derives Eq + case class Foo(x: ADTs.Foo) derives Eq + case class IList[A](x: ADTs.IList[A]) derives Eq + case class Inner(x: ADTs.Inner) derives Eq + case class Outer(x: ADTs.Outer) derives Eq + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Eq + case class Tree[A](x: ADTs.Tree[A]) derives Eq + case class Recursive(x: ADTs.Recursive) derives Eq end EqSuite diff --git a/core/src/test/scala-3/cats/derived/FoldableSuite.scala b/core/src/test/scala-3/cats/derived/FoldableSuite.scala index 528a005c..7bef2b80 100644 --- a/core/src/test/scala-3/cats/derived/FoldableSuite.scala +++ b/core/src/test/scala-3/cats/derived/FoldableSuite.scala @@ -18,12 +18,12 @@ package cats.derived import cats.{Eval, Foldable} import cats.laws.discipline.* -import cats.syntax.all.* +import cats.syntax.all.given import scala.compiletime.* class FoldableSuite extends KittensSuite: import FoldableSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: FoldableTests[F] = FoldableTests[F](summonInline) @@ -71,7 +71,7 @@ class FoldableSuite extends KittensSuite: end FoldableSuite object FoldableSuite: - import TestDefns.* + import ADTs.* type OptList[A] = Option[List[A]] type ListSnoc[A] = List[Snoc[A]] @@ -93,15 +93,15 @@ object FoldableSuite: given Foldable[AtLeastOne] = semiauto.foldable object derivedInstances: - case class IList[A](x: TestDefns.IList[A]) derives Foldable - case class Tree[A](x: TestDefns.Tree[A]) derives Foldable - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Foldable - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Foldable - case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Foldable + case class IList[A](x: ADTs.IList[A]) derives Foldable + case class Tree[A](x: ADTs.Tree[A]) derives Foldable + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives Foldable + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Foldable + case class EnumK1[A](x: ADTs.EnumK1[A]) derives Foldable case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Foldable - case class Many[+A](x: TestDefns.Many[A]) derives Foldable - case class AtMostOne[+A](x: TestDefns.AtMostOne[A]) derives Foldable - case class AtLeastOne[+A](x: TestDefns.AtLeastOne[A]) derives Foldable + case class Many[+A](x: ADTs.Many[A]) derives Foldable + case class AtMostOne[+A](x: ADTs.AtMostOne[A]) derives Foldable + case class AtLeastOne[+A](x: ADTs.AtLeastOne[A]) derives Foldable final case class Nel[+A](head: A, tail: List[A]) object Nel: diff --git a/core/src/test/scala-3/cats/derived/FunctorSuite.scala b/core/src/test/scala-3/cats/derived/FunctorSuite.scala index a45e9862..b13f7159 100644 --- a/core/src/test/scala-3/cats/derived/FunctorSuite.scala +++ b/core/src/test/scala-3/cats/derived/FunctorSuite.scala @@ -23,7 +23,7 @@ import scala.compiletime.* class FunctorSuite extends KittensSuite: import FunctorSuite.* - import TestDefns.* + import ADTs.* given ExhaustiveCheck[Predicate[Boolean]] = ExhaustiveCheck.instance(List(_ => true, _ => false, identity, !_)) @@ -74,7 +74,7 @@ class FunctorSuite extends KittensSuite: end FunctorSuite object FunctorSuite: - import TestDefns.* + import ADTs.* type OptList[A] = Option[List[A]] type ListSnoc[A] = List[Snoc[A]] @@ -97,14 +97,14 @@ object FunctorSuite: given Functor[AtLeastOne] = semiauto.functor object derivedInstances: - case class IList[A](x: TestDefns.IList[A]) derives Functor - case class Tree[A](x: TestDefns.Tree[A]) derives Functor - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Functor - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Functor - case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Functor + case class IList[A](x: ADTs.IList[A]) derives Functor + case class Tree[A](x: ADTs.Tree[A]) derives Functor + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives Functor + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Functor + case class EnumK1[A](x: ADTs.EnumK1[A]) derives Functor case class AndChar[A](x: FoldableSuite.AndChar[A]) derives Functor - case class Many[+A](x: TestDefns.Many[A]) derives Functor - case class AtMostOne[+A](x: TestDefns.AtMostOne[A]) derives Functor - case class AtLeastOne[+A](x: TestDefns.AtLeastOne[A]) derives Functor + case class Many[+A](x: ADTs.Many[A]) derives Functor + case class AtMostOne[+A](x: ADTs.AtMostOne[A]) derives Functor + case class AtLeastOne[+A](x: ADTs.AtLeastOne[A]) derives Functor end FunctorSuite diff --git a/core/src/test/scala-3/cats/derived/HashSuite.scala b/core/src/test/scala-3/cats/derived/HashSuite.scala index ad81a28e..87a88f76 100644 --- a/core/src/test/scala-3/cats/derived/HashSuite.scala +++ b/core/src/test/scala-3/cats/derived/HashSuite.scala @@ -7,7 +7,7 @@ import scala.util.hashing.MurmurHash3 class HashSuite extends KittensSuite: import HashSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: HashTests[A] = HashTests[A](summonInline) @@ -50,7 +50,7 @@ class HashSuite extends KittensSuite: end HashSuite object HashSuite: - import TestDefns.* + import ADTs.* object semiInstances: given Hash[IList[Int]] = semiauto.hash @@ -62,12 +62,12 @@ object HashSuite: given Hash[EnumK0] = semiauto.hash object derivedInstances: - case class IList[A](x: TestDefns.IList[A]) derives Hash - case class Inner(x: TestDefns.Inner) derives Hash - case class Outer(x: TestDefns.Outer) derives Hash - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Hash - case class Tree[A](x: TestDefns.Tree[A]) derives Hash - case class Recursive(x: TestDefns.Recursive) derives Hash - case class EnumK0(x: TestDefns.EnumK0) derives Hash + case class IList[A](x: ADTs.IList[A]) derives Hash + case class Inner(x: ADTs.Inner) derives Hash + case class Outer(x: ADTs.Outer) derives Hash + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Hash + case class Tree[A](x: ADTs.Tree[A]) derives Hash + case class Recursive(x: ADTs.Recursive) derives Hash + case class EnumK0(x: ADTs.EnumK0) derives Hash end HashSuite diff --git a/core/src/test/scala-3/cats/derived/InvariantSuite.scala b/core/src/test/scala-3/cats/derived/InvariantSuite.scala index e4abab12..c89d202d 100644 --- a/core/src/test/scala-3/cats/derived/InvariantSuite.scala +++ b/core/src/test/scala-3/cats/derived/InvariantSuite.scala @@ -24,7 +24,7 @@ import scala.compiletime.* class InvariantSuite extends KittensSuite: import InvariantSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: InvariantTests[F] = InvariantTests[F](summonInline) @@ -69,7 +69,7 @@ class InvariantSuite extends KittensSuite: end InvariantSuite object InvariantSuite: - import TestDefns.* + import ADTs.* type ListSnoc[A] = List[Snoc[A]] type GenericAdtF[A] = GenericAdt[A => Boolean] @@ -95,11 +95,11 @@ object InvariantSuite: given Invariant[AtLeastOne] = semiauto.invariant object derivedInstances: - case class Bivariant[A](x: TestDefns.Bivariant[A]) derives Invariant - case class IList[A](x: TestDefns.IList[A]) derives Invariant - case class EnumK1Inv[A](x: TestDefns.EnumK1Inv[A]) derives Invariant - case class Many[A](x: TestDefns.Many[A]) derives Invariant - case class AtMostOne[A](x: TestDefns.AtMostOne[A]) derives Invariant - case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Invariant + case class Bivariant[A](x: ADTs.Bivariant[A]) derives Invariant + case class IList[A](x: ADTs.IList[A]) derives Invariant + case class EnumK1Inv[A](x: ADTs.EnumK1Inv[A]) derives Invariant + case class Many[A](x: ADTs.Many[A]) derives Invariant + case class AtMostOne[A](x: ADTs.AtMostOne[A]) derives Invariant + case class AtLeastOne[A](x: ADTs.AtLeastOne[A]) derives Invariant end InvariantSuite diff --git a/core/src/test/scala-3/cats/derived/KittensSuite.scala b/core/src/test/scala-3/cats/derived/KittensSuite.scala index 922c2b3f..526b7139 100644 --- a/core/src/test/scala-3/cats/derived/KittensSuite.scala +++ b/core/src/test/scala-3/cats/derived/KittensSuite.scala @@ -29,7 +29,7 @@ import scala.quoted.* /** An opinionated stack of traits to improve consistency and reduce boilerplate in Kittens tests. Note that unlike the * corresponding CatsSuite in the Cat project, this trait does not mix in any instances. */ -abstract class KittensSuite extends KittensSuite.WithoutEq, TestEqInstances: +abstract class KittensSuite extends KittensSuite.WithoutEq, ADTs.EqInstances: given [A <: Product](using mirror: Mirror.ProductOf[A], via: Eq[mirror.MirroredElemTypes]): Eq[A] = Eq.by(Tuple.fromProductTyped) diff --git a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala index 3ff5692f..d85b884b 100644 --- a/core/src/test/scala-3/cats/derived/MonoidKSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidKSuite.scala @@ -6,7 +6,7 @@ import scala.compiletime.* class MonoidKSuite extends KittensSuite: import MonoidKSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: MonoidKTests[F] = MonoidKTests[F](summonInline) @@ -44,7 +44,7 @@ class MonoidKSuite extends KittensSuite: end MonoidKSuite object MonoidKSuite: - import TestDefns.* + import ADTs.* type BoxMul[A] = Box[Mul[A]] @@ -54,8 +54,8 @@ object MonoidKSuite: given MonoidK[BoxMul] = semiauto.monoidK object derivedInstances: - case class ComplexProduct[A](x: TestDefns.ComplexProduct[A]) derives MonoidK - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives MonoidK + case class ComplexProduct[A](x: ADTs.ComplexProduct[A]) derives MonoidK + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives MonoidK case class Simple[A](value1: List[A], value2: Set[A]) derives MonoidK case class Recursive[A](first: List[A], rest: Recursive[A]) derives MonoidK diff --git a/core/src/test/scala-3/cats/derived/MonoidSuite.scala b/core/src/test/scala-3/cats/derived/MonoidSuite.scala index f6324d64..3651cb82 100644 --- a/core/src/test/scala-3/cats/derived/MonoidSuite.scala +++ b/core/src/test/scala-3/cats/derived/MonoidSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class MonoidSuite extends KittensSuite: import MonoidSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: MonoidTests[A] = MonoidTests[A](summonInline) @@ -61,7 +61,7 @@ class MonoidSuite extends KittensSuite: end MonoidSuite object MonoidSuite: - import TestDefns.* + import ADTs.* object semiInstances: given Monoid[Foo] = semiauto.monoid @@ -70,8 +70,8 @@ object MonoidSuite: given Monoid[Box[Mul]] = semiauto.monoid object derivedInstances: - case class Foo(x: TestDefns.Foo) derives Monoid - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Monoid + case class Foo(x: ADTs.Foo) derives Monoid + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Monoid case class BoxMul(x: Box[Mul]) derives Monoid final case class Mul(value: Int) diff --git a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala index 1d0fdc74..8c8097b2 100644 --- a/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/NonEmptyTraverseSuite.scala @@ -20,12 +20,12 @@ import cats.{Eq, NonEmptyTraverse} import cats.data.{NonEmptyList, NonEmptyVector, OneAnd} import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* -import cats.syntax.all.* +import cats.syntax.all.given import scala.compiletime.* class NonEmptyTraverseSuite extends KittensSuite: import NonEmptyTraverseSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: NonEmptyTraverseTests[F] = NonEmptyTraverseTests[F](summonInline) @@ -107,7 +107,7 @@ class NonEmptyTraverseSuite extends KittensSuite: end NonEmptyTraverseSuite object NonEmptyTraverseSuite: - import TestDefns.* + import ADTs.* type NelSCons[A] = NonEmptyList[SCons[A]] type NelAndOne[A] = NonEmptyList[OneAnd[Vector, A]] @@ -124,10 +124,10 @@ object NonEmptyTraverseSuite: given NonEmptyTraverse[AtLeastOne] = semiauto.nonEmptyTraverse object derivedInstances: - case class ICons[A](x: TestDefns.ICons[A]) derives NonEmptyTraverse - case class Tree[A](x: TestDefns.Tree[A]) derives NonEmptyTraverse - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives NonEmptyTraverse - case class EnumK1[A](x: TestDefns.EnumK1[A]) derives NonEmptyTraverse - case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives NonEmptyTraverse + case class ICons[A](x: ADTs.ICons[A]) derives NonEmptyTraverse + case class Tree[A](x: ADTs.Tree[A]) derives NonEmptyTraverse + case class Interleaved[A](x: ADTs.Interleaved[A]) derives NonEmptyTraverse + case class EnumK1[A](x: ADTs.EnumK1[A]) derives NonEmptyTraverse + case class AtLeastOne[A](x: ADTs.AtLeastOne[A]) derives NonEmptyTraverse end NonEmptyTraverseSuite diff --git a/core/src/test/scala-3/cats/derived/OrderSuite.scala b/core/src/test/scala-3/cats/derived/OrderSuite.scala index 14a29a3f..657bdeb8 100644 --- a/core/src/test/scala-3/cats/derived/OrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/OrderSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class OrderSuite extends KittensSuite: import OrderSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: OrderTests[A] = OrderTests[A](summonInline) @@ -61,7 +61,7 @@ class OrderSuite extends KittensSuite: end OrderSuite object OrderSuite: - import TestDefns.* + import ADTs.* object semiInstances: given Order[Inner] = semiauto.order @@ -72,11 +72,11 @@ object OrderSuite: given Order[EnumK0] = semiauto.order object derivedInstances: - case class Inner(x: TestDefns.Inner) derives Order - case class Outer(x: TestDefns.Outer) derives Order - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Order - case class Recursive(x: TestDefns.Recursive) derives Order - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Order - case class EnumK0(x: TestDefns.EnumK0) derives Order + case class Inner(x: ADTs.Inner) derives Order + case class Outer(x: ADTs.Outer) derives Order + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Order + case class Recursive(x: ADTs.Recursive) derives Order + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives Order + case class EnumK0(x: ADTs.EnumK0) derives Order end OrderSuite diff --git a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala index b25286ee..335367f6 100644 --- a/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala +++ b/core/src/test/scala-3/cats/derived/PartialOrderSuite.scala @@ -22,7 +22,7 @@ import scala.compiletime.* class PartialOrderSuite extends KittensSuite: import PartialOrderSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: PartialOrderTests[A] = PartialOrderTests[A](summonInline) @@ -73,7 +73,7 @@ class PartialOrderSuite extends KittensSuite: end PartialOrderSuite object PartialOrderSuite: - import TestDefns.* + import ADTs.* object semiInstances: given PartialOrder[IList[Int]] = semiauto.partialOrder @@ -86,13 +86,13 @@ object PartialOrderSuite: given PartialOrder[EnumK0] = semiauto.partialOrder object derivedInstances: - case class IList[A](x: TestDefns.IList[A]) derives PartialOrder - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives PartialOrder - case class Tree[A](x: TestDefns.Tree[A]) derives PartialOrder - case class Inner(x: TestDefns.Inner) derives PartialOrder - case class Outer(x: TestDefns.Outer) derives PartialOrder - case class Recursive(x: TestDefns.Recursive) derives PartialOrder - case class EnumK0(x: TestDefns.EnumK0) derives PartialOrder + case class IList[A](x: ADTs.IList[A]) derives PartialOrder + case class Interleaved[A](x: ADTs.Interleaved[A]) derives PartialOrder + case class Tree[A](x: ADTs.Tree[A]) derives PartialOrder + case class Inner(x: ADTs.Inner) derives PartialOrder + case class Outer(x: ADTs.Outer) derives PartialOrder + case class Recursive(x: ADTs.Recursive) derives PartialOrder + case class EnumK0(x: ADTs.EnumK0) derives PartialOrder case class BoxKV(x: Box[KeyValue]) derives PartialOrder final case class KeyValue(key: String, value: Int) diff --git a/core/src/test/scala-3/cats/derived/PureSuite.scala b/core/src/test/scala-3/cats/derived/PureSuite.scala index 72fd7e59..ea45a8e0 100644 --- a/core/src/test/scala-3/cats/derived/PureSuite.scala +++ b/core/src/test/scala-3/cats/derived/PureSuite.scala @@ -23,7 +23,7 @@ import scala.compiletime.* class PureSuite extends KittensSuite: import PureSuite.* - import TestDefns.* + import ADTs.* extension [A](a: A) inline def pure[F[_]] = @@ -57,17 +57,17 @@ class PureSuite extends KittensSuite: val instance = "derived.pure" checkAll(s"$instance is Serializable", SerializableTests.serializable(Pure[Interleaved])) test(s"$instance[CaseClassWOption]")( - assert(3.14.pure[CaseClassWOption].x == TestDefns.CaseClassWOption(Some(3.14))) + assert(3.14.pure[CaseClassWOption].x == ADTs.CaseClassWOption(Some(3.14))) ) test(s"$instance[Interleaved]")( - assert('x'.pure[Interleaved].x == TestDefns.Interleaved(0, 'x', 0, Vector('x'), "")) + assert('x'.pure[Interleaved].x == ADTs.Interleaved(0, 'x', 0, Vector('x'), "")) ) } end PureSuite object PureSuite: - import TestDefns.* + import ADTs.* type LOption[A] = List[Option[A]] type PList[A] = (List[A], List[A]) @@ -83,8 +83,8 @@ object PureSuite: given Pure[BoxColor] = semiauto.pure object derivedInstances: - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives Pure - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Pure + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives Pure + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Pure final case class Color[A](r: Int, g: Int, b: Int) object Color: diff --git a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala index 582e20d0..c30ab3f0 100644 --- a/core/src/test/scala-3/cats/derived/ReducibleSuite.scala +++ b/core/src/test/scala-3/cats/derived/ReducibleSuite.scala @@ -20,12 +20,12 @@ import cats.{Eval, Reducible} import cats.data.{NonEmptyList, OneAnd} import cats.laws.discipline.* import cats.laws.discipline.arbitrary.* -import cats.syntax.all.* +import cats.syntax.all.given import scala.compiletime.* class ReducibleSuite extends KittensSuite: import ReducibleSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: ReducibleTests[F] = ReducibleTests[F](summonInline) @@ -66,7 +66,7 @@ class ReducibleSuite extends KittensSuite: end ReducibleSuite object ReducibleSuite: - import TestDefns.* + import ADTs.* type NelSCons[A] = NonEmptyList[SCons[A]] type NelAndOne[A] = NonEmptyList[OneAnd[Vector, A]] @@ -85,11 +85,11 @@ object ReducibleSuite: given Reducible[AtLeastOne] = semiauto.reducible object derivedInstances: - case class ICons[A](x: TestDefns.ICons[A]) derives Reducible - case class Tree[A](x: TestDefns.Tree[A]) derives Reducible - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Reducible - case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Reducible - case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Reducible + case class ICons[A](x: ADTs.ICons[A]) derives Reducible + case class Tree[A](x: ADTs.Tree[A]) derives Reducible + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Reducible + case class EnumK1[A](x: ADTs.EnumK1[A]) derives Reducible + case class AtLeastOne[A](x: ADTs.AtLeastOne[A]) derives Reducible final case class Zipper[+A](left: List[A], focus: A, right: List[A]) object Zipper: diff --git a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala index 5c2743cb..edf3c13a 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupKSuite.scala @@ -6,7 +6,7 @@ import scala.compiletime.* class SemigroupKSuite extends KittensSuite: import SemigroupKSuite.* - import TestDefns.* + import ADTs.* inline def tests[F[_]]: SemigroupKTests[F] = SemigroupKTests[F](summonInline) @@ -42,7 +42,7 @@ class SemigroupKSuite extends KittensSuite: end SemigroupKSuite object SemigroupKSuite: - import TestDefns.* + import ADTs.* type BoxMul[A] = Box[Mul[A]] @@ -52,8 +52,8 @@ object SemigroupKSuite: given SemigroupK[BoxMul] = semiauto.semigroupK object derivedInstances: - case class ComplexProduct[A](x: TestDefns.ComplexProduct[A]) derives SemigroupK - case class CaseClassWOption[A](x: TestDefns.CaseClassWOption[A]) derives SemigroupK + case class ComplexProduct[A](x: ADTs.ComplexProduct[A]) derives SemigroupK + case class CaseClassWOption[A](x: ADTs.CaseClassWOption[A]) derives SemigroupK case class Simple[A](value1: List[A], value2: Set[A]) derives SemigroupK case class Recursive[A](first: List[A], rest: Recursive[A]) derives SemigroupK diff --git a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala index 581192a5..c11b75b1 100644 --- a/core/src/test/scala-3/cats/derived/SemigroupSuite.scala +++ b/core/src/test/scala-3/cats/derived/SemigroupSuite.scala @@ -24,7 +24,7 @@ import scala.compiletime.* class SemigroupSuite extends KittensSuite: import SemigroupSuite.* - import TestDefns.* + import ADTs.* inline def tests[A]: SemigroupTests[A] = SemigroupTests[A](summonInline) @@ -62,7 +62,7 @@ class SemigroupSuite extends KittensSuite: end SemigroupSuite object SemigroupSuite: - import TestDefns.* + import ADTs.* object semiInstances: given Semigroup[Foo] = semiauto.semigroup @@ -71,8 +71,8 @@ object SemigroupSuite: given Semigroup[Box[Mul]] = semiauto.semigroup object derivedInstances: - case class Foo(x: TestDefns.Foo) derives Semigroup - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Semigroup + case class Foo(x: ADTs.Foo) derives Semigroup + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Semigroup case class BoxMul(x: Box[Mul]) derives Semigroup final case class Mul(value: Int) diff --git a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala index 5ab2c556..69c319e7 100644 --- a/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala +++ b/core/src/test/scala-3/cats/derived/ShowPrettySuite.scala @@ -5,9 +5,9 @@ import cats.laws.discipline.SerializableTests import scala.compiletime.* class ShowPrettySuite extends KittensSuite: - import ShowPrettySuite.* import ShowPrettySuite.given - import TestDefns.* + import ShowPrettySuite.* + import ADTs.* inline def show[A](value: A): String = summonInline[ShowPretty[A]].show(value) @@ -173,7 +173,7 @@ class ShowPrettySuite extends KittensSuite: end ShowPrettySuite object ShowPrettySuite: - import TestDefns.* + import ADTs.* given Show[Address] = Show.show(a => List(a.street, a.city, a.state).mkString(" ")) @@ -195,15 +195,15 @@ object ShowPrettySuite: given ShowPretty[Box[Bogus]] = semiauto.showPretty object derivedInstances: - case class Foo(x: TestDefns.Foo) derives ShowPretty - case class Outer(x: TestDefns.Outer) derives ShowPretty - case class IntTree(x: TestDefns.IntTree) derives ShowPretty - case class People(x: TestDefns.People) derives ShowPretty - case class ListFieldChild(x: TestDefns.ListFieldChild) derives ShowPretty - case class ListField(x: TestDefns.ListField) derives ShowPretty - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives ShowPretty - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives ShowPretty - case class Tree[A](x: TestDefns.Tree[A]) derives ShowPretty + case class Foo(x: ADTs.Foo) derives ShowPretty + case class Outer(x: ADTs.Outer) derives ShowPretty + case class IntTree(x: ADTs.IntTree) derives ShowPretty + case class People(x: ADTs.People) derives ShowPretty + case class ListFieldChild(x: ADTs.ListFieldChild) derives ShowPretty + case class ListField(x: ADTs.ListField) derives ShowPretty + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives ShowPretty + case class Interleaved[A](x: ADTs.Interleaved[A]) derives ShowPretty + case class Tree[A](x: ADTs.Tree[A]) derives ShowPretty case class BoxBogus(x: Box[Bogus]) derives ShowPretty end ShowPrettySuite diff --git a/core/src/test/scala-3/cats/derived/ShowSuite.scala b/core/src/test/scala-3/cats/derived/ShowSuite.scala index 4fc36c10..b695fba3 100644 --- a/core/src/test/scala-3/cats/derived/ShowSuite.scala +++ b/core/src/test/scala-3/cats/derived/ShowSuite.scala @@ -7,7 +7,7 @@ import scala.compiletime.* class ShowSuite extends KittensSuite: import ShowSuite.given import ShowSuite.* - import TestDefns.* + import ADTs.* inline def show[A](value: A): String = summonInline[Show[A]].show(value) @@ -94,7 +94,7 @@ class ShowSuite extends KittensSuite: end ShowSuite object ShowSuite: - import TestDefns.* + import ADTs.* given Show[Address] = Show.show(a => List(a.street, a.city, a.state).mkString(" ")) @@ -117,16 +117,16 @@ object ShowSuite: given Show[EnumK0] = semiauto.show object derivedInstances: - case class Foo(x: TestDefns.Foo) derives Show - case class Outer(x: TestDefns.Outer) derives Show - case class IntTree(x: TestDefns.IntTree) derives Show - case class People(x: TestDefns.People) derives Show - case class ListFieldChild(x: TestDefns.ListFieldChild) derives Show - case class ListField(x: TestDefns.ListField) derives Show - case class EnumK0(x: TestDefns.EnumK0) derives Show - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Show - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Show - case class Tree[A](x: TestDefns.Tree[A]) derives Show + case class Foo(x: ADTs.Foo) derives Show + case class Outer(x: ADTs.Outer) derives Show + case class IntTree(x: ADTs.IntTree) derives Show + case class People(x: ADTs.People) derives Show + case class ListFieldChild(x: ADTs.ListFieldChild) derives Show + case class ListField(x: ADTs.ListField) derives Show + case class EnumK0(x: ADTs.EnumK0) derives Show + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives Show + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Show + case class Tree[A](x: ADTs.Tree[A]) derives Show case class BoxBogus(x: Box[Bogus]) derives Show end ShowSuite diff --git a/core/src/test/scala-3/cats/derived/TraverseSuite.scala b/core/src/test/scala-3/cats/derived/TraverseSuite.scala index b0254b8e..7b4c9f16 100644 --- a/core/src/test/scala-3/cats/derived/TraverseSuite.scala +++ b/core/src/test/scala-3/cats/derived/TraverseSuite.scala @@ -5,7 +5,7 @@ import cats.laws.discipline.* import scala.compiletime.* class TraverseSuite extends KittensSuite: - import TestDefns.* + import ADTs.* import TraverseSuite.* inline def tests[F[_]]: TraverseTests[F] = @@ -52,7 +52,7 @@ class TraverseSuite extends KittensSuite: end TraverseSuite object TraverseSuite: - import TestDefns.* + import ADTs.* type OptList[A] = Option[List[A]] type ListSnoc[A] = List[Snoc[A]] @@ -72,13 +72,13 @@ object TraverseSuite: given Traverse[AtMostOne] = semiauto.traverse object derivedInstances: - case class IList[A](x: TestDefns.IList[A]) derives Traverse - case class Tree[A](x: TestDefns.Tree[A]) derives Traverse - case class GenericAdt[A](x: TestDefns.GenericAdt[A]) derives Traverse - case class Interleaved[A](x: TestDefns.Interleaved[A]) derives Traverse - case class EnumK1[A](x: TestDefns.EnumK1[A]) derives Traverse - case class Many[A](x: TestDefns.Many[A]) derives Traverse - case class AtMostOne[A](x: TestDefns.AtMostOne[A]) derives Traverse - case class AtLeastOne[A](x: TestDefns.AtLeastOne[A]) derives Traverse + case class IList[A](x: ADTs.IList[A]) derives Traverse + case class Tree[A](x: ADTs.Tree[A]) derives Traverse + case class GenericAdt[A](x: ADTs.GenericAdt[A]) derives Traverse + case class Interleaved[A](x: ADTs.Interleaved[A]) derives Traverse + case class EnumK1[A](x: ADTs.EnumK1[A]) derives Traverse + case class Many[A](x: ADTs.Many[A]) derives Traverse + case class AtMostOne[A](x: ADTs.AtMostOne[A]) derives Traverse + case class AtLeastOne[A](x: ADTs.AtLeastOne[A]) derives Traverse end TraverseSuite From 79d9e2234c50ec40e4da753f5323116cea143f1c Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Tue, 13 Sep 2022 12:50:39 +0200 Subject: [PATCH 29/29] Simplify DerivedShowPretty --- .../cats/derived/DerivedShowPretty.scala | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/core/src/main/scala-3/cats/derived/DerivedShowPretty.scala b/core/src/main/scala-3/cats/derived/DerivedShowPretty.scala index e93ba93a..195e9b2b 100644 --- a/core/src/main/scala-3/cats/derived/DerivedShowPretty.scala +++ b/core/src/main/scala-3/cats/derived/DerivedShowPretty.scala @@ -21,14 +21,11 @@ Make sure that A satisfies one of the following conditions: type DerivedShowPretty[A] = Derived[ShowPretty[A]] object DerivedShowPretty: opaque type Or[A] = A => List[String] - object Or extends OrInstances: - def apply[A](instance: A => List[String]): Or[A] = instance + object Or: extension [A](or: Or[A]) def apply(a: A): List[String] = or(a) - - sealed abstract class OrInstances: inline given [A]: Or[A] = summonFrom { - case instance: Show[A] => Or((a: A) => instance.show(a).split(System.lineSeparator).toList) - case derived: DerivedShowPretty[A] => Or(derived.instance.showLines(_)) + case instance: Show[A] => instance.show(_).split(System.lineSeparator).toList + case derived: DerivedShowPretty[A] => derived.instance.showLines(_) } inline def apply[A]: ShowPretty[A] = @@ -48,23 +45,18 @@ object DerivedShowPretty: val n = labels.size if n <= 0 then List(s"$prefix()") else - var lines: List[String] = List(")") - val inner = inst.project(a)(n - 1)([t] => (show: Or[t], x: t) => show.apply(x)) - inner match - case Nil => lines = s" ${labels(n - 1)} = \"\"," :: lines - case h :: t => lines = s" ${labels(n - 1)} = $h" :: t.map(s => " " + s) ::: lines + var lines = List(")") + inst.project(a)(n - 1)([t] => (show: Or[t], x: t) => show.apply(x)) match + case Nil => lines ::= s" ${labels(n - 1)} = \"\"," + case h :: t => lines :::= s" ${labels(n - 1)} = $h" :: t.map(s => " " + s) var i = n - 2 while i >= 0 do - val inner = inst.project(a)(i)([t] => (show: Or[t], x: t) => show.apply(x)) - inner match - case Nil => lines = s" ${labels(i)} = \"\"," :: lines - case v :: Nil => lines = s" ${labels(i)} = $v," :: lines + inst.project(a)(i)([t] => (show: Or[t], x: t) => show.apply(x)) match + case Nil => lines ::= s" ${labels(i)} = \"\"," + case v :: Nil => lines ::= s" ${labels(i)} = $v," case h :: t => lines = s" ${labels(i)} = $h" :: t.init.map(s => " " + s) ::: s" ${t.last}," :: lines i -= 1 - - lines = s"$prefix(" :: lines - - lines + s"$prefix(" :: lines trait Coproduct[A](using inst: K0.CoproductInstances[Or, A]) extends ShowPretty[A]: def showLines(a: A): List[String] =