-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from sparsetech/issue/25
Route: Overload functions to take Path instead of String
- Loading branch information
Showing
6 changed files
with
100 additions
and
25 deletions.
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
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,42 @@ | ||
package trail | ||
|
||
import org.scalatest._ | ||
import shapeless._ | ||
|
||
class RouteParseTests extends FunSpec with Matchers { | ||
it("Route can be parsed from Path") { | ||
val userInfo = Root / "user" / Arg[String] / Arg[Boolean] | ||
|
||
val parsed = userInfo.parse(trail.Path("/user/bob/true")) | ||
assert(parsed === Some("bob" :: true :: HNil)) | ||
userInfo.parse(trail.Path("/user/bob")) shouldBe empty | ||
} | ||
|
||
it("Route with query parameters can be parsed from Path") { | ||
val userInfo = Root / "user" / Arg[String] / Arg[Boolean] & Param[Int]("n") | ||
|
||
val parsed = userInfo.parse(trail.Path("/user/bob/true", List("n" -> "42"))) | ||
assert(parsed === Some("bob" :: true :: HNil, 42 :: HNil)) | ||
} | ||
|
||
it("Route can be parsed from string") { | ||
val userInfo = Root / "user" / Arg[String] / Arg[Boolean] | ||
|
||
val parsed = userInfo.parse("/user/bob/true") | ||
parsed shouldBe defined | ||
|
||
assert(parsed === Some("bob" :: true :: HNil)) | ||
|
||
userInfo.parse("/user/bob") shouldBe empty | ||
userInfo.parse("/user/bob/true/true") shouldBe empty | ||
userInfo.parse("/user/bob/1") shouldBe empty | ||
userInfo.parse("/usr/bob/1") shouldBe empty | ||
} | ||
|
||
it("Boolean argument can be parsed") { | ||
val userInfo = Root / "user" / Arg[String] / Arg[Boolean] | ||
|
||
assert(userInfo.parse("/user/hello/false") | ||
.contains("hello" :: false :: HNil)) | ||
} | ||
} |