#[derive(Debug, Clone)]
pub struct Operation {
pub id: String,
#[allow(dead_code)]
pub user: String,
pub timestamp: String,
pub description: String,
pub is_current: bool,
}
impl Operation {
pub fn short_id(&self) -> &str {
&self.id[..12.min(self.id.len())]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_short_id() {
let op = Operation {
id: "75ea3c2331bf1234567890".to_string(),
user: "user@host".to_string(),
timestamp: "2026-02-02 11:25:54".to_string(),
description: "snapshot working copy".to_string(),
is_current: true,
};
assert_eq!(op.short_id(), "75ea3c2331bf");
}
#[test]
fn test_short_id_short_input() {
let op = Operation {
id: "abc".to_string(),
user: "user@host".to_string(),
timestamp: "2026-02-02 11:25:54".to_string(),
description: "test".to_string(),
is_current: false,
};
assert_eq!(op.short_id(), "abc");
}
}