@@ -22,18 +22,22 @@ async fn add_two(req: Request<()>) -> Result<String, tide::Error> {
2222 Ok ( ( one + two) . to_string ( ) )
2323}
2424
25- async fn echo_path ( req : Request < ( ) > ) -> Result < String , tide:: Error > {
26- match req. param ( "path " ) {
25+ async fn echo_param ( req : Request < ( ) > ) -> tide :: Result < tide:: Response > {
26+ match req. param ( "param " ) {
2727 Ok ( path) => Ok ( path. into ( ) ) ,
28- Err ( mut err) => {
29- err. set_status ( StatusCode :: BadRequest ) ;
30- Err ( err)
31- }
28+ Err ( _) => Ok ( StatusCode :: NotFound . into ( ) ) ,
29+ }
30+ }
31+
32+ async fn echo_wildcard ( req : Request < ( ) > ) -> tide:: Result < tide:: Response > {
33+ match req. wildcard ( ) {
34+ Some ( path) => Ok ( path. into ( ) ) ,
35+ None => Ok ( StatusCode :: NotFound . into ( ) ) ,
3236 }
3337}
3438
3539#[ async_std:: test]
36- async fn wildcard ( ) -> tide:: Result < ( ) > {
40+ async fn param ( ) -> tide:: Result < ( ) > {
3741 let mut app = tide:: Server :: new ( ) ;
3842 app. at ( "/add_one/:num" ) . get ( add_one) ;
3943 assert_eq ! ( app. get( "/add_one/3" ) . recv_string( ) . await ?, "4" ) ;
@@ -61,20 +65,21 @@ async fn not_found_error() -> tide::Result<()> {
6165}
6266
6367#[ async_std:: test]
64- async fn wild_path ( ) -> tide:: Result < ( ) > {
68+ async fn wildcard ( ) -> tide:: Result < ( ) > {
6569 let mut app = tide:: new ( ) ;
66- app. at ( "/echo/*path " ) . get ( echo_path ) ;
70+ app. at ( "/echo/*" ) . get ( echo_wildcard ) ;
6771 assert_eq ! ( app. get( "/echo/some_path" ) . recv_string( ) . await ?, "some_path" ) ;
6872 assert_eq ! (
6973 app. get( "/echo/multi/segment/path" ) . recv_string( ) . await ?,
7074 "multi/segment/path"
7175 ) ;
72- assert_eq ! ( app. get( "/echo/" ) . await ?. status( ) , StatusCode :: NotFound ) ;
76+ assert_eq ! ( app. get( "/echo/" ) . await ?. status( ) , StatusCode :: Ok ) ;
77+ assert_eq ! ( app. get( "/echo" ) . await ?. status( ) , StatusCode :: Ok ) ;
7378 Ok ( ( ) )
7479}
7580
7681#[ async_std:: test]
77- async fn multi_wildcard ( ) -> tide:: Result < ( ) > {
82+ async fn multi_param ( ) -> tide:: Result < ( ) > {
7883 let mut app = tide:: new ( ) ;
7984 app. at ( "/add_two/:one/:two/" ) . get ( add_two) ;
8085 assert_eq ! ( app. get( "/add_two/1/2/" ) . recv_string( ) . await ?, "3" ) ;
@@ -84,9 +89,9 @@ async fn multi_wildcard() -> tide::Result<()> {
8489}
8590
8691#[ async_std:: test]
87- async fn wild_last_segment ( ) -> tide:: Result < ( ) > {
92+ async fn wildcard_last_segment ( ) -> tide:: Result < ( ) > {
8893 let mut app = tide:: new ( ) ;
89- app. at ( "/echo/:path /*" ) . get ( echo_path ) ;
94+ app. at ( "/echo/:param /*" ) . get ( echo_param ) ;
9095 assert_eq ! ( app. get( "/echo/one/two" ) . recv_string( ) . await ?, "one" ) ;
9196 assert_eq ! (
9297 app. get( "/echo/one/two/three/four" ) . recv_string( ) . await ?,
@@ -95,50 +100,6 @@ async fn wild_last_segment() -> tide::Result<()> {
95100 Ok ( ( ) )
96101}
97102
98- #[ async_std:: test]
99- async fn invalid_wildcard ( ) -> tide:: Result < ( ) > {
100- let mut app = tide:: new ( ) ;
101- app. at ( "/echo/*path/:one/" ) . get ( echo_path) ;
102- assert_eq ! (
103- app. get( "/echo/one/two" ) . await ?. status( ) ,
104- StatusCode :: NotFound
105- ) ;
106- Ok ( ( ) )
107- }
108-
109- #[ async_std:: test]
110- async fn nameless_wildcard ( ) -> tide:: Result < ( ) > {
111- let mut app = tide:: Server :: new ( ) ;
112- app. at ( "/echo/:" ) . get ( |_| async { Ok ( "" ) } ) ;
113- assert_eq ! (
114- app. get( "/echo/one/two" ) . await ?. status( ) ,
115- StatusCode :: NotFound
116- ) ;
117- assert_eq ! ( app. get( "/echo/one" ) . await ?. status( ) , StatusCode :: Ok ) ;
118- Ok ( ( ) )
119- }
120-
121- #[ async_std:: test]
122- async fn nameless_internal_wildcard ( ) -> tide:: Result < ( ) > {
123- let mut app = tide:: new ( ) ;
124- app. at ( "/echo/:/:path" ) . get ( echo_path) ;
125- assert_eq ! ( app. get( "/echo/one" ) . await ?. status( ) , StatusCode :: NotFound ) ;
126- assert_eq ! ( app. get( "/echo/one/two" ) . recv_string( ) . await ?, "two" ) ;
127- Ok ( ( ) )
128- }
129-
130- #[ async_std:: test]
131- async fn nameless_internal_wildcard2 ( ) -> tide:: Result < ( ) > {
132- let mut app = tide:: new ( ) ;
133- app. at ( "/echo/:/:path" ) . get ( |req : Request < ( ) > | async move {
134- assert_eq ! ( req. param( "path" ) ?, "two" ) ;
135- Ok ( "" )
136- } ) ;
137-
138- assert ! ( app. get( "/echo/one/two" ) . await ?. status( ) . is_success( ) ) ;
139- Ok ( ( ) )
140- }
141-
142103#[ async_std:: test]
143104async fn ambiguous_router_wildcard_vs_star ( ) -> tide:: Result < ( ) > {
144105 let mut app = tide:: new ( ) ;
0 commit comments