-
-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
799 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
use leptos::*; | ||
use leptos_actix::generate_route_list; | ||
use leptos_router::{Route, Router, Routes, TrailingSlash}; | ||
|
||
#[component] | ||
fn DefaultApp() -> impl IntoView { | ||
let view = || view! { "" }; | ||
view! { | ||
<Router> | ||
<Routes> | ||
<Route path="/foo" view/> | ||
<Route path="/bar/" view/> | ||
<Route path="/baz/:id" view/> | ||
<Route path="/baz/:name/" view/> | ||
<Route path="/baz/*any" view/> | ||
</Routes> | ||
</Router> | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_default_app() { | ||
let routes = generate_route_list(DefaultApp); | ||
|
||
// We still have access to the original (albeit normalized) Leptos paths: | ||
assert_same( | ||
&routes, | ||
|r| r.leptos_path(), | ||
&["/bar", "/baz/*any", "/baz/:id", "/baz/:name", "/foo"], | ||
); | ||
|
||
// ... But leptos-actix has also reformatted "paths" to work for Actix. | ||
assert_same( | ||
&routes, | ||
|r| r.path(), | ||
&["/bar", "/baz/{id}", "/baz/{name}", "/baz/{tail:.*}", "/foo"], | ||
); | ||
} | ||
|
||
#[component] | ||
fn ExactApp() -> impl IntoView { | ||
let view = || view! { "" }; | ||
let trailing_slash = TrailingSlash::Exact; | ||
view! { | ||
<Router trailing_slash> | ||
<Routes> | ||
<Route path="/foo" view/> | ||
<Route path="/bar/" view/> | ||
<Route path="/baz/:id" view/> | ||
<Route path="/baz/:name/" view/> | ||
<Route path="/baz/*any" view/> | ||
</Routes> | ||
</Router> | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_exact_app() { | ||
let routes = generate_route_list(ExactApp); | ||
|
||
// In Exact mode, the Leptos paths no longer have their trailing slashes stripped: | ||
assert_same( | ||
&routes, | ||
|r| r.leptos_path(), | ||
&["/bar/", "/baz/*any", "/baz/:id", "/baz/:name/", "/foo"], | ||
); | ||
|
||
// Actix paths also have trailing slashes as a result: | ||
assert_same( | ||
&routes, | ||
|r| r.path(), | ||
&[ | ||
"/bar/", | ||
"/baz/{id}", | ||
"/baz/{name}/", | ||
"/baz/{tail:.*}", | ||
"/foo", | ||
], | ||
); | ||
} | ||
|
||
#[component] | ||
fn RedirectApp() -> impl IntoView { | ||
let view = || view! { "" }; | ||
let trailing_slash = TrailingSlash::Redirect; | ||
view! { | ||
<Router trailing_slash> | ||
<Routes> | ||
<Route path="/foo" view/> | ||
<Route path="/bar/" view/> | ||
<Route path="/baz/:id" view/> | ||
<Route path="/baz/:name/" view/> | ||
<Route path="/baz/*any" view/> | ||
</Routes> | ||
</Router> | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_redirect_app() { | ||
let routes = generate_route_list(RedirectApp); | ||
|
||
assert_same( | ||
&routes, | ||
|r| r.leptos_path(), | ||
&[ | ||
"/bar", | ||
"/bar/", | ||
"/baz/*any", | ||
"/baz/:id", | ||
"/baz/:id/", | ||
"/baz/:name", | ||
"/baz/:name/", | ||
"/foo", | ||
"/foo/", | ||
], | ||
); | ||
|
||
// ... But leptos-actix has also reformatted "paths" to work for Actix. | ||
assert_same( | ||
&routes, | ||
|r| r.path(), | ||
&[ | ||
"/bar", | ||
"/bar/", | ||
"/baz/{id}", | ||
"/baz/{id}/", | ||
"/baz/{name}", | ||
"/baz/{name}/", | ||
"/baz/{tail:.*}", | ||
"/foo", | ||
"/foo/", | ||
], | ||
); | ||
} | ||
|
||
fn assert_same<'t, T, F, U>( | ||
input: &'t Vec<T>, | ||
mapper: F, | ||
expected_sorted_values: &[U], | ||
) where | ||
F: Fn(&'t T) -> U + 't, | ||
U: Ord + std::fmt::Debug, | ||
{ | ||
let mut values: Vec<U> = input.iter().map(mapper).collect(); | ||
values.sort(); | ||
assert_eq!(values, expected_sorted_values); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.