Skip to content

Commit 465ec23

Browse files
committed
liburl: cosmetic test changes.
1 parent feaad62 commit 465ec23

File tree

1 file changed

+113
-97
lines changed

1 file changed

+113
-97
lines changed

src/liburl/lib.rs

+113-97
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ fn query_from_str(rawquery: &str) -> DecodeResult<Query> {
427427
/// # Example
428428
///
429429
/// ```rust
430-
/// let query = vec!(("title".to_string(), "The Village".to_string()),
430+
/// let query = vec![("title".to_string(), "The Village".to_string()),
431431
/// ("north".to_string(), "52.91".to_string()),
432-
/// ("west".to_string(), "4.10".to_string()));
432+
/// ("west".to_string(), "4.10".to_string())];
433433
/// println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
434434
/// ```
435435
pub fn query_to_str(query: &Query) -> String {
@@ -868,87 +868,86 @@ mod tests {
868868
#[test]
869869
fn test_url_parse() {
870870
let url = "http://user:[email protected]:8080/doc/~u?s=v#something";
871+
let u = from_str::<Url>(url).unwrap();
871872

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()));
881880
}
882881

883882
#[test]
884883
fn test_path_parse() {
885884
let path = "/doc/~u?s=v#something";
885+
let u = from_str::<Path>(path).unwrap();
886886

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()));
892890
}
893891

894892
#[test]
895893
fn test_url_parse_host_slash() {
896894
let urlstr = "http://0.42.42.42/";
897895
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());
900898
}
901899

902900
#[test]
903901
fn test_path_parse_host_slash() {
904902
let pathstr = "/";
905903
let path = from_str::<Path>(pathstr).unwrap();
906-
assert!(path.path == "/".to_string());
904+
assert_eq!(path.path, "/".to_string());
907905
}
908906

909907
#[test]
910908
fn test_url_host_with_port() {
911909
let urlstr = "scheme://host:1234";
912910
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));
916914
// 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+
918917
let urlstr = "scheme://host:1234/";
919918
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());
924923
}
925924

926925
#[test]
927926
fn test_url_with_underscores() {
928927
let urlstr = "http://dotcom.com/file_name.html";
929928
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());
931930
}
932931

933932
#[test]
934933
fn test_path_with_underscores() {
935934
let pathstr = "/file_name.html";
936935
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());
938937
}
939938

940939
#[test]
941940
fn test_url_with_dashes() {
942941
let urlstr = "http://dotcom.com/file-name.html";
943942
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());
945944
}
946945

947946
#[test]
948947
fn test_path_with_dashes() {
949948
let pathstr = "/file-name.html";
950949
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());
952951
}
953952

954953
#[test]
@@ -965,62 +964,72 @@ mod tests {
965964
#[test]
966965
fn test_full_url_parse_and_format() {
967966
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);
969969
}
970970

971971
#[test]
972972
fn test_userless_url_parse_and_format() {
973973
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);
975976
}
976977

977978
#[test]
978979
fn test_queryless_url_parse_and_format() {
979980
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);
981983
}
982984

983985
#[test]
984986
fn test_empty_query_url_parse_and_format() {
985987
let url = "http://user:[email protected]/doc?#something";
986988
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);
988991
}
989992

990993
#[test]
991994
fn test_fragmentless_url_parse_and_format() {
992995
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);
994998
}
995999

9961000
#[test]
9971001
fn test_minimal_url_parse_and_format() {
9981002
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);
10001005
}
10011006

10021007
#[test]
10031008
fn test_url_with_port_parse_and_format() {
10041009
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);
10061012
}
10071013

10081014
#[test]
10091015
fn test_scheme_host_only_url_parse_and_format() {
10101016
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);
10121019
}
10131020

10141021
#[test]
10151022
fn test_pathless_url_parse_and_format() {
10161023
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);
10181026
}
10191027

10201028
#[test]
10211029
fn test_scheme_host_fragment_only_url_parse_and_format() {
10221030
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);
10241033
}
10251034

10261035
#[test]
@@ -1042,68 +1051,75 @@ mod tests {
10421051
#[test]
10431052
fn test_url_without_authority() {
10441053
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);
10461056
}
10471057

10481058
#[test]
10491059
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");
10761090
}
10771091

10781092
#[test]
10791093
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");
11071123
}
11081124

11091125
#[test]
@@ -1189,8 +1205,8 @@ mod tests {
11891205

11901206
let mut m = HashMap::new();
11911207
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());
11941210
}
11951211

11961212
#[test]

0 commit comments

Comments
 (0)