#[derive(Debug, Clone)]
pub struct Object {
pub id: i64,
pub hash_type: String,
pub hash_value: String,
pub excluded: bool,
}
impl Object {
#[allow(dead_code)]
pub fn is_excluded(&self) -> bool {
self.excluded
}
}
#[cfg(test)]
mod tests {
use super::*;
fn make_object(id: i64, excluded: bool) -> Object {
Object {
id,
hash_type: "sha256".to_string(),
hash_value: format!("abc123def456_{id}"),
excluded,
}
}
#[test]
fn object_fields_populated() {
let obj = Object {
id: 42,
hash_type: "sha256".to_string(),
hash_value: "deadbeef".to_string(),
excluded: false,
};
assert_eq!(obj.id, 42);
assert_eq!(obj.hash_type, "sha256");
assert_eq!(obj.hash_value, "deadbeef");
assert!(!obj.excluded);
}
#[test]
fn object_clone_creates_copy() {
let original = make_object(1, true);
let cloned = original.clone();
assert_eq!(cloned.id, original.id);
assert_eq!(cloned.hash_type, original.hash_type);
assert_eq!(cloned.hash_value, original.hash_value);
assert_eq!(cloned.excluded, original.excluded);
}
#[test]
fn object_is_excluded_true() {
let obj = make_object(1, true);
assert!(obj.is_excluded());
}
#[test]
fn object_is_excluded_false() {
let obj = make_object(1, false);
assert!(!obj.is_excluded());
}
}