@@ -22,18 +22,22 @@ async fn add_two(req: Request<()>) -> Result<String, tide::Error> {
22
22
Ok ( ( one + two) . to_string ( ) )
23
23
}
24
24
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 " ) {
27
27
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 ( ) ) ,
32
36
}
33
37
}
34
38
35
39
#[ async_std:: test]
36
- async fn wildcard ( ) -> tide:: Result < ( ) > {
40
+ async fn param ( ) -> tide:: Result < ( ) > {
37
41
let mut app = tide:: Server :: new ( ) ;
38
42
app. at ( "/add_one/:num" ) . get ( add_one) ;
39
43
assert_eq ! ( app. get( "/add_one/3" ) . recv_string( ) . await ?, "4" ) ;
@@ -61,20 +65,21 @@ async fn not_found_error() -> tide::Result<()> {
61
65
}
62
66
63
67
#[ async_std:: test]
64
- async fn wild_path ( ) -> tide:: Result < ( ) > {
68
+ async fn wildcard ( ) -> tide:: Result < ( ) > {
65
69
let mut app = tide:: new ( ) ;
66
- app. at ( "/echo/*path " ) . get ( echo_path ) ;
70
+ app. at ( "/echo/*" ) . get ( echo_wildcard ) ;
67
71
assert_eq ! ( app. get( "/echo/some_path" ) . recv_string( ) . await ?, "some_path" ) ;
68
72
assert_eq ! (
69
73
app. get( "/echo/multi/segment/path" ) . recv_string( ) . await ?,
70
74
"multi/segment/path"
71
75
) ;
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 ) ;
73
78
Ok ( ( ) )
74
79
}
75
80
76
81
#[ async_std:: test]
77
- async fn multi_wildcard ( ) -> tide:: Result < ( ) > {
82
+ async fn multi_param ( ) -> tide:: Result < ( ) > {
78
83
let mut app = tide:: new ( ) ;
79
84
app. at ( "/add_two/:one/:two/" ) . get ( add_two) ;
80
85
assert_eq ! ( app. get( "/add_two/1/2/" ) . recv_string( ) . await ?, "3" ) ;
@@ -84,9 +89,9 @@ async fn multi_wildcard() -> tide::Result<()> {
84
89
}
85
90
86
91
#[ async_std:: test]
87
- async fn wild_last_segment ( ) -> tide:: Result < ( ) > {
92
+ async fn wildcard_last_segment ( ) -> tide:: Result < ( ) > {
88
93
let mut app = tide:: new ( ) ;
89
- app. at ( "/echo/:path /*" ) . get ( echo_path ) ;
94
+ app. at ( "/echo/:param /*" ) . get ( echo_param ) ;
90
95
assert_eq ! ( app. get( "/echo/one/two" ) . recv_string( ) . await ?, "one" ) ;
91
96
assert_eq ! (
92
97
app. get( "/echo/one/two/three/four" ) . recv_string( ) . await ?,
@@ -95,50 +100,6 @@ async fn wild_last_segment() -> tide::Result<()> {
95
100
Ok ( ( ) )
96
101
}
97
102
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
-
142
103
#[ async_std:: test]
143
104
async fn ambiguous_router_wildcard_vs_star ( ) -> tide:: Result < ( ) > {
144
105
let mut app = tide:: new ( ) ;
0 commit comments