@@ -427,9 +427,9 @@ fn query_from_str(rawquery: &str) -> DecodeResult<Query> {
427
427
/// # Example
428
428
///
429
429
/// ```rust
430
- /// let query = vec!( ("title".to_string(), "The Village".to_string()),
430
+ /// let query = vec![ ("title".to_string(), "The Village".to_string()),
431
431
/// ("north".to_string(), "52.91".to_string()),
432
- /// ("west".to_string(), "4.10".to_string())) ;
432
+ /// ("west".to_string(), "4.10".to_string())] ;
433
433
/// println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
434
434
/// ```
435
435
pub fn query_to_str ( query : & Query ) -> String {
@@ -868,87 +868,86 @@ mod tests {
868
868
#[ test]
869
869
fn test_url_parse ( ) {
870
870
let url =
"http://user:[email protected] :8080/doc/~u?s=v#something" ;
871
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
871
872
872
- let up = from_str :: < Url > ( url) ;
873
- let u = up. unwrap ( ) ;
874
- assert_eq ! ( & u. scheme, & "http" . to_string( ) ) ;
875
- assert_eq ! ( & u. user, & Some ( UserInfo :: new( "user" . to_string( ) , Some ( "pass" . to_string( ) ) ) ) ) ;
876
- assert_eq ! ( & u. host, & "rust-lang.org" . to_string( ) ) ;
877
- assert_eq ! ( & u. port, & Some ( 8080 ) ) ;
878
- assert_eq ! ( & u. path. path, & "/doc/~u" . to_string( ) ) ;
879
- assert_eq ! ( & u. path. query, & vec!( ( "s" . to_string( ) , "v" . to_string( ) ) ) ) ;
880
- assert_eq ! ( & u. path. fragment, & Some ( "something" . to_string( ) ) ) ;
873
+ assert_eq ! ( u. scheme, "http" . to_string( ) ) ;
874
+ assert_eq ! ( u. user, Some ( UserInfo :: new( "user" . to_string( ) , Some ( "pass" . to_string( ) ) ) ) ) ;
875
+ assert_eq ! ( u. host, "rust-lang.org" . to_string( ) ) ;
876
+ assert_eq ! ( u. port, Some ( 8080 ) ) ;
877
+ assert_eq ! ( u. path. path, "/doc/~u" . to_string( ) ) ;
878
+ assert_eq ! ( u. path. query, vec!( ( "s" . to_string( ) , "v" . to_string( ) ) ) ) ;
879
+ assert_eq ! ( u. path. fragment, Some ( "something" . to_string( ) ) ) ;
881
880
}
882
881
883
882
#[ test]
884
883
fn test_path_parse ( ) {
885
884
let path = "/doc/~u?s=v#something" ;
885
+ let u = from_str :: < Path > ( path) . unwrap ( ) ;
886
886
887
- let up = from_str :: < Path > ( path) ;
888
- let u = up. unwrap ( ) ;
889
- assert_eq ! ( & u. path, & "/doc/~u" . to_string( ) ) ;
890
- assert_eq ! ( & u. query, & vec!( ( "s" . to_string( ) , "v" . to_string( ) ) ) ) ;
891
- assert_eq ! ( & u. fragment, & Some ( "something" . to_string( ) ) ) ;
887
+ assert_eq ! ( u. path, "/doc/~u" . to_string( ) ) ;
888
+ assert_eq ! ( u. query, vec!( ( "s" . to_string( ) , "v" . to_string( ) ) ) ) ;
889
+ assert_eq ! ( u. fragment, Some ( "something" . to_string( ) ) ) ;
892
890
}
893
891
894
892
#[ test]
895
893
fn test_url_parse_host_slash ( ) {
896
894
let urlstr = "http://0.42.42.42/" ;
897
895
let url = from_str :: < Url > ( urlstr) . unwrap ( ) ;
898
- assert ! ( url. host == "0.42.42.42" . to_string( ) ) ;
899
- assert ! ( url. path. path == "/" . to_string( ) ) ;
896
+ assert_eq ! ( url. host, "0.42.42.42" . to_string( ) ) ;
897
+ assert_eq ! ( url. path. path, "/" . to_string( ) ) ;
900
898
}
901
899
902
900
#[ test]
903
901
fn test_path_parse_host_slash ( ) {
904
902
let pathstr = "/" ;
905
903
let path = from_str :: < Path > ( pathstr) . unwrap ( ) ;
906
- assert ! ( path. path == "/" . to_string( ) ) ;
904
+ assert_eq ! ( path. path, "/" . to_string( ) ) ;
907
905
}
908
906
909
907
#[ test]
910
908
fn test_url_host_with_port ( ) {
911
909
let urlstr = "scheme://host:1234" ;
912
910
let url = from_str :: < Url > ( urlstr) . unwrap ( ) ;
913
- assert_eq ! ( & url. scheme, & "scheme" . to_string( ) ) ;
914
- assert_eq ! ( & url. host, & "host" . to_string( ) ) ;
915
- assert_eq ! ( & url. port, & Some ( 1234 ) ) ;
911
+ assert_eq ! ( url. scheme, "scheme" . to_string( ) ) ;
912
+ assert_eq ! ( url. host, "host" . to_string( ) ) ;
913
+ assert_eq ! ( url. port, Some ( 1234 ) ) ;
916
914
// is empty path really correct? Other tests think so
917
- assert_eq ! ( & url. path. path, & "" . to_string( ) ) ;
915
+ assert_eq ! ( url. path. path, "" . to_string( ) ) ;
916
+
918
917
let urlstr = "scheme://host:1234/" ;
919
918
let url = from_str :: < Url > ( urlstr) . unwrap ( ) ;
920
- assert_eq ! ( & url. scheme, & "scheme" . to_string( ) ) ;
921
- assert_eq ! ( & url. host, & "host" . to_string( ) ) ;
922
- assert_eq ! ( & url. port, & Some ( 1234 ) ) ;
923
- assert_eq ! ( & url. path. path, & "/" . to_string( ) ) ;
919
+ assert_eq ! ( url. scheme, "scheme" . to_string( ) ) ;
920
+ assert_eq ! ( url. host, "host" . to_string( ) ) ;
921
+ assert_eq ! ( url. port, Some ( 1234 ) ) ;
922
+ assert_eq ! ( url. path. path, "/" . to_string( ) ) ;
924
923
}
925
924
926
925
#[ test]
927
926
fn test_url_with_underscores ( ) {
928
927
let urlstr = "http://dotcom.com/file_name.html" ;
929
928
let url = from_str :: < Url > ( urlstr) . unwrap ( ) ;
930
- assert ! ( url. path. path == "/file_name.html" . to_string( ) ) ;
929
+ assert_eq ! ( url. path. path, "/file_name.html" . to_string( ) ) ;
931
930
}
932
931
933
932
#[ test]
934
933
fn test_path_with_underscores ( ) {
935
934
let pathstr = "/file_name.html" ;
936
935
let path = from_str :: < Path > ( pathstr) . unwrap ( ) ;
937
- assert ! ( path. path == "/file_name.html" . to_string( ) ) ;
936
+ assert_eq ! ( path. path, "/file_name.html" . to_string( ) ) ;
938
937
}
939
938
940
939
#[ test]
941
940
fn test_url_with_dashes ( ) {
942
941
let urlstr = "http://dotcom.com/file-name.html" ;
943
942
let url = from_str :: < Url > ( urlstr) . unwrap ( ) ;
944
- assert ! ( url. path. path == "/file-name.html" . to_string( ) ) ;
943
+ assert_eq ! ( url. path. path, "/file-name.html" . to_string( ) ) ;
945
944
}
946
945
947
946
#[ test]
948
947
fn test_path_with_dashes ( ) {
949
948
let pathstr = "/file-name.html" ;
950
949
let path = from_str :: < Path > ( pathstr) . unwrap ( ) ;
951
- assert ! ( path. path == "/file-name.html" . to_string( ) ) ;
950
+ assert_eq ! ( path. path, "/file-name.html" . to_string( ) ) ;
952
951
}
953
952
954
953
#[ test]
@@ -965,62 +964,72 @@ mod tests {
965
964
#[ test]
966
965
fn test_full_url_parse_and_format ( ) {
967
966
let url =
"http://user:[email protected] /doc?s=v#something" ;
968
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
967
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
968
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
969
969
}
970
970
971
971
#[ test]
972
972
fn test_userless_url_parse_and_format ( ) {
973
973
let url = "http://rust-lang.org/doc?s=v#something" ;
974
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
974
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
975
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
975
976
}
976
977
977
978
#[ test]
978
979
fn test_queryless_url_parse_and_format ( ) {
979
980
let url =
"http://user:[email protected] /doc#something" ;
980
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
981
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
982
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
981
983
}
982
984
983
985
#[ test]
984
986
fn test_empty_query_url_parse_and_format ( ) {
985
987
let url =
"http://user:[email protected] /doc?#something" ;
986
988
let should_be =
"http://user:[email protected] /doc#something" ;
987
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , should_be) ;
989
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
990
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , should_be) ;
988
991
}
989
992
990
993
#[ test]
991
994
fn test_fragmentless_url_parse_and_format ( ) {
992
995
let url =
"http://user:[email protected] /doc?q=v" ;
993
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
996
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
997
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
994
998
}
995
999
996
1000
#[ test]
997
1001
fn test_minimal_url_parse_and_format ( ) {
998
1002
let url = "http://rust-lang.org/doc" ;
999
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1003
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1004
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1000
1005
}
1001
1006
1002
1007
#[ test]
1003
1008
fn test_url_with_port_parse_and_format ( ) {
1004
1009
let url = "http://rust-lang.org:80/doc" ;
1005
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1010
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1011
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1006
1012
}
1007
1013
1008
1014
#[ test]
1009
1015
fn test_scheme_host_only_url_parse_and_format ( ) {
1010
1016
let url = "http://rust-lang.org" ;
1011
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1017
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1018
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1012
1019
}
1013
1020
1014
1021
#[ test]
1015
1022
fn test_pathless_url_parse_and_format ( ) {
1016
1023
let url =
"http://user:[email protected] ?q=v#something" ;
1017
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1024
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1025
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1018
1026
}
1019
1027
1020
1028
#[ test]
1021
1029
fn test_scheme_host_fragment_only_url_parse_and_format ( ) {
1022
1030
let url = "http://rust-lang.org#something" ;
1023
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1031
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1032
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1024
1033
}
1025
1034
1026
1035
#[ test]
@@ -1042,68 +1051,75 @@ mod tests {
1042
1051
#[ test]
1043
1052
fn test_url_without_authority ( ) {
1044
1053
let url =
"mailto:[email protected] " ;
1045
- assert_eq ! ( from_str:: <Url >( url) . unwrap( ) . to_str( ) . as_slice( ) , url) ;
1054
+ let u = from_str :: < Url > ( url) . unwrap ( ) ;
1055
+ assert_eq ! ( format!( "{}" , u) . as_slice( ) , url) ;
1046
1056
}
1047
1057
1048
1058
#[ test]
1049
1059
fn test_encode ( ) {
1050
- assert_eq ! ( encode( "" ) , "" . to_string( ) ) ;
1051
- assert_eq ! ( encode( "http://example.com" ) , "http://example.com" . to_string( ) ) ;
1052
- assert_eq ! ( encode( "foo bar% baz" ) , "foo%20bar%25%20baz" . to_string( ) ) ;
1053
- assert_eq ! ( encode( " " ) , "%20" . to_string( ) ) ;
1054
- assert_eq ! ( encode( "!" ) , "!" . to_string( ) ) ;
1055
- assert_eq ! ( encode( "\" " ) , "\" " . to_string( ) ) ;
1056
- assert_eq ! ( encode( "#" ) , "#" . to_string( ) ) ;
1057
- assert_eq ! ( encode( "$" ) , "$" . to_string( ) ) ;
1058
- assert_eq ! ( encode( "%" ) , "%25" . to_string( ) ) ;
1059
- assert_eq ! ( encode( "&" ) , "&" . to_string( ) ) ;
1060
- assert_eq ! ( encode( "'" ) , "%27" . to_string( ) ) ;
1061
- assert_eq ! ( encode( "(" ) , "(" . to_string( ) ) ;
1062
- assert_eq ! ( encode( ")" ) , ")" . to_string( ) ) ;
1063
- assert_eq ! ( encode( "*" ) , "*" . to_string( ) ) ;
1064
- assert_eq ! ( encode( "+" ) , "+" . to_string( ) ) ;
1065
- assert_eq ! ( encode( "," ) , "," . to_string( ) ) ;
1066
- assert_eq ! ( encode( "/" ) , "/" . to_string( ) ) ;
1067
- assert_eq ! ( encode( ":" ) , ":" . to_string( ) ) ;
1068
- assert_eq ! ( encode( ";" ) , ";" . to_string( ) ) ;
1069
- assert_eq ! ( encode( "=" ) , "=" . to_string( ) ) ;
1070
- assert_eq ! ( encode( "?" ) , "?" . to_string( ) ) ;
1071
- assert_eq ! ( encode( "@" ) , "@" . to_string( ) ) ;
1072
- assert_eq ! ( encode( "[" ) , "[" . to_string( ) ) ;
1073
- assert_eq ! ( encode( "]" ) , "]" . to_string( ) ) ;
1074
- assert_eq ! ( encode( "\0 " ) , "%00" . to_string( ) ) ;
1075
- assert_eq ! ( encode( "\n " ) , "%0A" . to_string( ) ) ;
1060
+ fn t ( input : & str , expected : & str ) {
1061
+ assert_eq ! ( encode( input) , expected. to_string( ) )
1062
+ }
1063
+
1064
+ t ( "" , "" ) ;
1065
+ t ( "http://example.com" , "http://example.com" ) ;
1066
+ t ( "foo bar% baz" , "foo%20bar%25%20baz" ) ;
1067
+ t ( " " , "%20" ) ;
1068
+ t ( "!" , "!" ) ;
1069
+ t ( "\" " , "\" " ) ;
1070
+ t ( "#" , "#" ) ;
1071
+ t ( "$" , "$" ) ;
1072
+ t ( "%" , "%25" ) ;
1073
+ t ( "&" , "&" ) ;
1074
+ t ( "'" , "%27" ) ;
1075
+ t ( "(" , "(" ) ;
1076
+ t ( ")" , ")" ) ;
1077
+ t ( "*" , "*" ) ;
1078
+ t ( "+" , "+" ) ;
1079
+ t ( "," , "," ) ;
1080
+ t ( "/" , "/" ) ;
1081
+ t ( ":" , ":" ) ;
1082
+ t ( ";" , ";" ) ;
1083
+ t ( "=" , "=" ) ;
1084
+ t ( "?" , "?" ) ;
1085
+ t ( "@" , "@" ) ;
1086
+ t ( "[" , "[" ) ;
1087
+ t ( "]" , "]" ) ;
1088
+ t ( "\0 " , "%00" ) ;
1089
+ t ( "\n " , "%0A" ) ;
1076
1090
}
1077
1091
1078
1092
#[ test]
1079
1093
fn test_encode_component ( ) {
1080
- assert_eq ! ( encode_component( "" ) , "" . to_string( ) ) ;
1081
- assert ! ( encode_component( "http://example.com" ) ==
1082
- "http%3A%2F%2Fexample.com" . to_string( ) ) ;
1083
- assert ! ( encode_component( "foo bar% baz" ) ==
1084
- "foo%20bar%25%20baz" . to_string( ) ) ;
1085
- assert_eq ! ( encode_component( " " ) , "%20" . to_string( ) ) ;
1086
- assert_eq ! ( encode_component( "!" ) , "%21" . to_string( ) ) ;
1087
- assert_eq ! ( encode_component( "#" ) , "%23" . to_string( ) ) ;
1088
- assert_eq ! ( encode_component( "$" ) , "%24" . to_string( ) ) ;
1089
- assert_eq ! ( encode_component( "%" ) , "%25" . to_string( ) ) ;
1090
- assert_eq ! ( encode_component( "&" ) , "%26" . to_string( ) ) ;
1091
- assert_eq ! ( encode_component( "'" ) , "%27" . to_string( ) ) ;
1092
- assert_eq ! ( encode_component( "(" ) , "%28" . to_string( ) ) ;
1093
- assert_eq ! ( encode_component( ")" ) , "%29" . to_string( ) ) ;
1094
- assert_eq ! ( encode_component( "*" ) , "%2A" . to_string( ) ) ;
1095
- assert_eq ! ( encode_component( "+" ) , "%2B" . to_string( ) ) ;
1096
- assert_eq ! ( encode_component( "," ) , "%2C" . to_string( ) ) ;
1097
- assert_eq ! ( encode_component( "/" ) , "%2F" . to_string( ) ) ;
1098
- assert_eq ! ( encode_component( ":" ) , "%3A" . to_string( ) ) ;
1099
- assert_eq ! ( encode_component( ";" ) , "%3B" . to_string( ) ) ;
1100
- assert_eq ! ( encode_component( "=" ) , "%3D" . to_string( ) ) ;
1101
- assert_eq ! ( encode_component( "?" ) , "%3F" . to_string( ) ) ;
1102
- assert_eq ! ( encode_component( "@" ) , "%40" . to_string( ) ) ;
1103
- assert_eq ! ( encode_component( "[" ) , "%5B" . to_string( ) ) ;
1104
- assert_eq ! ( encode_component( "]" ) , "%5D" . to_string( ) ) ;
1105
- assert_eq ! ( encode_component( "\0 " ) , "%00" . to_string( ) ) ;
1106
- assert_eq ! ( encode_component( "\n " ) , "%0A" . to_string( ) ) ;
1094
+ fn t ( input : & str , expected : & str ) {
1095
+ assert_eq ! ( encode_component( input) , expected. to_string( ) )
1096
+ }
1097
+
1098
+ t ( "" , "" ) ;
1099
+ t ( "http://example.com" , "http%3A%2F%2Fexample.com" ) ;
1100
+ t ( "foo bar% baz" , "foo%20bar%25%20baz" ) ;
1101
+ t ( " " , "%20" ) ;
1102
+ t ( "!" , "%21" ) ;
1103
+ t ( "#" , "%23" ) ;
1104
+ t ( "$" , "%24" ) ;
1105
+ t ( "%" , "%25" ) ;
1106
+ t ( "&" , "%26" ) ;
1107
+ t ( "'" , "%27" ) ;
1108
+ t ( "(" , "%28" ) ;
1109
+ t ( ")" , "%29" ) ;
1110
+ t ( "*" , "%2A" ) ;
1111
+ t ( "+" , "%2B" ) ;
1112
+ t ( "," , "%2C" ) ;
1113
+ t ( "/" , "%2F" ) ;
1114
+ t ( ":" , "%3A" ) ;
1115
+ t ( ";" , "%3B" ) ;
1116
+ t ( "=" , "%3D" ) ;
1117
+ t ( "?" , "%3F" ) ;
1118
+ t ( "@" , "%40" ) ;
1119
+ t ( "[" , "%5B" ) ;
1120
+ t ( "]" , "%5D" ) ;
1121
+ t ( "\0 " , "%00" ) ;
1122
+ t ( "\n " , "%0A" ) ;
1107
1123
}
1108
1124
1109
1125
#[ test]
@@ -1189,8 +1205,8 @@ mod tests {
1189
1205
1190
1206
let mut m = HashMap :: new ( ) ;
1191
1207
m. insert ( "foo bar" . to_string ( ) , vec ! ( "abc" . to_string( ) , "12 = 34" . to_string( ) ) ) ;
1192
- assert ! ( encode_form_urlencoded( & m) ==
1193
- "foo+bar=abc&foo+bar=12+%3D+34" . to_string( ) ) ;
1208
+ assert_eq ! ( encode_form_urlencoded( & m) ,
1209
+ "foo+bar=abc&foo+bar=12+%3D+34" . to_string( ) ) ;
1194
1210
}
1195
1211
1196
1212
#[ test]
0 commit comments