Skip to content

Commit

Permalink
Merge pull request #3439 from rossabaker/method-hash
Browse files Browse the repository at this point in the history
Add Hash[Method] instance
  • Loading branch information
aeons committed May 19, 2020
2 parents 5a98a86 + 38443ad commit 6bd072a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit 6bd072a

Please sign in to comment.