From 1befce5ffce0ca2c77ce87ec57a417b3d036da3d Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:40:08 +0100 Subject: [PATCH] chore: Cover foreign traits in tests --- .../diagnostics.dot | 22 +++++----- .../expectations/app.rs | 25 +++++------ .../expectations/diagnostics.dot | 22 +++++----- .../trait_methods_are_supported/src/lib.rs | 42 +++++++++---------- 4 files changed, 56 insertions(+), 55 deletions(-) diff --git a/libs/ui_tests/reflection/trait_methods_are_supported/diagnostics.dot b/libs/ui_tests/reflection/trait_methods_are_supported/diagnostics.dot index 179e9da05..d64bd220a 100644 --- a/libs/ui_tests/reflection/trait_methods_are_supported/diagnostics.dot +++ b/libs/ui_tests/reflection/trait_methods_are_supported/diagnostics.dot @@ -1,4 +1,4 @@ -digraph "GET /home - 0" { +digraph "GET / - 0" { 0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next) -> pavex::response::Response"] 1 [ label = "pavex::middleware::Next::new(crate::route_0::Next0) -> pavex::middleware::Next"] 2 [ label = "crate::route_0::Next0() -> crate::route_0::Next0"] @@ -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 = "::a_method_that_returns_self() -> app_a7fd6a2c::A"] 2 [ label = "::a_method_that_consumes_self(app_a7fd6a2c::B) -> app_a7fd6a2c::C"] 3 [ label = "::a_method_with_a_generic::(&app_a7fd6a2c::A) -> app_a7fd6a2c::D"] 4 [ label = ">::a_method(&app_a7fd6a2c::C) -> app_a7fd6a2c::E"] - 5 [ label = "::a_method_that_borrows_self(&app_a7fd6a2c::A) -> app_a7fd6a2c::B"] - 6 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] + 5 [ label = "::default() -> app_a7fd6a2c::F"] + 6 [ label = "::a_method_that_borrows_self(&app_a7fd6a2c::A) -> app_a7fd6a2c::B"] + 7 [ label = "::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>) -> pavex::response::Response"] 1 [ label = "pavex::middleware::Next::new(crate::route_1::Next0<'a>) -> pavex::middleware::Next>"] 2 [ label = "crate::route_1::Next0(&'a pavex::router::AllowedMethods) -> crate::route_1::Next0<'a>"] @@ -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 = "::into_response(pavex::response::Response) -> pavex::response::Response"] 3 [ label = "&pavex::router::AllowedMethods"] diff --git a/libs/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs b/libs/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs index 1af8c7177..3fe8ba6da 100644 --- a/libs/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs +++ b/libs/ui_tests/reflection/trait_methods_are_supported/expectations/app.rs @@ -23,7 +23,7 @@ pub fn run( } fn build_router() -> pavex_matchit::Router { let mut router = pavex_matchit::Router::new(); - router.insert("/home", 0u32).unwrap(); + router.insert("/", 0u32).unwrap(); router } async fn route_request( @@ -84,21 +84,22 @@ pub mod route_0 { ::into_response(v2) } async fn handler() -> pavex::response::Response { - let v0 = ::a_method_that_returns_self(); - let v1 = ::a_method_that_borrows_self( - &v0, + let v0 = ::default(); + let v1 = ::a_method_that_returns_self(); + let v2 = ::a_method_that_borrows_self( + &v1, ); - let v2 = ::a_method_that_consumes_self( - v1, + let v3 = ::a_method_that_consumes_self( + v2, ); - let v3 = >::a_method(&v2); - let v4 = ::a_method_with_a_generic::< + >>::a_method(&v3); + let v5 = ::a_method_with_a_generic::< std::string::String, - >(&v0); - let v5 = app::handler(v0, v2, v4, v3); - ::into_response(v5) + >(&v1); + let v6 = app::handler(v1, v3, v5, v4, v0); + ::into_response(v6) } struct Next0 where diff --git a/libs/ui_tests/reflection/trait_methods_are_supported/expectations/diagnostics.dot b/libs/ui_tests/reflection/trait_methods_are_supported/expectations/diagnostics.dot index 3528dffa4..cb359cecb 100644 --- a/libs/ui_tests/reflection/trait_methods_are_supported/expectations/diagnostics.dot +++ b/libs/ui_tests/reflection/trait_methods_are_supported/expectations/diagnostics.dot @@ -1,4 +1,4 @@ -digraph "GET /home - 0" { +digraph "GET / - 0" { 0 [ label = "pavex::middleware::wrap_noop(pavex::middleware::Next) -> pavex::response::Response"] 1 [ label = "pavex::middleware::Next::new(crate::route_0::Next0) -> pavex::middleware::Next"] 2 [ label = "crate::route_0::Next0() -> crate::route_0::Next0"] @@ -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 = "::a_method_that_returns_self() -> app::A"] 2 [ label = "::a_method_that_consumes_self(app::B) -> app::C"] 3 [ label = "::a_method_with_a_generic::(&app::A) -> app::D"] 4 [ label = ">::a_method(&app::C) -> app::E"] - 5 [ label = "::a_method_that_borrows_self(&app::A) -> app::B"] - 6 [ label = "::into_response(pavex::response::Response) -> pavex::response::Response"] + 5 [ label = "::default() -> app::F"] + 6 [ label = "::a_method_that_borrows_self(&app::A) -> app::B"] + 7 [ label = "::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>) -> pavex::response::Response"] 1 [ label = "pavex::middleware::Next::new(crate::route_1::Next0<'a>) -> pavex::middleware::Next>"] 2 [ label = "crate::route_1::Next0(&'a pavex::router::AllowedMethods) -> crate::route_1::Next0<'a>"] @@ -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 = "::into_response(pavex::response::Response) -> pavex::response::Response"] 3 [ label = "&pavex::router::AllowedMethods"] diff --git a/libs/ui_tests/reflection/trait_methods_are_supported/src/lib.rs b/libs/ui_tests/reflection/trait_methods_are_supported/src/lib.rs index 181a3f800..32dd0c22f 100644 --- a/libs/ui_tests/reflection/trait_methods_are_supported/src/lib.rs +++ b/libs/ui_tests/reflection/trait_methods_are_supported/src/lib.rs @@ -1,4 +1,4 @@ -use pavex::blueprint::{constructor::Lifecycle, router::GET, Blueprint}; +use pavex::blueprint::{router::GET, Blueprint}; use pavex::f; pub struct A; @@ -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; @@ -49,32 +52,25 @@ impl GenericTrait 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!(::a_method_that_returns_self), - Lifecycle::RequestScoped, - ); - bp.constructor( - f!(::a_method_that_borrows_self), - Lifecycle::RequestScoped, - ); - bp.constructor( - f!(::a_method_with_a_generic::), - Lifecycle::RequestScoped, - ); - bp.constructor( - f!(::a_method_that_consumes_self), - Lifecycle::RequestScoped, - ); - bp.constructor( - f!(>::a_method), - Lifecycle::RequestScoped, - ); - bp.route(GET, "/home", f!(crate::handler)); + // A foreign trait, from `std`. + bp.request_scoped(f!(::default)); + bp.request_scoped(f!(::a_method_that_returns_self)); + bp.request_scoped(f!(::a_method_that_borrows_self)); + bp.request_scoped(f!(::a_method_with_a_generic::< + std::string::String, + >)); + bp.request_scoped(f!( + ::a_method_that_consumes_self + )); + bp.request_scoped(f!( + >::a_method + )); + bp.route(GET, "/", f!(crate::handler)); bp }