Skip to content

Commit

Permalink
url/tests/unit: add tests for the has_authority and authority methods
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Martinez Ruiz <amr@redhat.com>
  • Loading branch information
unleashed committed Feb 9, 2021
1 parent 36485a9 commit 104d85c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,47 @@ fn pop_if_empty_in_bounds() {
segments.pop_if_empty();
segments.pop();
}

#[test]
fn test_has_authority() {
let url = Url::parse("mailto:joe@example.com").unwrap();
assert!(!url.has_authority());
let url = Url::parse("unix:/run/foo.socket").unwrap();
assert!(!url.has_authority());
let url = Url::parse("file:///tmp/foo").unwrap();
assert!(url.has_authority());
let url = Url::parse("http://example.com/tmp/foo").unwrap();
assert!(url.has_authority());
}

#[test]
fn test_authority() {
let url = Url::parse("mailto:joe@example.com").unwrap();
assert_eq!(url.authority(), "");
let url = Url::parse("unix:/run/foo.socket").unwrap();
assert_eq!(url.authority(), "");
let url = Url::parse("file:///tmp/foo").unwrap();
assert_eq!(url.authority(), "");
let url = Url::parse("http://example.com/tmp/foo").unwrap();
assert_eq!(url.authority(), "example.com");
let url = Url::parse("ftp://127.0.0.1:21/").unwrap();
assert_eq!(url.authority(), "127.0.0.1");
let url = Url::parse("ftp://user@127.0.0.1:2121/").unwrap();
assert_eq!(url.authority(), "user@127.0.0.1:2121");
let url = Url::parse("https://:@example.com/").unwrap();
assert_eq!(url.authority(), "example.com");
let url = Url::parse("https://:password@[::1]:8080/").unwrap();
assert_eq!(url.authority(), ":password@[::1]:8080");
let url = Url::parse("gopher://user:@àlex.example.com:70").unwrap();
assert_eq!(url.authority(), "user@%C3%A0lex.example.com:70");
let url = Url::parse("irc://àlex:àlex@àlex.рф.example.com:6667/foo").unwrap();
assert_eq!(
url.authority(),
"%C3%A0lex:%C3%A0lex@%C3%A0lex.%D1%80%D1%84.example.com:6667"
);
let url = Url::parse("https://àlex:àlex@àlex.рф.example.com:443/foo").unwrap();
assert_eq!(
url.authority(),
"%C3%A0lex:%C3%A0lex@xn--lex-8ka.xn--p1ai.example.com"
);
}

0 comments on commit 104d85c

Please sign in to comment.