Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a regression test for AnyVal Hash derivation #624

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/test/scala-2/cats/derived/adtdefns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ object TestDefns {
case object Green extends Rgb
case object Blue extends Rgb

final case class AnyValStr(name: String) extends AnyVal
object AnyValStr {
implicit val arbitrary: Arbitrary[AnyValStr] =
Arbitrary(Arbitrary.arbitrary[String].map(apply))
implicit val cogen: Cogen[AnyValStr] =
Cogen[String].contramap(_.name)
}

final case class ComplexProduct[T](lbl: String, set: Set[T], fns: Vector[() => T], opt: Eval[Option[T]])
object ComplexProduct {

Expand Down
7 changes: 5 additions & 2 deletions core/src/test/scala-2/cats/derived/hash.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ class HashSuite extends KittensSuite {
interleaved: Hash[Interleaved[Int]],
tree: Hash[Tree[Int]],
recursive: Hash[Recursive],
singletons: Hash[Singletons[Int]]
singletons: Hash[Singletons[Int]],
anyVal: Hash[AnyValStr]
): 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)
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[Singletons[Int]", HashTests[Singletons[Int]].hash)
checkAll(s"$context.Hash[Singletons[Int]]", HashTests[Singletons[Int]].hash)
checkAll(s"$context.Hash[AnyValStr]", HashTests[AnyValStr].hash)
checkAll(s"$context.Hash is Serializable", SerializableTests.serializable(Hash[Tree[Int]]))
}

Expand Down Expand Up @@ -53,5 +55,6 @@ object HashSuite {
implicit val tree: Hash[Tree[Int]] = semiauto.hash
implicit val recursive: Hash[Recursive] = semiauto.hash
implicit val singletons: Hash[Singletons[Int]] = semiauto.hash
implicit val anyVal: Hash[AnyValStr] = semiauto.hash
}
}