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

use route-recognizer 0.2 #607

Merged
merged 1 commit into from
Jun 19, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/*");
}