@@ -3,32 +3,29 @@ 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
- let uri = format ! ( "/hello/{}/{}" , name, age) ;
14
- let expected = format ! ( "Hello, {} year old named {}!" , age, name) ;
15
- test ( uri, expected) . await ;
13
+ test ( format ! ( "/hello/{}/{}" , name, age) ,
14
+ format ! ( "Hello, {} year old named {}!" , age, name) ) . await ;
16
15
}
17
16
}
18
17
19
18
#[ rocket:: async_test]
20
19
async fn test_failing_hello_hi ( ) {
21
20
// Invalid integers.
22
21
for & ( name, age) in & [ ( "Mike" , 1000 ) , ( "Michael" , 128 ) , ( "A" , -800 ) , ( "a" , -200 ) ] {
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 ;
22
+ test ( format ! ( "/hello/{}/{}" , name, age) ,
23
+ format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ) . await ;
26
24
}
27
25
28
26
// Non-integers.
29
27
for & ( name, age) in & [ ( "Mike" , "!" ) , ( "Michael" , "hi" ) , ( "A" , "blah" ) , ( "a" , "0-1" ) ] {
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 ;
28
+ test ( format ! ( "/hello/{}/{}" , name, age) ,
29
+ format ! ( "Hi {}! Your age ({}) is kind of funky." , name, age) ) . await ;
33
30
}
34
31
}
0 commit comments