Skip to content

Commit

Permalink
add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Jun 8, 2024
1 parent a991527 commit af5c597
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ fn basic_parsing() {
}
}

#[test]
fn link_with_username() {
let link = "https://[email protected]";
let Ok((rest, link_destination)) = LinkDestination::parse(link) else {
panic!("Parsing {} as link failed", link);
};

assert!(link_destination.punycode.is_none());
assert_eq!(rest.len(), 0);
assert_eq!(link_destination.scheme, "https");
assert_eq!(link_destination.target, "https://[email protected]");
assert_eq!(link_destination.hostname, Some("example.com"));

}

#[test]
fn link_with_username_and_password() {
let link = "https://slaux:[email protected]";
let Ok((rest, link_destination)) = LinkDestination::parse(link) else {
panic!("Parsing {} as link failed", link);
};

assert!(link_destination.punycode.is_none());
assert_eq!(rest.len(), 0);
assert_eq!(link_destination.scheme, "https");
assert_eq!(link_destination.target, "https://slaux:[email protected]");
assert_eq!(link_destination.hostname, Some("example.com"));
}

#[test]
fn bare_scheme_no_parse() {
// bare scheme shouldn't be linkified
Expand Down Expand Up @@ -159,3 +188,16 @@ fn generic_schemes() {
}
);
}


#[test]
fn dclogin_link() {
let link = "dclogin://[email protected]?p=L%265j%3A%40g%3C3%5C%5Crr&v=1";
let Ok((rest, link_destination)) = LinkDestination::parse(link) else {
panic!("Cannot parse {} as link", link);
};
assert_eq!(rest.len(), 0);
assert!(link_destination.punycode.is_none());
assert_eq!(link_destination.scheme, "dclogin");
assert_eq!(link_destination.target, link);
}

0 comments on commit af5c597

Please sign in to comment.