mirror of https://github.com/fafhrd91/actix-web
started some test code
This commit is contained in:
parent
ac82b56ad7
commit
db69279557
actix-web-codegen
|
@ -255,23 +255,17 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
|||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use actix_web_cute_codegen::{scope};
|
||||
/// use actix_web_codegen::{scope};
|
||||
///
|
||||
/// #[scope("/scope")]
|
||||
/// const mod_inner: () = {
|
||||
/// use actix_web_cute_codegen::{get, hook};
|
||||
/// use actix_web::{HttpResponse, Responder};
|
||||
/// use futures::{Future, future};
|
||||
/// use actix_web::{HttpResponse, HttpRequest, Responder, get };
|
||||
/// use actix_web::web::Json;
|
||||
///
|
||||
/// #[get("/test")]
|
||||
/// pub fn test() -> impl Responder {
|
||||
/// HttpResponse::Ok()
|
||||
/// }
|
||||
///
|
||||
/// #[get("/test_async")]
|
||||
/// pub fn auto_sync() -> impl Future<Item=HttpResponse, Error=actix_web::Error> {
|
||||
/// future::ok(HttpResponse::Ok().finish())
|
||||
/// }
|
||||
/// #[get("/test")]
|
||||
/// pub async fn test() -> impl Responder {
|
||||
/// actix_web::HttpResponse::Ok().finish()
|
||||
/// }
|
||||
/// };
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -662,7 +662,7 @@ impl fmt::Display for ScopeArgs {
|
|||
writeln!(f, "#[allow(non_camel_case_types)]")?;
|
||||
writeln!(f, "struct {};\n", self.name)?;
|
||||
writeln!(f, "impl actix_web::dev::HttpServiceFactory for {} {{", self.name)?;
|
||||
writeln!(f, " fn register(self, config: &mut actix_web::dev::AppService) {{")?;
|
||||
writeln!(f, " fn register(self, __config: &mut actix_web::dev::AppService) {{")?;
|
||||
write!(f, " let scope = actix_web::Scope::new(\"{}\")", self.path)?;
|
||||
|
||||
for handler in self.scope_items.handlers.iter() {
|
||||
|
@ -670,7 +670,7 @@ impl fmt::Display for ScopeArgs {
|
|||
}
|
||||
|
||||
writeln!(f, ";\n")?;
|
||||
writeln!(f, " actix_web::dev::HttpServiceFactory::register(scope, config)")?;
|
||||
writeln!(f, " actix_web::dev::HttpServiceFactory::register(scope, __config)")?;
|
||||
writeln!(f, " }}\n}}")
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ use actix_web::{
|
|||
web, App, Error, HttpRequest, HttpResponse, Responder,
|
||||
};
|
||||
use actix_web_codegen::{
|
||||
connect, delete, get, head, options, patch, post, put, route, routes, trace,
|
||||
connect, delete, get, head, options, patch, post, put, route, routes, trace, scope
|
||||
};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
|
||||
|
@ -384,3 +384,67 @@ async fn test_wrap() {
|
|||
let body = String::from_utf8(body.to_vec()).unwrap();
|
||||
assert!(body.contains("wrong number of parameters"));
|
||||
}
|
||||
|
||||
#[scope("/works")]
|
||||
const mod_inner: () = {
|
||||
use actix_web::{HttpResponse, HttpRequest, Responder, put, head, connect, options, trace, patch, delete, web };
|
||||
use actix_web::web::Json;
|
||||
|
||||
#[actix_web::get("/test")]
|
||||
pub async fn test() -> impl Responder {
|
||||
mod_test2()
|
||||
}
|
||||
|
||||
#[actix_web::get("/twicetest/{value}")]
|
||||
pub async fn test_twice(value: web::Path<String>) -> impl actix_web::Responder {
|
||||
let int_value: i32 = value.parse().unwrap_or(0);
|
||||
let doubled = int_value * 2;
|
||||
HttpResponse::Ok().body(format!("Twice value: {}", doubled))
|
||||
}
|
||||
|
||||
#[actix_web::post("/test")]
|
||||
pub async fn test_post() -> impl Responder {
|
||||
HttpResponse::Ok().body(format!("post works"))
|
||||
}
|
||||
|
||||
#[put("/test")]
|
||||
pub async fn test_put() -> impl Responder {
|
||||
HttpResponse::Ok().body(format!("put works"))
|
||||
}
|
||||
|
||||
#[head("/test")]
|
||||
pub async fn test_head() -> impl Responder {
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
#[connect("/test")]
|
||||
pub async fn test_connect() -> impl Responder {
|
||||
HttpResponse::Ok().body("CONNECT works")
|
||||
}
|
||||
|
||||
#[options("/test")]
|
||||
pub async fn test_options() -> impl Responder {
|
||||
HttpResponse::Ok().body("OPTIONS works")
|
||||
}
|
||||
|
||||
#[trace("/test")]
|
||||
pub async fn test_trace(req: HttpRequest) -> impl Responder {
|
||||
HttpResponse::Ok().body(format!("TRACE works: {:?}", req))
|
||||
}
|
||||
|
||||
#[patch("/test")]
|
||||
pub async fn test_patch() -> impl Responder {
|
||||
HttpResponse::Ok().body(format!("patch works"))
|
||||
}
|
||||
|
||||
#[delete("/test")]
|
||||
pub async fn test_delete() -> impl Responder {
|
||||
HttpResponse::Ok().body("DELETE works")
|
||||
}
|
||||
|
||||
pub fn mod_test2() -> impl actix_web::Responder {
|
||||
actix_web::HttpResponse::Ok().finish()
|
||||
}
|
||||
};
|
||||
|
||||
// todo: tests to call each endpoint...
|
Loading…
Reference in New Issue