git_hosting_providers: Clean up tests (#19927)

This PR cleans up the tests for the various Git hosting providers.

These tests had rotted a bit over time, to the point that some of them
weren't even testing what they claimed anymore.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-29 17:24:32 -04:00 committed by GitHub
parent 518f6b529b
commit 90edb7189f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 356 additions and 445 deletions

2
Cargo.lock generated
View file

@ -4909,11 +4909,11 @@ dependencies = [
"git", "git",
"gpui", "gpui",
"http_client", "http_client",
"indoc",
"pretty_assertions", "pretty_assertions",
"regex", "regex",
"serde", "serde",
"serde_json", "serde_json",
"unindent",
"url", "url",
"util", "util",
] ]

View file

@ -25,6 +25,6 @@ url.workspace = true
util.workspace = true util.workspace = true
[dev-dependencies] [dev-dependencies]
unindent.workspace = true indoc.workspace = true
serde_json.workspace = true serde_json.workspace = true
pretty_assertions.workspace = true pretty_assertions.workspace = true

View file

@ -84,53 +84,62 @@ impl GitHostingProvider for Bitbucket {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::sync::Arc; use pretty_assertions::assert_eq;
use git::{parse_git_remote_url, GitHostingProviderRegistry};
use super::*; use super::*;
#[test] #[test]
fn test_parse_git_remote_url_bitbucket_https_with_username() { fn test_parse_remote_url_given_ssh_url() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new()); let parsed_remote = Bitbucket
provider_registry.register_hosting_provider(Arc::new(Bitbucket)); .parse_remote_url("git@bitbucket.org:zed-industries/zed.git")
let url = "https://thorstenballzed@bitbucket.org/thorstenzed/testingrepo.git"; .unwrap();
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket"); assert_eq!(
assert_eq!(parsed.owner.as_ref(), "thorstenzed"); parsed_remote,
assert_eq!(parsed.repo.as_ref(), "testingrepo"); ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
} }
#[test] #[test]
fn test_parse_git_remote_url_bitbucket_https_without_username() { fn test_parse_remote_url_given_https_url() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new()); let parsed_remote = Bitbucket
provider_registry.register_hosting_provider(Arc::new(Bitbucket)); .parse_remote_url("https://bitbucket.org/zed-industries/zed.git")
let url = "https://bitbucket.org/thorstenzed/testingrepo.git"; .unwrap();
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket"); assert_eq!(
assert_eq!(parsed.owner.as_ref(), "thorstenzed"); parsed_remote,
assert_eq!(parsed.repo.as_ref(), "testingrepo"); ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
} }
#[test] #[test]
fn test_parse_git_remote_url_bitbucket_git() { fn test_parse_remote_url_given_https_url_with_username() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new()); let parsed_remote = Bitbucket
provider_registry.register_hosting_provider(Arc::new(Bitbucket)); .parse_remote_url("https://thorstenballzed@bitbucket.org/zed-industries/zed.git")
let url = "git@bitbucket.org:thorstenzed/testingrepo.git"; .unwrap();
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket"); assert_eq!(
assert_eq!(parsed.owner.as_ref(), "thorstenzed"); parsed_remote,
assert_eq!(parsed.repo.as_ref(), "testingrepo"); ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
} }
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url() { fn test_build_bitbucket_permalink() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
let permalink = Bitbucket.build_permalink( let permalink = Bitbucket.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "f00b4r", sha: "f00b4r",
path: "main.rs", path: "main.rs",
@ -138,18 +147,17 @@ mod tests {
}, },
); );
let expected_url = "https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs"; let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url_single_line_selection() { fn test_build_bitbucket_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
let permalink = Bitbucket.build_permalink( let permalink = Bitbucket.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "f00b4r", sha: "f00b4r",
path: "main.rs", path: "main.rs",
@ -157,19 +165,17 @@ mod tests {
}, },
); );
let expected_url = let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-7";
"https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs#lines-7";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_bitbucket_permalink_from_ssh_url_multi_line_selection() { fn test_build_bitbucket_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
let permalink = Bitbucket.build_permalink( let permalink = Bitbucket.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "f00b4r", sha: "f00b4r",
path: "main.rs", path: "main.rs",
@ -178,7 +184,7 @@ mod tests {
); );
let expected_url = let expected_url =
"https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs#lines-24:48"; "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-24:48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
} }

View file

