1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-01 16:10:51 +00:00

feat: abbreviate package.json semantic versions (#2271)

This commit is contained in:
Tom Golden 2021-04-29 14:06:25 -05:00 committed by GitHub
parent 8a8dca71a6
commit c2e84e1802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,6 +68,11 @@ fn extract_package_version(file_contents: &str, display_private: bool) -> Option
};
let formatted_version = format_version(raw_version);
if formatted_version == "v0.0.0-development" || formatted_version.starts_with("v0.0.0-semantic")
{
return Some("semantic".to_string());
};
Some(formatted_version)
}
@ -343,6 +348,51 @@ mod tests {
project_dir.close()
}
#[test]
fn test_package_version_semantic_development_version() -> io::Result<()> {
let config_name = "package.json";
let config_content = json::json!({
"name": "starship",
"version": "0.0.0-development"
})
.to_string();
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(&config_content))?;
expect_output(&project_dir, Some("semantic"), None);
project_dir.close()
}
#[test]
fn test_package_version_with_semantic_other_version() -> io::Result<()> {
let config_name = "package.json";
let config_content = json::json!({
"name": "starship",
"version": "v0.0.0-semantically-released"
})
.to_string();
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(&config_content))?;
expect_output(&project_dir, Some("semantic"), None);
project_dir.close()
}
#[test]
fn test_package_version_with_non_semantic_tag() -> io::Result<()> {
let config_name = "package.json";
let config_content = json::json!({
"name": "starship",
"version": "v0.0.0-alpha"
})
.to_string();
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(&config_content))?;
expect_output(&project_dir, Some("v0.0.0-alpha"), None);
project_dir.close()
}
#[test]
fn test_extract_poetry_version() -> io::Result<()> {
let config_name = "pyproject.toml";