use super::id::{ChangeId, CommitId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TagInfo {
pub name: String,
pub remote: Option<String>,
pub present: bool,
pub change_id: Option<ChangeId>,
pub commit_id: Option<CommitId>,
pub description: Option<String>,
}
impl TagInfo {
pub fn full_name(&self) -> String {
match &self.remote {
Some(remote) => format!("{}@{}", self.name, remote),
None => self.name.clone(),
}
}
pub fn is_local(&self) -> bool {
self.remote.is_none()
}
pub fn is_jumpable(&self) -> bool {
self.change_id.is_some()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_full_name_local() {
let tag = TagInfo {
name: "v0.4.10".into(),
remote: None,
present: true,
change_id: Some(ChangeId::from("mzslzzzz")),
commit_id: Some(CommitId::from("57d01adc")),
description: Some("fix: something".into()),
};
assert_eq!(tag.full_name(), "v0.4.10");
}
#[test]
fn test_full_name_remote() {
let tag = TagInfo {
name: "v0.4.10".into(),
remote: Some("origin".into()),
present: true,
change_id: None,
commit_id: None,
description: None,
};
assert_eq!(tag.full_name(), "v0.4.10@origin");
}
#[test]
fn test_is_local() {
let local = TagInfo {
name: "v1.0".into(),
remote: None,
present: true,
change_id: Some(ChangeId::from("abc")),
commit_id: None,
description: None,
};
assert!(local.is_local());
let remote = TagInfo {
name: "v1.0".into(),
remote: Some("origin".into()),
present: true,
change_id: None,
commit_id: None,
description: None,
};
assert!(!remote.is_local());
}
#[test]
fn test_is_jumpable() {
let jumpable = TagInfo {
name: "v1.0".into(),
remote: None,
present: true,
change_id: Some(ChangeId::from("abc12345")),
commit_id: Some(CommitId::from("def67890")),
description: Some("release".into()),
};
assert!(jumpable.is_jumpable());
let not_jumpable = TagInfo {
name: "v1.0".into(),
remote: None,
present: true,
change_id: None,
commit_id: None,
description: None,
};
assert!(!not_jumpable.is_jumpable());
}
}