@ -175,16 +175,47 @@ impl GitHostingProvider for Codeberg {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use pretty_assertions::assert_eq;
use super::*; use super::*;
#[test] #[test]
fn test_build_codeberg_permalink_from_ssh_url() { fn test_parse_remote_url_given_ssh_url() {
let remote = ParsedGitRemote { let parsed_remote = Codeberg
owner: "rajveermalviya".into(), .parse_remote_url("git@codeberg.org:zed-industries/zed.git")
repo: "zed".into(), .unwrap();
};
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Codeberg
.parse_remote_url("https://codeberg.org/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_build_codeberg_permalink() {
let permalink = Codeberg.build_permalink( let permalink = Codeberg.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -192,18 +223,17 @@ mod tests {
}, },
); );
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs"; let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_codeberg_permalink_from_ssh_url_single_line_selection() { fn test_build_codeberg_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Codeberg.build_permalink( let permalink = Codeberg.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -211,18 +241,17 @@ mod tests {
}, },
); );
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_codeberg_permalink_from_ssh_url_multi_line_selection() { fn test_build_codeberg_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Codeberg.build_permalink( let permalink = Codeberg.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -230,64 +259,7 @@ mod tests {
}, },
); );
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L24-L48"; let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L24-L48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_codeberg_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Codeberg.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: None,
},
);
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/zed/src/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_codeberg_permalink_from_https_url_single_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Codeberg.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: Some(6..6),
},
);
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/zed/src/main.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_codeberg_permalink_from_https_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Codeberg.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: Some(23..47),
},
);
let expected_url = "https://codeberg.org/rajveermalviya/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/zed/src/main.rs#L24-L48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
} }

View file

@ -84,16 +84,47 @@ impl GitHostingProvider for Gitee {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use pretty_assertions::assert_eq;
use super::*; use super::*;
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url() { fn test_parse_remote_url_given_ssh_url() {
let remote = ParsedGitRemote { let parsed_remote = Gitee
owner: "libkitten".into(), .parse_remote_url("git@gitee.com:zed-industries/zed.git")
repo: "zed".into(), .unwrap();
};
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Gitee
.parse_remote_url("https://gitee.com/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_build_gitee_permalink() {
let permalink = Gitee.build_permalink( let permalink = Gitee.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -101,18 +132,17 @@ mod tests {
}, },
); );
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs"; let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url_single_line_selection() { fn test_build_gitee_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "libkitten".into(),
repo: "zed".into(),
};
let permalink = Gitee.build_permalink( let permalink = Gitee.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -120,18 +150,17 @@ mod tests {
}, },
); );
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_gitee_permalink_from_ssh_url_multi_line_selection() { fn test_build_gitee_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "libkitten".into(),
repo: "zed".into(),
};
let permalink = Gitee.build_permalink( let permalink = Gitee.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194", sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -139,64 +168,7 @@ mod tests {
}, },
); );
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48"; let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_gitee_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "libkitten".into(),
repo: "zed".into(),
};
let permalink = Gitee.build_permalink(
remote,
BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/zed/src/main.rs",
selection: None,
},
);
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_gitee_permalink_from_https_url_single_line_selection() {
let remote = ParsedGitRemote {
owner: "libkitten".into(),
repo: "zed".into(),
};
let permalink = Gitee.build_permalink(
remote,
BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/zed/src/main.rs",
selection: Some(6..6),
},
);
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_gitee_permalink_from_https_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "libkitten".into(),
repo: "zed".into(),
};
let permalink = Gitee.build_permalink(
remote,
BuildPermalinkParams {
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
path: "crates/zed/src/main.rs",
selection: Some(23..47),
},
);
let expected_url = "https://gitee.com/libkitten/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/zed/src/main.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
} }

View file

