Skip to content

Commit

Permalink
Re-format trybuild tests
Browse files Browse the repository at this point in the history
Automated with

for file in axum-macros/tests/**/*.rs; do
    rustfmt --edition 2021 "$file"
done
  • Loading branch information
jplatte committed Nov 26, 2024
1 parent 69a89c0 commit 680619c
Show file tree
Hide file tree
Showing 42 changed files with 74 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use axum::{
body::Bytes,
http::{Method, Uri},
Json,
};
use axum_macros::debug_handler;
use axum::{Json, body::Bytes, http::{Method, Uri}};

#[debug_handler]
async fn one(_: Json<()>, _: String, _: Uri) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use axum::response::AppendHeaders;

#[axum::debug_handler]
async fn handler(
) -> (
async fn handler() -> (
axum::http::StatusCode,
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#[axum::debug_handler]
async fn handler(
) -> (
async fn handler() -> (
axum::http::request::Parts, // this should be response parts, not request parts
axum::http::StatusCode,
) {
panic!()
}

fn main(){}
fn main() {}
5 changes: 3 additions & 2 deletions axum-macros/tests/debug_handler/fail/too_many_extractors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::http::Uri;
use axum_macros::debug_handler;

#[debug_handler]
async fn handler(
Expand All @@ -20,6 +20,7 @@ async fn handler(
_e15: Uri,
_e16: Uri,
_e17: Uri,
) {}
) {
}

fn main() {}
2 changes: 1 addition & 1 deletion axum-macros/tests/debug_handler/fail/wrong_order.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{http::Uri, Json};
use axum_macros::debug_handler;
use axum::{Json, http::Uri};

#[debug_handler]
async fn one(_: Json<()>, _: Uri) {}
Expand Down
11 changes: 4 additions & 7 deletions axum-macros/tests/debug_handler/fail/wrong_return_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
async fn named_type() -> (
axum::http::StatusCode,
axum::Json<&'static str>,
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
) {
panic!()
}


struct CustomIntoResponse{

}
impl axum::response::IntoResponse for CustomIntoResponse{
struct CustomIntoResponse {}
impl axum::response::IntoResponse for CustomIntoResponse {
fn into_response(self) -> axum::response::Response {
todo!()
}
Expand All @@ -22,7 +19,7 @@ impl axum::response::IntoResponse for CustomIntoResponse{
async fn custom_type() -> (
axum::http::StatusCode,
CustomIntoResponse,
axum::response::AppendHeaders<[( axum::http::HeaderName,&'static str); 1]>,
axum::response::AppendHeaders<[(axum::http::HeaderName, &'static str); 1]>,
) {
panic!()
}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/debug_handler/pass/impl_into_response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::response::IntoResponse;
use axum_macros::debug_handler;

#[debug_handler]
async fn handler() -> impl IntoResponse {
Expand Down
17 changes: 4 additions & 13 deletions axum-macros/tests/debug_handler/pass/infer_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::extract::State;
use axum_macros::debug_handler;

#[debug_handler]
async fn handler(_: State<AppState>) {}
Expand All @@ -8,22 +8,13 @@ async fn handler(_: State<AppState>) {}
async fn handler_2(_: axum::extract::State<AppState>) {}

#[debug_handler]
async fn handler_3(
_: axum::extract::State<AppState>,
_: axum::extract::State<AppState>,
) {}
async fn handler_3(_: axum::extract::State<AppState>, _: axum::extract::State<AppState>) {}

#[debug_handler]
async fn handler_4(
_: State<AppState>,
_: State<AppState>,
) {}
async fn handler_4(_: State<AppState>, _: State<AppState>) {}

#[debug_handler]
async fn handler_5(
_: axum::extract::State<AppState>,
_: State<AppState>,
) {}
async fn handler_5(_: axum::extract::State<AppState>, _: State<AppState>) {}

#[derive(Clone)]
struct AppState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use axum::http::{Method, Uri};
use axum_macros::debug_handler;

#[debug_handler]
async fn handler(_one: Method, _two: Uri, _three: String) {}
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/debug_handler/pass/ready.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::debug_handler;
use std::future::{Ready, ready};
use std::future::{ready, Ready};

#[debug_handler]
fn handler() -> Ready<()> {
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/debug_handler/pass/state_and_body.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{extract::Request, extract::State};
use axum_macros::debug_handler;
use axum::{extract::State, extract::Request};

#[debug_handler(state = AppState)]
async fn handler(_: State<AppState>, _: Request) {}
Expand Down
7 changes: 1 addition & 6 deletions axum-macros/tests/debug_middleware/fail/next_not_last.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use axum::{
extract::Request,
response::Response,
middleware::Next,
debug_middleware,
};
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};

#[debug_middleware]
async fn my_middleware(next: Next, request: Request) -> Response {
Expand Down
7 changes: 1 addition & 6 deletions axum-macros/tests/debug_middleware/pass/basic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use axum::{
extract::Request,
response::Response,
middleware::Next,
debug_middleware,
};
use axum::{debug_middleware, extract::Request, middleware::Next, response::Response};

#[debug_middleware]
async fn my_middleware(request: Request, next: Next) -> Response {
Expand Down
10 changes: 6 additions & 4 deletions axum-macros/tests/from_ref/pass/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use axum::{Router, routing::get, extract::{State, FromRef}};
use axum::{
extract::{FromRef, State},
routing::get,
Router,
};

// This will implement `FromRef` for each field in the struct.
#[derive(Clone, FromRef)]
Expand All @@ -14,7 +18,5 @@ fn main() {
auth_token: Default::default(),
};

let _: axum::Router = Router::new()
.route("/", get(handler))
.with_state(state);
let _: axum::Router = Router::new().route("/", get(handler)).with_state(state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum Extractor {
Foo {
#[from_request(via(axum::Extension))]
foo: (),
}
},
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::FromRequest;
use axum::extract::State;
use axum_macros::FromRequest;

#[derive(FromRequest)]
struct Extractor {
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/container_parts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{
extract::{FromRequestParts, Extension},
extract::{Extension, FromRequestParts},
response::Response,
};

Expand Down
9 changes: 3 additions & 6 deletions axum-macros/tests/from_request/pass/named.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use axum::{
extract::FromRequest,
response::Response,
};
use axum::{extract::FromRequest, response::Response};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};

#[derive(FromRequest)]
Expand Down
9 changes: 3 additions & 6 deletions axum-macros/tests/from_request/pass/named_parts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use axum::{
extract::FromRequestParts,
response::Response,
};
use axum::{extract::FromRequestParts, response::Response};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};

#[derive(FromRequestParts)]
Expand Down
6 changes: 3 additions & 3 deletions axum-macros/tests/from_request/pass/named_via.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use axum::{
response::Response,
extract::{Extension, FromRequest},
response::Response,
};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};

#[derive(FromRequest)]
Expand Down
6 changes: 3 additions & 3 deletions axum-macros/tests/from_request/pass/named_via_parts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use axum::{
response::Response,
extract::{Extension, FromRequestParts},
response::Response,
};
use axum_extra::{
TypedHeader,
typed_header::TypedHeaderRejection,
headers::{self, UserAgent},
typed_header::TypedHeaderRejection,
TypedHeader,
};

#[derive(FromRequestParts)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use axum::{
Router,
};
use axum_macros::FromRequest;
use std::collections::HashMap;
use serde::Deserialize;
use std::collections::HashMap;

fn main() {
let _: Router = Router::new().route("/", get(handler).post(handler_result));
Expand All @@ -17,10 +17,7 @@ async fn handler(_: MyJson) {}
async fn handler_result(_: Result<MyJson, MyJsonRejection>) {}

#[derive(FromRequest, Deserialize)]
#[from_request(
via(axum::extract::Json),
rejection(MyJsonRejection),
)]
#[from_request(via(axum::extract::Json), rejection(MyJsonRejection))]
#[serde(transparent)]
struct MyJson(HashMap<String, String>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use axum::{
Router,
};
use axum_macros::FromRequestParts;
use std::collections::HashMap;
use serde::Deserialize;
use std::collections::HashMap;

fn main() {
let _: Router = Router::new().route("/", get(handler).post(handler_result));
Expand All @@ -17,10 +17,7 @@ async fn handler(_: MyQuery) {}
async fn handler_result(_: Result<MyQuery, MyQueryRejection>) {}

#[derive(FromRequestParts, Deserialize)]
#[from_request(
via(axum::extract::Query),
rejection(MyQueryRejection),
)]
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
#[serde(transparent)]
struct MyQuery(HashMap<String, String>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ async fn handler(_: MyJson<Payload>) {}
async fn handler_result(_: Result<MyJson<Payload>, MyJsonRejection>) {}

#[derive(FromRequest)]
#[from_request(
via(axum::Json),
rejection(MyJsonRejection),
)]
#[from_request(via(axum::Json), rejection(MyJsonRejection))]
struct MyJson<T>(T);

struct MyJsonRejection {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ async fn handler(_: MyQuery<Payload>) {}
async fn handler_result(_: Result<MyQuery<Payload>, MyQueryRejection>) {}

#[derive(FromRequestParts)]
#[from_request(
via(axum::extract::Query),
rejection(MyQueryRejection),
)]
#[from_request(via(axum::extract::Query), rejection(MyQueryRejection))]
struct MyQuery<T>(T);

struct MyQueryRejection {}
Expand Down
4 changes: 2 additions & 2 deletions axum-macros/tests/from_request/pass/state_cookie.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_macros::FromRequest;
use axum::extract::FromRef;
use axum_extra::extract::cookie::{PrivateCookieJar, Key};
use axum_extra::extract::cookie::{Key, PrivateCookieJar};
use axum_macros::FromRequest;

#[derive(FromRequest)]
#[from_request(state(AppState))]
Expand Down
4 changes: 2 additions & 2 deletions axum-macros/tests/from_request/pass/state_explicit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use axum_macros::FromRequest;
use axum::{
extract::{FromRef, State},
Router,
routing::get,
Router,
};
use axum_macros::FromRequest;

fn main() {
let _: axum::Router = Router::new()
Expand Down
6 changes: 3 additions & 3 deletions axum-macros/tests/from_request/pass/state_explicit_parts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use axum_macros::FromRequestParts;
use axum::{
extract::{FromRef, State, Query},
Router,
extract::{FromRef, Query, State},
routing::get,
Router,
};
use axum_macros::FromRequestParts;
use std::collections::HashMap;

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{
extract::{State, FromRef},
extract::{FromRef, State},
routing::get,
Router,
};
Expand Down
6 changes: 1 addition & 5 deletions axum-macros/tests/from_request/pass/state_field_infer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use axum::{
extract::State,
routing::get,
Router,
};
use axum::{extract::State, routing::get, Router};
use axum_macros::FromRequest;

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion axum-macros/tests/from_request/pass/state_infer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum_macros::FromRequest;
use axum::extract::State;
use axum_macros::FromRequest;

#[derive(FromRequest)]
struct Extractor {
Expand Down
Loading

0 comments on commit 680619c

Please sign in to comment.