Skip to content

Commit d8d4753

Browse files
committed
url/tests/unit: add tests for the has_authority and authority methods
Signed-off-by: Alejandro Martinez Ruiz <[email protected]>
1 parent 8b3ee5a commit d8d4753

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

url/tests/unit.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,3 +1162,47 @@ fn test_make_relative() {
11621162
assert_eq!(make_relative, None, "base: {}, uri: {}", base, uri);
11631163
}
11641164
}
1165+
1166+
#[test]
1167+
fn test_has_authority() {
1168+
let url = Url::parse("mailto:[email protected]").unwrap();
1169+
assert!(!url.has_authority());
1170+
let url = Url::parse("unix:/run/foo.socket").unwrap();
1171+
assert!(!url.has_authority());
1172+
let url = Url::parse("file:///tmp/foo").unwrap();
1173+
assert!(url.has_authority());
1174+
let url = Url::parse("http://example.com/tmp/foo").unwrap();
1175+
assert!(url.has_authority());
1176+
}
1177+
1178+
#[test]
1179+
fn test_authority() {
1180+
let url = Url::parse("mailto:[email protected]").unwrap();
1181+
assert_eq!(url.authority(), "");
1182+
let url = Url::parse("unix:/run/foo.socket").unwrap();
1183+
assert_eq!(url.authority(), "");
1184+
let url = Url::parse("file:///tmp/foo").unwrap();
1185+
assert_eq!(url.authority(), "");
1186+
let url = Url::parse("http://example.com/tmp/foo").unwrap();
1187+
assert_eq!(url.authority(), "example.com");
1188+
let url = Url::parse("ftp://127.0.0.1:21/").unwrap();
1189+
assert_eq!(url.authority(), "127.0.0.1");
1190+
let url = Url::parse("ftp://[email protected]:2121/").unwrap();
1191+
assert_eq!(url.authority(), "[email protected]:2121");
1192+
let url = Url::parse("https://:@example.com/").unwrap();
1193+
assert_eq!(url.authority(), "example.com");
1194+
let url = Url::parse("https://:password@[::1]:8080/").unwrap();
1195+
assert_eq!(url.authority(), ":password@[::1]:8080");
1196+
let url = Url::parse("gopher://user:@àlex.example.com:70").unwrap();
1197+
assert_eq!(url.authority(), "user@%C3%A0lex.example.com:70");
1198+
let url = Url::parse("irc://àlex:àlex@àlex.рф.example.com:6667/foo").unwrap();
1199+
assert_eq!(
1200+
url.authority(),
1201+
"%C3%A0lex:%C3%A0lex@%C3%A0lex.%D1%80%D1%84.example.com:6667"
1202+
);
1203+
let url = Url::parse("https://àlex:àlex@àlex.рф.example.com:443/foo").unwrap();
1204+
assert_eq!(
1205+
url.authority(),
1206+
"%C3%A0lex:%C3%[email protected]"
1207+
);
1208+
}

0 commit comments

Comments
 (0)