@@ -3,29 +3,32 @@ use rocket::local::Client;
3
3
async fn test ( uri : String , expected : String ) {
4
4
let rocket = rocket:: ignite ( ) . mount ( "/" , routes ! [ super :: hello, super :: hi] ) ;
5
5
let client = Client :: new ( rocket) . unwrap ( ) ;
6
- let mut response = client. get ( & uri) . dispatch ( ) . await ;
6
+ let mut response = client. get ( uri) . dispatch ( ) . await ;
7
7
assert_eq ! ( response. body_string( ) . await , Some ( expected) ) ;
8
8
}
9
9
10
10
#[ rocket:: async_test]
11
11
async fn test_hello ( ) {
12
12
for & ( name, age) in & [ ( "Mike" , 22 ) , ( "Michael" , 80 ) , ( "A" , 0 ) , ( "a" , 127 ) ] {
13
- test ( format ! ( "/hello/{}/{}" , name, age) ,
14
- format ! ( "Hello, {} year old named {}!" , age, name) ) . await ;
13
+ let uri = format ! ( "/hello/{}/{}" , name, age) ;
14
+ let expected = format ! ( "Hello, {} year old named {}!" , age, name) ;
15
+ test ( uri, expected) . await ;
15
16
}
16
17
}
17
18
18
19
#[ rocket:: async_test]
19
20
async fn test_failing_hello_hi ( ) {
20
21
// Invalid integers.
21
22
for & ( name, age) in & [ ( "Mike" , 1000 ) , ( "Michael" , 128 ) , ( "A" , -800 ) , ( "a" , -200 ) ] {
22
- test ( format ! ( "/hello/{}/{}" , name, age) ,
23
- format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ) . await ;
23
+ let uri = format ! ( "/hello/{}/{}" , name, age) ;
24
+ let expected = format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ;
25
+ test ( uri, expected) . await ;
24
26
}
25
27
26
28
// Non-integers.
27
29
for & ( name, age) in & [ ( "Mike" , "!" ) , ( "Michael" , "hi" ) , ( "A" , "blah" ) , ( "a" , "0-1" ) ] {
28
- test ( format ! ( "/hello/{}/{}" , name, age) ,
29
- format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ) . await ;
30
+ let uri = format ! ( "/hello/{}/{}" , name, age) ;
31
+ let expected = format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ;
32
+ test ( uri, expected) . await ;
30
33
}
31
34
}
0 commit comments