mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-31 23:02:37 +00:00
d7f6d82fe4
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.
36 lines
928 B
Rust
36 lines
928 B
Rust
#![feature(plugin, decl_macro)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
extern crate rocket;
|
|
|
|
use std::path::PathBuf;
|
|
use rocket::Route;
|
|
|
|
#[get("/<path..>")]
|
|
fn files(route: &Route, path: PathBuf) -> String {
|
|
format!("{}/{}", route.base(), path.to_string_lossy())
|
|
}
|
|
|
|
mod route_guard_tests {
|
|
use super::*;
|
|
use rocket::local::Client;
|
|
|
|
fn assert_path(client: &Client, path: &str) {
|
|
let mut res = client.get(path).dispatch();
|
|
assert_eq!(res.body_string(), Some(path.into()));
|
|
}
|
|
|
|
#[test]
|
|
fn check_mount_path() {
|
|
let rocket = rocket::ignite()
|
|
.mount("/first", routes![files])
|
|
.mount("/second", routes![files]);
|
|
|
|
let client = Client::new(rocket).unwrap();
|
|
assert_path(&client, "/first/some/path");
|
|
assert_path(&client, "/second/some/path");
|
|
assert_path(&client, "/first/second/b/c");
|
|
assert_path(&client, "/second/a/b/c");
|
|
}
|
|
}
|