Skip to content

Commit

Permalink
fix: service macro comments (#3474)
Browse files Browse the repository at this point in the history
* fix: service macro comments #3472

* test: service macro comments #3472

* fix: add case for empty tuple seperately

* doc: add case for empty tuple seperately

* test: move test_services into lib

---------

Co-authored-by: Rob Ede <[email protected]>
  • Loading branch information
Durairaj and robjtede authored Oct 7, 2024
1 parent 3849cda commit 27c07f1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions actix-web/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ where
/// ```
#[macro_export]
macro_rules! services {
() => {()};
($($x:expr),+ $(,)?) => {
($($x,)+)
}
Expand Down Expand Up @@ -870,4 +871,40 @@ mod tests {
let req = test::TestRequest::default().to_request();
let _res = test::call_service(&app, req).await;
}

#[test]
fn define_services_macro_with_multiple_arguments() {
let result = services!(1, 2, 3);
assert_eq!(result, (1, 2, 3));
}

#[test]
fn define_services_macro_with_single_argument() {
let result = services!(1);
assert_eq!(result, (1,));
}

#[test]
fn define_services_macro_with_no_arguments() {
let result = services!();
let () = result;
}

#[test]
fn define_services_macro_with_trailing_comma() {
let result = services!(1, 2, 3,);
assert_eq!(result, (1, 2, 3));
}

#[test]
fn define_services_macro_with_comments_in_arguments() {
let result = services!(
1, // First comment
2, // Second comment
3 // Third comment
);

// Assert that comments are ignored and it correctly returns a tuple.
assert_eq!(result, (1, 2, 3));
}
}

0 comments on commit 27c07f1

Please sign in to comment.