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 Hash[Method] instance #3439

Merged
merged 1 commit into from May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/src/main/scala/org/http4s/Method.scala
Expand Up @@ -7,7 +7,7 @@
package org.http4s

import cats.implicits._
import cats.{Eq, Show}
import cats.{Eq, Hash, Show}
import org.http4s.Method.Semantics
import org.http4s.parser.Rfc2616BasicRules
import org.http4s.util.{Renderable, Writer}
Expand Down Expand Up @@ -151,6 +151,10 @@ object Method {

private val allByKey: Map[String, Right[Nothing, Method]] = all.map(m => (m.name, Right(m))).toMap

implicit val http4sEqForMethod: Eq[Method] = Eq.fromUniversalEquals
implicit val catsHashForHttp4sMethod: Hash[Method] = Hash.fromUniversalHashCode

@deprecated("Upgraded to hash. Kept for binary compatibility", "0.21.5")
private[Method] val http4sEqForMethod: Eq[Method] = Eq.fromUniversalEquals

implicit val http4sShowForMethod: Show[Method] = Show.fromToString
}
8 changes: 5 additions & 3 deletions tests/src/test/scala/org/http4s/MethodSpec.scala
Expand Up @@ -6,14 +6,18 @@

package org.http4s

import cats.kernel.laws.discipline.EqTests
import cats.Hash
import cats.kernel.laws.discipline._
import java.util.Locale
import org.http4s.parser.Rfc2616BasicRules
import org.scalacheck.Prop.forAll

class MethodSpec extends Http4sSpec {
import Method._

checkAll("Method", HashTests[Method].eqv)
checkAll("Hash[Method]", SerializableTests.serializable(Hash[Method]))

"parses own string rendering to equal value" in {
forAll(genToken) { token =>
fromString(token).map(_.renderString) must beRight(token)
Expand All @@ -34,8 +38,6 @@ class MethodSpec extends Http4sSpec {
}
}

checkAll("Method", EqTests[Method].eqv)

"methods are equal by name" in {
prop { (m: Method) =>
Method.fromString(m.name) must beRight(m)
Expand Down