-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix get_raw_segments index argument in route codegen.
Fixes #41.
- Loading branch information
1 parent
e54a3f3
commit e0c1740
Showing
2 changed files
with
58 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#![feature(plugin)] | ||
#![plugin(rocket_codegen)] | ||
|
||
extern crate rocket; | ||
|
||
use std::path::PathBuf; | ||
|
||
#[get("/test/<path..>")] | ||
fn test(path: PathBuf) -> String { | ||
format!("{:?}", path) | ||
} | ||
|
||
#[get("/two/<path..>")] | ||
fn two(path: PathBuf) -> String { | ||
format!("{:?}", path) | ||
} | ||
|
||
#[get("/one/two/<path..>")] | ||
fn one_two(path: PathBuf) -> String { | ||
format!("{:?}", path) | ||
} | ||
|
||
#[get("/<path..>", rank = 2)] | ||
fn none(path: PathBuf) -> String { | ||
format!("{:?}", path) | ||
} | ||
|
||
use rocket::testing::MockRequest; | ||
use rocket::http::Method::*; | ||
|
||
#[test] | ||
fn segments_works() { | ||
let rocket = rocket::ignite().mount("/", routes![test, two, one_two, none]); | ||
|
||
// We construct a path that matches each of the routes above. We ensure the | ||
// prefix is stripped, confirming that dynamic segments are working. | ||
for prefix in &["", "/test", "/two", "/one/two"] { | ||
let path = "this/is/the/path/we/want"; | ||
let mut req = MockRequest::new(Get, format!("{}/{}", prefix, path)); | ||
|
||
let mut response = req.dispatch_with(&rocket); | ||
let body_str = response.body().and_then(|b| b.into_string()); | ||
assert_eq!(body_str, Some(format!("{:?}", path))); | ||
} | ||
} |