| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- extern crate url;
- use url::Url;
- use url::format::{PathFormatter, UserInfoFormatter};
- #[test]
- fn path_formatting() {
- let data = [
- (vec![], "/"),
- (vec![""], "/"),
- (vec!["test", "path"], "/test/path"),
- (vec!["test", "path", ""], "/test/path/")
- ];
- for &(ref path, result) in &data {
- assert_eq!(PathFormatter {
- path: path
- }.to_string(), result.to_string());
- }
- }
- #[test]
- fn userinfo_formatting() {
- // Test data as (username, password, result) tuples.
- let data = [
- ("", None, ""),
- ("", Some(""), ":@"),
- ("", Some("password"), ":password@"),
- ("username", None, "username@"),
- ("username", Some(""), "username:@"),
- ("username", Some("password"), "username:password@")
- ];
- for &(username, password, result) in &data {
- assert_eq!(UserInfoFormatter {
- username: username,
- password: password
- }.to_string(), result.to_string());
- }
- }
- #[test]
- fn relative_scheme_url_formatting() {
- let data = [
- ("http://example.com/", "http://example.com/"),
- ("http://addslash.com", "http://addslash.com/"),
- ("http://@emptyuser.com/", "http://emptyuser.com/"),
- ("http://:@emptypass.com/", "http://:@emptypass.com/"),
- ("http://user@user.com/", "http://user@user.com/"),
- ("http://user:pass@userpass.com/", "http://user:pass@userpass.com/"),
- ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
- ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
- ];
- for &(input, result) in &data {
- let url = Url::parse(input).unwrap();
- assert_eq!(url.to_string(), result.to_string());
- }
- }
|