Skip to content

Commit

Permalink
chore: Cover foreign traits in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Oct 29, 2024
1 parent a146063 commit 1befce5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
digraph "GET /home - 0" {
digraph "GET / - 0" {
0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next<crate::route_0::Next0>) -> pavex::response::Response"]
1 [ label = "pavex::middleware::Next::new(crate::route_0::Next0) -> pavex::middleware::Next<crate::route_0::Next0>"]
2 [ label = "crate::route_0::Next0() -> crate::route_0::Next0"]
Expand All @@ -8,26 +8,28 @@ digraph "GET /home - 0" {
0 -> 3 [ ]
}

digraph "GET /home - 1" {
0 [ label = "app_a7fd6a2c::handler(app_a7fd6a2c::A, app_a7fd6a2c::C, app_a7fd6a2c::D, app_a7fd6a2c::E) -> pavex::response::Response"]
digraph "GET / - 1" {
0 [ label = "app_a7fd6a2c::handler(app_a7fd6a2c::A, app_a7fd6a2c::C, app_a7fd6a2c::D, app_a7fd6a2c::E, app_a7fd6a2c::F) -> pavex::response::Response"]
1 [ label = "<app_a7fd6a2c::A as app_a7fd6a2c::MyTrait>::a_method_that_returns_self() -> app_a7fd6a2c::A"]
2 [ label = "<app_a7fd6a2c::B as app_a7fd6a2c::AnotherTrait>::a_method_that_consumes_self(app_a7fd6a2c::B) -> app_a7fd6a2c::C"]
3 [ label = "<app_a7fd6a2c::A as app_a7fd6a2c::MyTrait>::a_method_with_a_generic::<std::string::String>(&app_a7fd6a2c::A) -> app_a7fd6a2c::D"]
4 [ label = "<app_a7fd6a2c::C as app_a7fd6a2c::GenericTrait::<std::string::String>>::a_method(&app_a7fd6a2c::C) -> app_a7fd6a2c::E"]
5 [ label = "<app_a7fd6a2c::A as app_a7fd6a2c::MyTrait>::a_method_that_borrows_self(&app_a7fd6a2c::A) -> app_a7fd6a2c::B"]
6 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
5 [ label = "<app_a7fd6a2c::F as core::default::Default>::default() -> app_a7fd6a2c::F"]
6 [ label = "<app_a7fd6a2c::A as app_a7fd6a2c::MyTrait>::a_method_that_borrows_self(&app_a7fd6a2c::A) -> app_a7fd6a2c::B"]
7 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
5 -> 0 [ ]
4 -> 0 [ ]
2 -> 4 [ label = "&"]
5 -> 2 [ ]
1 -> 5 [ label = "&"]
6 -> 2 [ ]
1 -> 6 [ label = "&"]
3 -> 0 [ ]
1 -> 3 [ label = "&"]
2 -> 0 [ ]
1 -> 0 [ ]
0 -> 6 [ ]
0 -> 7 [ ]
}

digraph "* /home - 0" {
digraph "* / - 0" {
0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next<crate::route_1::Next0<'a>>) -> pavex::response::Response"]
1 [ label = "pavex::middleware::Next::new(crate::route_1::Next0<'a>) -> pavex::middleware::Next<crate::route_1::Next0<'a>>"]
2 [ label = "crate::route_1::Next0(&'a pavex::router::AllowedMethods) -> crate::route_1::Next0<'a>"]
Expand All @@ -39,7 +41,7 @@ digraph "* /home - 0" {
5 -> 2 [ ]
}

digraph "* /home - 1" {
digraph "* / - 1" {
0 [ label = "pavex::router::default_fallback(&pavex::router::AllowedMethods) -> pavex::response::Response"]
2 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
3 [ label = "&pavex::router::AllowedMethods"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn run(
}
fn build_router() -> pavex_matchit::Router<u32> {
let mut router = pavex_matchit::Router::new();
router.insert("/home", 0u32).unwrap();
router.insert("/", 0u32).unwrap();
router
}
async fn route_request(
Expand Down Expand Up @@ -84,21 +84,22 @@ pub mod route_0 {
<pavex::response::Response as pavex::response::IntoResponse>::into_response(v2)
}
async fn handler() -> pavex::response::Response {
let v0 = <app::A as app::MyTrait>::a_method_that_returns_self();
let v1 = <app::A as app::MyTrait>::a_method_that_borrows_self(
&v0,
let v0 = <app::F as core::default::Default>::default();
let v1 = <app::A as app::MyTrait>::a_method_that_returns_self();
let v2 = <app::A as app::MyTrait>::a_method_that_borrows_self(
&v1,
);
let v2 = <app::B as app::AnotherTrait>::a_method_that_consumes_self(
v1,
let v3 = <app::B as app::AnotherTrait>::a_method_that_consumes_self(
v2,
);
let v3 = <app::C as app::GenericTrait<
let v4 = <app::C as app::GenericTrait<
std::string::String,
>>::a_method(&v2);
let v4 = <app::A as app::MyTrait>::a_method_with_a_generic::<
>>::a_method(&v3);
let v5 = <app::A as app::MyTrait>::a_method_with_a_generic::<
std::string::String,
>(&v0);
let v5 = app::handler(v0, v2, v4, v3);
<pavex::response::Response as pavex::response::IntoResponse>::into_response(v5)
>(&v1);
let v6 = app::handler(v1, v3, v5, v4, v0);
<pavex::response::Response as pavex::response::IntoResponse>::into_response(v6)
}
struct Next0<T>
where
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
digraph "GET /home - 0" {
digraph "GET / - 0" {
0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next<crate::route_0::Next0>) -> pavex::response::Response"]
1 [ label = "pavex::middleware::Next::new(crate::route_0::Next0) -> pavex::middleware::Next<crate::route_0::Next0>"]
2 [ label = "crate::route_0::Next0() -> crate::route_0::Next0"]
Expand All @@ -8,26 +8,28 @@ digraph "GET /home - 0" {
0 -> 3 [ ]
}

digraph "GET /home - 1" {
0 [ label = "app::handler(app::A, app::C, app::D, app::E) -> pavex::response::Response"]
digraph "GET / - 1" {
0 [ label = "app::handler(app::A, app::C, app::D, app::E, app::F) -> pavex::response::Response"]
1 [ label = "<app::A as app::MyTrait>::a_method_that_returns_self() -> app::A"]
2 [ label = "<app::B as app::AnotherTrait>::a_method_that_consumes_self(app::B) -> app::C"]
3 [ label = "<app::A as app::MyTrait>::a_method_with_a_generic::<std::string::String>(&app::A) -> app::D"]
4 [ label = "<app::C as app::GenericTrait::<std::string::String>>::a_method(&app::C) -> app::E"]
5 [ label = "<app::A as app::MyTrait>::a_method_that_borrows_self(&app::A) -> app::B"]
6 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
5 [ label = "<app::F as core::default::Default>::default() -> app::F"]
6 [ label = "<app::A as app::MyTrait>::a_method_that_borrows_self(&app::A) -> app::B"]
7 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
5 -> 0 [ ]
4 -> 0 [ ]
2 -> 4 [ label = "&"]
5 -> 2 [ ]
1 -> 5 [ label = "&"]
6 -> 2 [ ]
1 -> 6 [ label = "&"]
3 -> 0 [ ]
1 -> 3 [ label = "&"]
2 -> 0 [ ]
1 -> 0 [ ]
0 -> 6 [ ]
0 -> 7 [ ]
}

digraph "* /home - 0" {
digraph "* / - 0" {
0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next<crate::route_1::Next0<'a>>) -> pavex::response::Response"]
1 [ label = "pavex::middleware::Next::new(crate::route_1::Next0<'a>) -> pavex::middleware::Next<crate::route_1::Next0<'a>>"]
2 [ label = "crate::route_1::Next0(&'a pavex::router::AllowedMethods) -> crate::route_1::Next0<'a>"]
Expand All @@ -39,7 +41,7 @@ digraph "* /home - 0" {
5 -> 2 [ ]
}

digraph "* /home - 1" {
digraph "* / - 1" {
0 [ label = "pavex::router::default_fallback(&pavex::router::AllowedMethods) -> pavex::response::Response"]
2 [ label = "<pavex::response::Response as pavex::response::IntoResponse>::into_response(pavex::response::Response) -> pavex::response::Response"]
3 [ label = "&pavex::router::AllowedMethods"]
Expand Down
42 changes: 19 additions & 23 deletions libs/ui_tests/reflection/trait_methods_are_supported/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint};
use pavex::blueprint::{router::GET, Blueprint};
use pavex::f;

pub struct A;
Expand All @@ -11,6 +11,9 @@ pub struct D;

pub struct E;

#[derive(Default)]
pub struct F;

pub trait MyTrait {
fn a_method_that_returns_self() -> Self;
fn a_method_that_borrows_self(&self) -> B;
Expand Down Expand Up @@ -49,32 +52,25 @@ impl<T> GenericTrait<T> for C {
}
}

pub fn handler(_a: A, _c: C, _d: D, _e: E) -> pavex::response::Response {
pub fn handler(_a: A, _c: C, _d: D, _e: E, _f: F) -> pavex::response::Response {
todo!()
}

pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.constructor(
f!(<crate::A as crate::MyTrait>::a_method_that_returns_self),
Lifecycle::RequestScoped,
);
bp.constructor(
f!(<crate::A as crate::MyTrait>::a_method_that_borrows_self),
Lifecycle::RequestScoped,
);
bp.constructor(
f!(<crate::A as crate::MyTrait>::a_method_with_a_generic::<std::string::String>),
Lifecycle::RequestScoped,
);
bp.constructor(
f!(<crate::B as crate::AnotherTrait>::a_method_that_consumes_self),
Lifecycle::RequestScoped,
);
bp.constructor(
f!(<crate::C as crate::GenericTrait<std::string::String>>::a_method),
Lifecycle::RequestScoped,
);
bp.route(GET, "/home", f!(crate::handler));
// A foreign trait, from `std`.
bp.request_scoped(f!(<crate::F as std::default::Default>::default));
bp.request_scoped(f!(<crate::A as crate::MyTrait>::a_method_that_returns_self));
bp.request_scoped(f!(<crate::A as crate::MyTrait>::a_method_that_borrows_self));
bp.request_scoped(f!(<crate::A as crate::MyTrait>::a_method_with_a_generic::<
std::string::String,
>));
bp.request_scoped(f!(
<crate::B as crate::AnotherTrait>::a_method_that_consumes_self
));
bp.request_scoped(f!(
<crate::C as crate::GenericTrait<std::string::String>>::a_method
));
bp.route(GET, "/", f!(crate::handler));
bp
}

0 comments on commit 1befce5

Please sign in to comment.