fix: Remove duplicated "v" in package versions (#648)

This commit is contained in:
Thomas O'Donnell 2019-11-20 15:16:07 +01:00 committed by Matan Kushner
parent 6a45e561fc
commit 45d977aa39

View File

@ -72,7 +72,12 @@ fn get_package_version() -> Option<String> {
}
fn format_version(version: &str) -> String {
format!("v{}", version.replace('"', "").trim())
let cleaned = version.replace('"', "").trim().to_string();
if cleaned.starts_with('v') {
cleaned
} else {
format!("v{}", cleaned)
}
}
#[cfg(test)]
@ -82,6 +87,16 @@ mod tests {
#[test]
fn test_format_version() {
assert_eq!(format_version("0.1.0"), "v0.1.0");
assert_eq!(format_version(" 0.1.0 "), "v0.1.0");
assert_eq!(format_version("0.1.0 "), "v0.1.0");
assert_eq!(format_version(" 0.1.0"), "v0.1.0");
assert_eq!(format_version("\"0.1.0\""), "v0.1.0");
assert_eq!(format_version("v0.1.0"), "v0.1.0");
assert_eq!(format_version(" v0.1.0 "), "v0.1.0");
assert_eq!(format_version(" v0.1.0"), "v0.1.0");
assert_eq!(format_version("v0.1.0 "), "v0.1.0");
assert_eq!(format_version("\"v0.1.0\""), "v0.1.0");
}
#[test]