mirror of
https://github.com/denisidoro/navi.git
synced 2026-07-18 00:54:58 +00:00
added extra test cases and improved error handling in git.rs
This commit is contained in:
parent
4c01ae0a38
commit
ed1791c71a
1 changed files with 49 additions and 1 deletions
|
|
@ -16,7 +16,23 @@ pub fn meta(uri: &str) -> (String, String, String) {
|
|||
let actual_uri = if uri.contains("://") || uri.contains('@') {
|
||||
uri.to_string()
|
||||
} else {
|
||||
format!("https://github.com/{uri}")
|
||||
if let Some((domain, route)) = uri.split_once('/') {
|
||||
if domain.contains(".") {
|
||||
format!("https://{domain}/{route}")
|
||||
} else {
|
||||
// Users can pass name starting wirh a slash
|
||||
let first_char = uri.chars().next();
|
||||
|
||||
if first_char == Some('/') {
|
||||
format!("https://github.com{uri}")
|
||||
}
|
||||
else {
|
||||
format!("https://github.com/{uri}")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
panic!("Invalid link")
|
||||
}
|
||||
};
|
||||
|
||||
let uri_to_split = actual_uri.replace(':', "/");
|
||||
|
|
@ -54,4 +70,36 @@ mod tests {
|
|||
assert_eq!(user, "user".to_string());
|
||||
assert_eq!(repo, "repo".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meta_github_repo_name() {
|
||||
let (actual_uri, user, repo) = meta("user/repo");
|
||||
assert_eq!(actual_uri, "https://github.com/user/repo".to_string());
|
||||
assert_eq!(user, "user".to_string());
|
||||
assert_eq!(repo, "repo".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meta_github_repo_name_with_slash() {
|
||||
let (actual_uri, user, repo) = meta("/user/repo");
|
||||
assert_eq!(actual_uri, "https://github.com/user/repo".to_string());
|
||||
assert_eq!(user, "user".to_string());
|
||||
assert_eq!(repo, "repo".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meta_github_clean_link() {
|
||||
let (actual_uri, user, repo) = meta("github.com/user/repo");
|
||||
assert_eq!(actual_uri, "https://github.com/user/repo".to_string());
|
||||
assert_eq!(user, "user".to_string());
|
||||
assert_eq!(repo, "repo".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_meta_random_git_provider_http() {
|
||||
let (actual_uri, user, repo) = meta("https://sr.ht/user/repo");
|
||||
assert_eq!(actual_uri, "https://sr.ht/user/repo".to_string());
|
||||
assert_eq!(user, "user".to_string());
|
||||
assert_eq!(repo, "repo".to_string());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue