2016-08-27 23:20:01 +00:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_macros)]
|
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
use rocket::Rocket;
|
|
|
|
|
2016-09-04 11:06:28 +00:00
|
|
|
#[get("/")]
|
2016-08-27 23:20:01 +00:00
|
|
|
fn hello() -> &'static str {
|
|
|
|
"Hello, world!"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
Rocket::new("localhost", 8000).mount_and_launch("/", routes![hello]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::rocket::{Rocket, Request, Method};
|
|
|
|
|
|
|
|
fn run_test<F>(f: F) where F: Fn(Rocket) {
|
|
|
|
let mut rocket = Rocket::new("_", 0);
|
|
|
|
rocket.mount("/", routes![super::hello]);
|
|
|
|
f(rocket);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
run_test(|_rocket: Rocket| {
|
|
|
|
let _req = Request::mock(Method::Get, "/");
|
|
|
|
// TODO: Allow something like this:
|
|
|
|
// let result = rocket.route(&req);
|
|
|
|
// assert_eq!(result.as_str(), "Hello, world!")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|