-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50dbc23
commit 1c157dc
Showing
13 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.finch | ||
|
||
sealed trait Segment | ||
|
||
object Segment { | ||
|
||
case class Part(name: String) extends Segment | ||
|
||
case object Wildcard extends Segment | ||
|
||
case object Empty extends Segment | ||
|
||
} | ||
|
||
sealed trait EndpointMetadata | ||
|
||
object EndpointMetadata { | ||
|
||
case class Method(method: com.twitter.finagle.http.Method, a: EndpointMetadata) extends EndpointMetadata | ||
|
||
case class Path(segment: io.finch.Segment) extends EndpointMetadata | ||
|
||
case class Parameter(name: String) extends EndpointMetadata | ||
|
||
case class Parameters(name: String) extends EndpointMetadata | ||
|
||
case class Header(name: String) extends EndpointMetadata | ||
|
||
case class Cookie(name: String) extends EndpointMetadata | ||
|
||
case object Body extends EndpointMetadata | ||
|
||
case class Multipart(name: String) extends EndpointMetadata | ||
|
||
case class Coproduct(a: EndpointMetadata, b: EndpointMetadata) extends EndpointMetadata | ||
|
||
case class Product(a: EndpointMetadata, b: EndpointMetadata) extends EndpointMetadata | ||
|
||
case object Const extends EndpointMetadata | ||
|
||
case object Empty extends EndpointMetadata | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.finch | ||
|
||
import io.finch.syntax.EndpointMapper | ||
|
||
class EndpointMetadataSpec extends FinchSpec { | ||
|
||
behavior of "EndpointMetadata" | ||
|
||
private def interpreter(ms: EndpointMetadata): Endpoint[_] = ms match { | ||
case EndpointMetadata.Method(m, meta) => new EndpointMapper(m, interpreter(meta)) | ||
case EndpointMetadata.Path(s) => s match { | ||
case Segment.Part(part) => path(part) | ||
case Segment.Wildcard => * | ||
case Segment.Empty => / | ||
} | ||
case EndpointMetadata.Multipart(name) => multipartAttribute(name) | ||
case EndpointMetadata.Cookie(name) => cookie(name) | ||
case EndpointMetadata.Parameter(name) => param(name) | ||
case EndpointMetadata.Parameters(name) => params(name) | ||
case EndpointMetadata.Header(name) => header(name) | ||
case EndpointMetadata.Body => stringBody | ||
case EndpointMetadata.Empty => Endpoint.empty[String] | ||
case EndpointMetadata.Const => Endpoint.const("foo") | ||
case EndpointMetadata.Coproduct(a, b) => interpreter(b) :+: interpreter(a) | ||
case EndpointMetadata.Product(a, b) => interpreter(a) :: interpreter(b) | ||
} | ||
|
||
it should "do a round-trip" in { | ||
check { l: EndpointMetadata => | ||
interpreter(l).meta === l | ||
} | ||
} | ||
} |
Oops, something went wrong.