2018-06-28 15:55:15 +00:00
|
|
|
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
2017-02-05 09:43:53 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2017-02-05 09:43:53 +00:00
|
|
|
|
|
|
|
#[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;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-02-05 09:43:53 +00:00
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
fn assert_no_collision(rocket: Rocket) {
|
|
|
|
let client = Client::new(rocket).unwrap();
|
|
|
|
let mut response = client.get("/?field=query").dispatch();
|
2017-04-14 08:59:28 +00:00
|
|
|
assert_eq!(response.body_string(), Some("query".into()));
|
2017-02-05 09:43:53 +00:00
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
let mut response = client.get("/").dispatch();
|
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]);
|
2017-06-06 20:41:04 +00:00
|
|
|
assert_no_collision(rocket);
|
2017-02-05 09:43:53 +00:00
|
|
|
|
|
|
|
let rocket = rocket::ignite().mount("/", routes![second, first]);
|
2017-06-06 20:41:04 +00:00
|
|
|
assert_no_collision(rocket);
|
2017-02-05 09:43:53 +00:00
|
|
|
}
|
|
|
|
}
|