1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-22 01:21:10 +00:00

fix: service macro comments (#3474)

* 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 <robjtede@icloud.com>
This commit is contained in:
Durairaj Subramaniam 2024-10-07 23:03:38 +01:00 committed by GitHub
parent 3849cdaa6c
commit 27c07f122b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -662,6 +662,7 @@ where
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! services { macro_rules! services {
() => {()};
($($x:expr),+ $(,)?) => { ($($x:expr),+ $(,)?) => {
($($x,)+) ($($x,)+)
} }
@ -870,4 +871,40 @@ mod tests {
let req = test::TestRequest::default().to_request(); let req = test::TestRequest::default().to_request();
let _res = test::call_service(&app, req).await; 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));
}
} }