zenpatch/data/action_type.rs
1//! Defines the type of action represented in a patch operation.
2//!
3//! Represents whether a patch file indicates adding, deleting, or updating a file.
4//! Used within the PatchAction structure to categorize changes.
5//! Derived traits support serialization, comparison, and debugging.
6//! Conforms to the one-item-per-file rule.
7
8#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
9pub enum ActionType {
10 Add,
11 Delete,
12 Update,
13}
14
15#[cfg(test)]
16mod tests {
17 // Access the enum under test via `super::`.
18 // Use fully qualified paths for standard library items as per guidelines (e.g., assert!).
19
20 #[test]
21 fn test_action_type_variants_exist() {
22 // Test instantiation of each variant.
23 let add = super::ActionType::Add;
24 let delete = super::ActionType::Delete;
25 let update = super::ActionType::Update;
26
27 // Basic check using debug format to ensure they are distinct enum variants.
28 std::assert_eq!(std::format!("{:?}", add), "Add");
29 std::assert_eq!(std::format!("{:?}", delete), "Delete");
30 std::assert_eq!(std::format!("{:?}", update), "Update");
31 }
32
33 #[test]
34 fn test_action_type_equality() {
35 // Test equality and inequality comparisons.
36 let add1 = super::ActionType::Add;
37 let add2 = super::ActionType::Add;
38 let delete = super::ActionType::Delete;
39
40 std::assert_eq!(add1, add2); // Same variants should be equal.
41 std::assert_ne!(add1, delete); // Different variants should not be equal.
42 }
43
44 #[test]
45 fn test_action_type_cloning() {
46 // Test cloning.
47 let original = super::ActionType::Update;
48 let cloned = original.clone();
49
50 std::assert_eq!(original, cloned); // Cloned value should be equal to original.
51 }
52}