Skip to content

Commit 6a40a9d

Browse files
committed
use route-recognizer 0.2
1 parent d88828d commit 6a40a9d

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ async-std = { version = "1.6.0", features = ["unstable"] }
3838
femme = "2.0.1"
3939
http-types = "2.0.1"
4040
kv-log-macro = "1.0.4"
41-
route-recognizer = "0.1.13"
4241
serde = "1.0.102"
4342
serde_json = "1.0.41"
43+
route-recognizer = "0.2.0"
4444

4545
[dev-dependencies]
4646
async-std = { version = "1.6.0", features = ["unstable", "attributes"] }

tests/wildcard.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ async fn echo_path(req: Request<()>) -> Result<String, tide::Error> {
2525
}
2626
}
2727

28-
async fn echo_empty(req: Request<()>) -> Result<String, tide::Error> {
29-
match req.param::<String>("") {
30-
Ok(path) => Ok(path),
31-
Err(err) => Err(tide::Error::new(StatusCode::BadRequest, err)),
32-
}
33-
}
34-
3528
#[async_std::test]
3629
async fn wildcard() {
3730
let mut app = tide::Server::new();
@@ -223,13 +216,29 @@ async fn nameless_internal_wildcard() {
223216
#[async_std::test]
224217
async fn nameless_internal_wildcard2() {
225218
let mut app = tide::new();
226-
app.at("/echo/:/:path").get(echo_empty);
219+
app.at("/echo/:/:path").get(|req: Request<()>| async move {
220+
assert_eq!(req.param::<String>("path")?, "two");
221+
Ok("")
222+
});
227223

228224
let req = http::Request::new(
229225
Method::Get,
230226
Url::parse("http://localhost/echo/one/two").unwrap(),
231227
);
232-
let mut res: http::Response = app.respond(req).await.unwrap();
233-
assert_eq!(res.status(), StatusCode::Ok);
234-
assert_eq!(&res.body_string().await.unwrap(), "one");
228+
let _: tide::Response = app.respond(req).await.unwrap();
229+
}
230+
231+
#[async_std::test]
232+
async fn ambiguous_router_wildcard_vs_star() {
233+
let mut app = tide::new();
234+
app.at("/:one/:two").get(|_| async { Ok("one/two") });
235+
app.at("/posts/*").get(|_| async { Ok("posts/*") });
236+
let req = http::Request::new(
237+
Method::Get,
238+
Url::parse("http://localhost/posts/10").unwrap(),
239+
);
240+
241+
let mut response: http_types::Response = app.respond(req).await.unwrap();
242+
let body_string = response.body_string().await.unwrap();
243+
assert_eq!(body_string, "posts/*");
235244
}

0 commit comments

Comments
 (0)