@ -197,11 +197,41 @@ impl GitHostingProvider for Github {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// TODO: Replace with `indoc`. use indoc::indoc;
use unindent::Unindent; use pretty_assertions::assert_eq;
use super::*; use super::*;
#[test]
fn test_parse_remote_url_given_ssh_url() {
let parsed_remote = Github
.parse_remote_url("git@github.com:zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Github
.parse_remote_url("https://github.com/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test] #[test]
fn test_parse_remote_url_given_https_url_with_username() { fn test_parse_remote_url_given_https_url_with_username() {
let parsed_remote = Github let parsed_remote = Github
@ -237,51 +267,12 @@ mod tests {
} }
#[test] #[test]
fn test_build_github_permalink_from_ssh_url_single_line_selection() { fn test_build_github_permalink() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Github.build_permalink( let permalink = Github.build_permalink(
remote, ParsedGitRemote {
BuildPermalinkParams { owner: "zed-industries".into(),
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", repo: "zed".into(),
path: "crates/editor/src/git/permalink.rs",
selection: Some(6..6),
}, },
);
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_github_permalink_from_ssh_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Github.build_permalink(
remote,
BuildPermalinkParams {
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/editor/src/git/permalink.rs",
selection: Some(23..47),
},
);
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_github_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Github.build_permalink(
remote,
BuildPermalinkParams { BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
path: "crates/zed/src/main.rs", path: "crates/zed/src/main.rs",
@ -294,40 +285,38 @@ mod tests {
} }
#[test] #[test]
fn test_build_github_permalink_from_https_url_single_line_selection() { fn test_build_github_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Github.build_permalink( let permalink = Github.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/zed/src/main.rs", path: "crates/editor/src/git/permalink.rs",
selection: Some(6..6), selection: Some(6..6),
}, },
); );
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7"; let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_github_permalink_from_https_url_multi_line_selection() { fn test_build_github_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Github.build_permalink( let permalink = Github.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/zed/src/main.rs", path: "crates/editor/src/git/permalink.rs",
selection: Some(23..47), selection: Some(23..47),
}, },
); );
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-L48"; let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
@ -342,7 +331,7 @@ mod tests {
assert!(Github.extract_pull_request(&remote, message).is_none()); assert!(Github.extract_pull_request(&remote, message).is_none());
// Pull request number at end of first line // Pull request number at end of first line
let message = r#" let message = indoc! {r#"
project panel: do not expand collapsed worktrees on "collapse all entries" (#10687) project panel: do not expand collapsed worktrees on "collapse all entries" (#10687)
Fixes #10597 Fixes #10597
@ -351,7 +340,7 @@ mod tests {
- Fixed "project panel: collapse all entries" expanding collapsed worktrees. - Fixed "project panel: collapse all entries" expanding collapsed worktrees.
"# "#
.unindent(); };
assert_eq!( assert_eq!(
Github Github
@ -363,12 +352,12 @@ mod tests {
); );
// Pull request number in middle of line, which we want to ignore // Pull request number in middle of line, which we want to ignore
let message = r#" let message = indoc! {r#"
Follow-up to #10687 to fix problems Follow-up to #10687 to fix problems
See the original PR, this is a fix. See the original PR, this is a fix.
"# "#
.unindent(); };
assert_eq!(Github.extract_pull_request(&remote, &message), None); assert_eq!(Github.extract_pull_request(&remote, &message), None);
} }
} }

View file

