Skip to content

Commit

Permalink
use route-recognizer 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jun 19, 2020
1 parent d88828d commit 6a40a9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ async-std = { version = "1.6.0", features = ["unstable"] }
femme = "2.0.1"
http-types = "2.0.1"
kv-log-macro = "1.0.4"
route-recognizer = "0.1.13"
serde = "1.0.102"
serde_json = "1.0.41"
route-recognizer = "0.2.0"

[dev-dependencies]
async-std = { version = "1.6.0", features = ["unstable", "attributes"] }
Expand Down
31 changes: 20 additions & 11 deletions tests/wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ async fn echo_path(req: Request<()>) -> Result<String, tide::Error> {
}
}

async fn echo_empty(req: Request<()>) -> Result<String, tide::Error> {
match req.param::<String>("") {
Ok(path) => Ok(path),
Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)),
}
}

#[async_std::test]
async fn wildcard() {
let mut app = tide::Server::new();
Expand Down Expand Up @@ -223,13 +216,29 @@ async fn nameless_internal_wildcard() {
#[async_std::test]
async fn nameless_internal_wildcard2() {
let mut app = tide::new();
app.at("/echo/:/:path").get(echo_empty);
app.at("/echo/:/:path").get(|req: Request<()>| async move {
assert_eq!(req.param::<String>("path")?, "two");
Ok("")
});

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/echo/one/two").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
assert_eq!(&res.body_string().await.unwrap(), "one");
let _: tide::Response = app.respond(req).await.unwrap();
}

#[async_std::test]
async fn ambiguous_router_wildcard_vs_star() {
let mut app = tide::new();
app.at("/:one/:two").get(|_| async { Ok("one/two") });
app.at("/posts/*").get(|_| async { Ok("posts/*") });
let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/posts/10").unwrap(),
);

let mut response: http_types::Response = app.respond(req).await.unwrap();
let body_string = response.body_string().await.unwrap();
assert_eq!(body_string, "posts/*");
}

0 comments on commit 6a40a9d

Please sign in to comment.