@@ -371,35 +371,51 @@ impl fmt::Display for InvalidMethod {
371371
372372impl Error for InvalidMethod { }
373373
374- #[ test]
375- fn test_method_eq ( ) {
376- assert_eq ! ( Method :: GET , Method :: GET ) ;
377- assert_eq ! ( Method :: GET , "GET" ) ;
378- assert_eq ! ( & Method :: GET , "GET" ) ;
374+ #[ cfg( test) ]
375+ mod test {
376+ use super :: * ;
379377
380- assert_eq ! ( "GET" , Method :: GET ) ;
381- assert_eq ! ( "GET" , & Method :: GET ) ;
378+ #[ test]
379+ fn test_method_eq ( ) {
380+ assert_eq ! ( Method :: GET , Method :: GET ) ;
381+ assert_eq ! ( Method :: GET , "GET" ) ;
382+ assert_eq ! ( & Method :: GET , "GET" ) ;
382383
383- assert_eq ! ( & Method :: GET , Method :: GET ) ;
384- assert_eq ! ( Method :: GET , & Method :: GET ) ;
385- }
384+ assert_eq ! ( "GET" , Method :: GET ) ;
385+ assert_eq ! ( "GET" , & Method :: GET ) ;
386386
387- #[ test]
388- fn test_invalid_method ( ) {
389- assert ! ( Method :: from_str( "" ) . is_err( ) ) ;
390- assert ! ( Method :: from_bytes( b"" ) . is_err( ) ) ;
391- }
387+ assert_eq ! ( & Method :: GET , Method :: GET ) ;
388+ assert_eq ! ( Method :: GET , & Method :: GET ) ;
389+ }
390+
391+ #[ test]
392+ fn test_invalid_method ( ) {
393+ assert ! ( Method :: from_str( "" ) . is_err( ) ) ;
394+ assert ! ( Method :: from_bytes( b"" ) . is_err( ) ) ;
395+ assert ! ( Method :: from_bytes( & [ 0xC0 ] ) . is_err( ) ) ; // invalid utf-8
396+ assert ! ( Method :: from_bytes( & [ 0x10 ] ) . is_err( ) ) ; // invalid method characters
397+ }
392398
393- #[ test]
394- fn test_is_idempotent ( ) {
395- assert ! ( Method :: OPTIONS . is_idempotent( ) ) ;
396- assert ! ( Method :: GET . is_idempotent( ) ) ;
397- assert ! ( Method :: PUT . is_idempotent( ) ) ;
398- assert ! ( Method :: DELETE . is_idempotent( ) ) ;
399- assert ! ( Method :: HEAD . is_idempotent( ) ) ;
400- assert ! ( Method :: TRACE . is_idempotent( ) ) ;
401-
402- assert ! ( !Method :: POST . is_idempotent( ) ) ;
403- assert ! ( !Method :: CONNECT . is_idempotent( ) ) ;
404- assert ! ( !Method :: PATCH . is_idempotent( ) ) ;
399+ #[ test]
400+ fn test_is_idempotent ( ) {
401+ assert ! ( Method :: OPTIONS . is_idempotent( ) ) ;
402+ assert ! ( Method :: GET . is_idempotent( ) ) ;
403+ assert ! ( Method :: PUT . is_idempotent( ) ) ;
404+ assert ! ( Method :: DELETE . is_idempotent( ) ) ;
405+ assert ! ( Method :: HEAD . is_idempotent( ) ) ;
406+ assert ! ( Method :: TRACE . is_idempotent( ) ) ;
407+
408+ assert ! ( !Method :: POST . is_idempotent( ) ) ;
409+ assert ! ( !Method :: CONNECT . is_idempotent( ) ) ;
410+ assert ! ( !Method :: PATCH . is_idempotent( ) ) ;
411+ }
412+
413+ #[ test]
414+ fn test_extention_method ( ) {
415+ assert_eq ! ( Method :: from_str( "WOW" ) . unwrap( ) , "WOW" ) ;
416+ assert_eq ! ( Method :: from_str( "wOw!!" ) . unwrap( ) , "wOw!!" ) ;
417+
418+ let long_method = "This_is_a_very_long_method.It_is_valid_but_unlikely." ;
419+ assert_eq ! ( Method :: from_str( & long_method) . unwrap( ) , long_method) ;
420+ }
405421}
0 commit comments