Skip to content

Commit

Permalink
spec should be very self explanatory'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouyang committed Dec 1, 2018
1 parent cc47ebe commit 1c2ed72
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core/src/test/scala/io/finch/MethodSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,43 @@ class MethodSpec
ScalaFuture.successful(Ok(s"$x$y").toResponse[Text.Plain]) })
}

behavior of "Custom Type Program[_]"

case class Program[A](value: A)

import cats.~>
implicit val conv: Program ~> IO = new (Program ~> IO) {
def apply[A](a: Program[A]): IO[A] = IO(a.value)
}

it should "map Program[Output[_]] value to endpoint" in {
checkValue((i: String) => get(zero) { Program(Ok(i)) })
}

it should "map A => Program[Output[_]] function to endpoint" in {
checkFunction(get(path[Int]) { i: Int => Program(Ok(i)) })
}

it should "map (A, B) => Program[Output[_]] function to endpoint" in {
checkFunction2(get(path[Int] :: path[Int]) { (x: Int, y: Int) =>
Program(Ok(s"$x$y"))
})
}

it should "map Program[Response] value to endpoint" in {
checkValue((i: Response) => get(zero) { Program(i) })
}

it should "map A => Program[Response] function to endpoint" in {
checkFunction(get(path[Int]) { i: Int => Program(Ok(i).toResponse[Text.Plain]) })
}

it should "map (A, B) => Program[Response] function to endpoint" in {
checkFunction2(get(path[Int] :: path[Int]) { (x: Int, y: Int) =>
Program(Ok(s"$x$y").toResponse[Text.Plain])
})
}

private def checkValue[A : Arbitrary](f: A => Endpoint[IO, A]): Unit = {
forAll((input: A) => {
val e = f(input)
Expand Down

0 comments on commit 1c2ed72

Please sign in to comment.