@ -131,13 +131,60 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url() { fn test_parse_remote_url_given_ssh_url() {
let remote = ParsedGitRemote { let parsed_remote = Gitlab::new()
owner: "zed-industries".into(), .parse_remote_url("git@gitlab.com:zed-industries/zed.git")
repo: "zed".into(), .unwrap();
};
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Gitlab::new()
.parse_remote_url("https://gitlab.com/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_self_hosted_ssh_url() {
let remote_url = "git@gitlab.my-enterprise.com:zed-industries/zed.git";
let parsed_remote = Gitlab::from_remote_url(remote_url)
.unwrap()
.parse_remote_url(remote_url)
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_build_gitlab_permalink() {
let permalink = Gitlab::new().build_permalink( let permalink = Gitlab::new().build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -150,13 +197,12 @@ mod tests {
} }
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url_single_line_selection() { fn test_build_gitlab_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Gitlab::new().build_permalink( let permalink = Gitlab::new().build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -169,13 +215,12 @@ mod tests {
} }
#[test] #[test]
fn test_build_gitlab_permalink_from_ssh_url_multi_line_selection() { fn test_build_gitlab_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Gitlab::new().build_permalink( let permalink = Gitlab::new().build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -187,74 +232,16 @@ mod tests {
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test]
fn test_build_gitlab_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Gitlab::new().build_permalink(
remote,
BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
path: "crates/zed/src/main.rs",
selection: None,
},
);
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_gitlab_permalink_from_https_url_single_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Gitlab::new().build_permalink(
remote,
BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
path: "crates/zed/src/main.rs",
selection: Some(6..6),
},
);
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_gitlab_permalink_from_https_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let permalink = Gitlab::new().build_permalink(
remote,
BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
path: "crates/zed/src/main.rs",
selection: Some(23..47),
},
);
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test] #[test]
fn test_build_gitlab_self_hosted_permalink_from_ssh_url() { fn test_build_gitlab_self_hosted_permalink_from_ssh_url() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let gitlab = let gitlab =
Gitlab::from_remote_url("git@gitlab.some-enterprise.com:zed-industries/zed.git") Gitlab::from_remote_url("git@gitlab.some-enterprise.com:zed-industries/zed.git")
.unwrap(); .unwrap();
let permalink = gitlab.build_permalink( let permalink = gitlab.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7", sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -268,15 +255,14 @@ mod tests {
#[test] #[test]
fn test_build_gitlab_self_hosted_permalink_from_https_url() { fn test_build_gitlab_self_hosted_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
};
let gitlab = let gitlab =
Gitlab::from_remote_url("https://gitlab-instance.big-co.com/zed-industries/zed.git") Gitlab::from_remote_url("https://gitlab-instance.big-co.com/zed-industries/zed.git")
.unwrap(); .unwrap();
let permalink = gitlab.build_permalink( let permalink = gitlab.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa", sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
path: "crates/zed/src/main.rs", path: "crates/zed/src/main.rs",

View file

@ -39,7 +39,7 @@ impl GitHostingProvider for Sourcehut {
} }
let mut path_segments = url.path_segments()?; let mut path_segments = url.path_segments()?;
let owner = path_segments.next()?; let owner = path_segments.next()?.trim_start_matches('~');
// We don't trim the `.git` suffix here like we do elsewhere, as // We don't trim the `.git` suffix here like we do elsewhere, as
// sourcehut treats a repo with `.git` suffix as a separate repo. // sourcehut treats a repo with `.git` suffix as a separate repo.
// //
@ -89,16 +89,62 @@ impl GitHostingProvider for Sourcehut {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use pretty_assertions::assert_eq;
use super::*; use super::*;
#[test] #[test]
fn test_build_sourcehut_permalink_from_ssh_url() { fn test_parse_remote_url_given_ssh_url() {
let remote = ParsedGitRemote { let parsed_remote = Sourcehut
owner: "rajveermalviya".into(), .parse_remote_url("git@git.sr.ht:~zed-industries/zed")
repo: "zed".into(), .unwrap();
};
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_ssh_url_with_git_suffix() {
let parsed_remote = Sourcehut
.parse_remote_url("git@git.sr.ht:~zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed.git".into(),
}
);
}
#[test]
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Sourcehut
.parse_remote_url("https://git.sr.ht/~zed-industries/zed")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_build_sourcehut_permalink() {
let permalink = Sourcehut.build_permalink( let permalink = Sourcehut.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -106,18 +152,17 @@ mod tests {
}, },
); );
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs"; let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_sourcehut_permalink_from_ssh_url_with_git_prefix() { fn test_build_sourcehut_permalink_with_git_suffix() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed.git".into(),
};
let permalink = Sourcehut.build_permalink( let permalink = Sourcehut.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed.git".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -125,18 +170,17 @@ mod tests {
}, },
); );
let expected_url = "https://git.sr.ht/~rajveermalviya/zed.git/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs"; let expected_url = "https://git.sr.ht/~zed-industries/zed.git/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_sourcehut_permalink_from_ssh_url_single_line_selection() { fn test_build_sourcehut_permalink_with_single_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Sourcehut.build_permalink( let permalink = Sourcehut.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -144,18 +188,17 @@ mod tests {
}, },
); );
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L7"; let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
#[test] #[test]
fn test_build_sourcehut_permalink_from_ssh_url_multi_line_selection() { fn test_build_sourcehut_permalink_with_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Sourcehut.build_permalink( let permalink = Sourcehut.build_permalink(
remote, ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams { BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b", sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/editor/src/git/permalink.rs", path: "crates/editor/src/git/permalink.rs",
@ -163,64 +206,7 @@ mod tests {
}, },
); );
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L24-48"; let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_sourcehut_permalink_from_https_url() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Sourcehut.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: None,
},
);
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/zed/src/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_sourcehut_permalink_from_https_url_single_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Sourcehut.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: Some(6..6),
},
);
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/zed/src/main.rs#L7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_sourcehut_permalink_from_https_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "rajveermalviya".into(),
repo: "zed".into(),
};
let permalink = Sourcehut.build_permalink(
remote,
BuildPermalinkParams {
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
path: "crates/zed/src/main.rs",
selection: Some(23..47),
},
);
let expected_url = "https://git.sr.ht/~rajveermalviya/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/zed/src/main.rs#L24-48";
assert_eq!(permalink.to_string(), expected_url.to_string()) assert_eq!(permalink.to_string(), expected_url.to_string())
} }
} }