Rocket/core/lib/tests/query-and-non-query-dont-collide.rs
Sergio Benitez d7f6d82fe4 Implement 'FromForm[Value]', 'Responder' proc-macro derives.
This completes the migration of custom derives to proc-macros, removing
the need for the `custom_derive` feature in consumer code. This commit
also includes documentation, unit tests, and compile UI tests for each
of the derives.

Additionally, this commit improves the existing `FromForm` and
`FromFormValue` derives. The generated code for `FromForm` now returns
an error value indicating the error condition. The `FromFormValue`
derive now accepts a `form` attribute on variants for specifying the
exact value string to match against.

Closes #590.
Closes #670.
2018-08-06 19:58:07 -07:00

44 lines
1009 B
Rust

#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]
#[macro_use] 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::local::Client;
fn assert_no_collision(rocket: Rocket) {
let client = Client::new(rocket).unwrap();
let mut response = client.get("/?field=query").dispatch();
assert_eq!(response.body_string(), Some("query".into()));
let mut response = client.get("/").dispatch();
assert_eq!(response.body_string(), Some("no query".into()));
}
#[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);
}
}