use super::*;
#[test]
fn https_url_passes_through() {
assert_eq!(
normalize("https://github.com/owner/repo").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn http_scheme_is_preserved() {
assert_eq!(
normalize("http://git.example.com/owner/repo").as_deref(),
Some("http://git.example.com/owner/repo"),
);
}
#[test]
fn dot_git_suffix_is_dropped() {
assert_eq!(
normalize("https://github.com/owner/repo.git").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn trailing_slash_is_dropped() {
assert_eq!(
normalize("https://github.com/owner/repo/").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn scp_like_maps_to_https() {
assert_eq!(
normalize("git@github.com:owner/repo.git").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn scp_like_without_user_or_dot_git() {
assert_eq!(
normalize("github.com:owner/repo").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn ssh_url_drops_userinfo_and_port() {
assert_eq!(
normalize("ssh://git@github.com:22/owner/repo.git").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn deep_subgroup_path_is_kept() {
assert_eq!(
normalize("git@gitlab.com:group/subgroup/repo.git").as_deref(),
Some("https://gitlab.com/group/subgroup/repo"),
);
}
#[test]
fn single_segment_path_is_rejected() {
assert_eq!(normalize("https://github.com/owner"), None);
assert_eq!(normalize("git@github.com:owner"), None);
}
#[test]
fn missing_path_is_rejected() {
assert_eq!(normalize("https://github.com"), None);
}
#[test]
fn empty_host_is_rejected() {
assert_eq!(normalize("https://:8443/owner/repo"), None);
assert_eq!(normalize("ssh://:22/owner/repo"), None);
}
#[test]
fn query_and_fragment_are_stripped() {
assert_eq!(
normalize("https://github.com/owner/repo?tab=readme").as_deref(),
Some("https://github.com/owner/repo"),
);
assert_eq!(
normalize("https://github.com/owner/repo#section").as_deref(),
Some("https://github.com/owner/repo"),
);
assert_eq!(
normalize("https://github.com/owner/repo.git?x=1").as_deref(),
Some("https://github.com/owner/repo"),
);
}
#[test]
fn query_before_path_is_rejected() {
assert_eq!(normalize("https://github.com?x=1/owner/repo"), None);
}
#[test]
fn unparseable_input_is_rejected() {
assert_eq!(normalize("not a url"), None);
assert_eq!(normalize(""), None);
}
#[test]
fn http_port_is_preserved() {
assert_eq!(
normalize("https://git.example.com:8443/owner/repo").as_deref(),
Some("https://git.example.com:8443/owner/repo"),
);
}
#[test]
fn ssh_port_is_dropped() {
assert_eq!(
normalize("ssh://git@git.example.com:2222/owner/repo.git").as_deref(),
Some("https://git.example.com/owner/repo"),
);
}
#[test]
fn scheme_match_is_case_insensitive() {
assert_eq!(
normalize("HTTPS://github.com/owner/repo").as_deref(),
Some("https://github.com/owner/repo"),
);
assert_eq!(
normalize("SSH://git@github.com/owner/repo.git").as_deref(),
Some("https://github.com/owner/repo"),
);
}