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

Drop case in Refined #160

Merged
merged 1 commit into from
May 7, 2016
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
10 changes: 9 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ lazy val submoduleJvmSettings = Seq(
Seq(
exclude[DirectMissingMethodProblem ]("eu.timepit.refined.generic.evalValidate"),
exclude[DirectMissingMethodProblem ]("eu.timepit.refined.GenericValidate.evalValidate"),
exclude[ReversedMissingMethodProblem]("eu.timepit.refined.GenericValidate.evalValidate")
exclude[ReversedMissingMethodProblem]("eu.timepit.refined.GenericValidate.evalValidate"),
exclude[MissingTypesProblem]("eu.timepit.refined.api.Refined"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productElement"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productArity"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.canEqual"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.copy"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productIterator"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.productPrefix"),
exclude[DirectMissingMethodProblem]("eu.timepit.refined.api.Refined.apply")
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ package api
* this class can be created with `[[refineV]]` and `[[refineMV]]` which
* verify that the wrapped value satisfies `P`.
*/
final case class Refined[T, P] private (get: T) {
final class Refined[T, P] private (val get: T) extends Serializable {
override def hashCode: Int = get.##
override def equals(that: Any): Boolean = that match {
case that: Refined[_, _] => this.get == that.get
case _ => false
}

override def toString: String =
get.toString
Expand All @@ -20,6 +25,10 @@ object Refined {
*/
def unsafeApply[T, P](t: T): Refined[T, P] =
new Refined(t)

def unapply[T, P](r: Refined[T, P]): Option[T] =
Some(r.get)

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package api
* this class can be created with `[[refineV]]` and `[[refineMV]]` which
* verify that the wrapped value satisfies `P`.
*/
final case class Refined[T, P] private (get: T) extends AnyVal {
final class Refined[T, P] private (val get: T) extends AnyVal with Serializable {

override def toString: String =
get.toString
Expand All @@ -20,4 +20,8 @@ object Refined {
*/
def unsafeApply[T, P](t: T): Refined[T, P] =
new Refined(t)

def unapply[T, P](r: Refined[T, P]): Option[T] =
Some(r.get)

}
26 changes: 26 additions & 0 deletions core/shared/src/test/scala/eu/timepit/refined/RefinedSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.timepit.refined

import eu.timepit.refined.TestUtils.wellTyped
import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.NonEmpty
import org.scalacheck.Properties
import shapeless.test.illTyped

class RefinedSpec extends Properties("Refined") {
type NonEmptyString = String Refined NonEmpty

property("apply") = wellTyped {
illTyped(
""" val x: NonEmptyString = Refined("") """,
"eu.timepit.refined.api.Refined.type does not take parameters"
)
}

property("copy") = wellTyped {
val nonEmptyString1: NonEmptyString = refineMV[NonEmpty]("abc")
illTyped(
""" nonEmptyString1.copy("") """,
"value copy is not a member of RefinedSpec\\.this\\.NonEmptyString"
)
}
}