Skip to content

Commit

Permalink
test: refactor tests for newer version of oblivion
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Apr 6, 2024
1 parent 0cf2d5a commit ce0f916
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
17 changes: 4 additions & 13 deletions oblivion-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,19 @@ use syn::{parse_macro_input, ItemFn};

/// ## Oblivion 业务函数宏
///
/// 请在使用该属性宏的`.rs`文件中加入:
///
/// ```rust
/// use futures::future::{BoxFuture, FutureExt};
/// ```
///
/// 然后再引入并使用它。
///
/// 这是一个示例:
///
/// ```rust
/// use futures::future::{BoxFuture, FutureExt};
/// use oblivion::oblivion_codegen::async_route;
/// use oblivion::utils::parser::OblivionRequest;
/// use oblivion::models::render::BaseResponse;
/// use oblivion::models::render::{BaseResponse, Response};
///
/// #[async_route]
/// fn welcome(mut req: OblivionRequest) -> BaseResponse {
/// BaseResponse::TextResponse(
/// fn welcome(mut req: OblivionRequest) -> Response {
/// Ok(BaseResponse::TextResponse(
/// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()),
/// 200,
/// )
/// ))
/// }
/// ```
#[proc_macro_attribute]
Expand Down
39 changes: 17 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,18 @@ pub mod models {
/// Routing can be simply implemented using routing macros:
///
/// ```rust
/// use futures::future::{BoxFuture, FutureExt};
/// use oblivion::path_route;
/// use oblivion::utils::parser::OblivionRequest;
/// use oblivion::models::render::BaseResponse;
/// use oblivion::models::render::{BaseResponse, Response};
/// use oblivion_codegen::async_route;
/// use oblivion::models::router::Router;
///
/// #[async_route]
/// fn welcome(mut req: OblivionRequest) -> BaseResponse {
/// BaseResponse::TextResponse(
/// fn welcome(mut req: OblivionRequest) -> Response {
/// Ok(BaseResponse::TextResponse(
/// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()),
/// 200,
/// )
/// ))
/// }
///
/// let mut router = Router::new();
Expand All @@ -63,9 +62,8 @@ pub mod models {
#[macro_export]
macro_rules! path_route {
($router:expr, $path:expr => $handler:ident) => {{
let mut router = $router;
let route = $crate::models::router::Route::new($handler);
router.regist(
$router.regist(
$crate::models::router::RoutePath::new($path, $crate::models::router::RouteType::Path),
route,
);
Expand All @@ -77,32 +75,30 @@ macro_rules! path_route {
/// Starting routes can be simply implemented using the start route macro:
///
/// ```rust
/// use futures::future::{BoxFuture, FutureExt};
/// use oblivion::startswith_route;
/// use oblivion::utils::parser::OblivionRequest;
/// use oblivion::models::render::BaseResponse;
/// use oblivion::models::render::{BaseResponse, Response};
/// use oblivion_codegen::async_route;
/// use oblivion::models::router::Router;
///
/// #[async_route]
/// fn welcome(mut req: OblivionRequest) -> BaseResponse {
/// BaseResponse::TextResponse(
/// fn welcome(mut req: OblivionRequest) -> Response {
/// Ok(BaseResponse::TextResponse(
/// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()),
/// 200,
/// )
/// ))
/// }
///
/// let mut router = Router::new();
/// startswith_route!(&mut router, "/welcome" => welcome);
/// startswith_route!(router, "/welcome" => welcome);
/// ```
///
/// The above route will direct all Oblivion Location Path String starting with `/welcome`.
#[macro_export]
macro_rules! startswith_route {
($router:expr, $path:expr => $handler:ident) => {{
let mut router = $router;
let route = $crate::models::router::Route::new($handler);
router.regist(
$router.regist(
$crate::models::router::RoutePath::new(
$path,
$crate::models::router::RouteType::StartswithPath,
Expand All @@ -120,20 +116,20 @@ macro_rules! startswith_route {
/// use futures::future::{BoxFuture, FutureExt};
/// use oblivion::regex_route;
/// use oblivion::utils::parser::OblivionRequest;
/// use oblivion::models::render::BaseResponse;
/// use oblivion::models::render::{BaseResponse, Response};
/// use oblivion_codegen::async_route;
/// use oblivion::models::router::Router;
///
/// #[async_route]
/// fn welcome(mut req: OblivionRequest) -> BaseResponse {
/// BaseResponse::TextResponse(
/// fn welcome(mut req: OblivionRequest) -> Response {
/// Ok(BaseResponse::TextResponse(
/// format!("欢迎进入信息绝对安全区, 来自[{}]的朋友", req.get_ip()),
/// 200,
/// )
/// ))
/// }
///
/// let mut router = Router::new();
/// regex_route!(&mut router, r"^/welcome/.*" => welcome);
/// regex_route!(router, r"^/welcome/.*" => welcome);
/// ```
///
/// The above route will direct all Oblivion Location Path String starting with `/welcome/`.
Expand All @@ -142,9 +138,8 @@ macro_rules! startswith_route {
#[macro_export]
macro_rules! regex_route {
($router:expr, $path:expr => $handler:ident) => {{
let mut router = $router;
let route = $crate::models::router::Route::new($handler);
router.regist(
$router.regist(
$crate::models::router::RoutePath::new(
$path,
$crate::models::router::RouteType::RegexPath,
Expand Down

0 comments on commit ce0f916

Please sign in to comment.