Skip to content

Commit

Permalink
Add a regression test for AnyVal Hash derivation (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 authored Dec 17, 2023
1 parent 33d4e2b commit 3c154a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
}
}

0 comments on commit 3c154a1

Please sign in to comment.