2017-02-05 09:43:53 +00:00
|
|
|
#![feature(plugin, custom_derive)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
struct Query {
|
|
|
|
field: String
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/?<query>")]
|
|
|
|
fn first(query: Query) -> String {
|
|
|
|
query.field
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
fn second() -> &'static str {
|
|
|
|
"no query"
|
|
|
|
}
|
|
|
|
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
use rocket::Rocket;
|
|
|
|
use rocket::testing::MockRequest;
|
|
|
|
use rocket::http::Method::*;
|
|
|
|
|
|
|
|
fn assert_no_collision(rocket: &Rocket) {
|
|
|
|
let mut req = MockRequest::new(Get, "/?field=query");
|
|
|
|
let mut response = req.dispatch_with(&rocket);
|
2017-04-14 08:59:28 +00:00
|
|
|
assert_eq!(response.body_string(), Some("query".into()));
|
2017-02-05 09:43:53 +00:00
|
|
|
|
|
|
|
let mut req = MockRequest::new(Get, "/");
|
|
|
|
let mut response = req.dispatch_with(&rocket);
|
2017-04-14 08:59:28 +00:00
|
|
|
assert_eq!(response.body_string(), Some("no query".into()));
|
2017-02-05 09:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_query_collisions() {
|
|
|
|
let rocket = rocket::ignite().mount("/", routes![first, second]);
|
|
|
|
assert_no_collision(&rocket);
|
|
|
|
|
|
|
|
let rocket = rocket::ignite().mount("/", routes![second, first]);
|
|
|
|
assert_no_collision(&rocket);
|
|
|
|
}
|
|
|
|
}
|