1use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
16#[serde(tag = "type", rename_all = "snake_case")]
17pub enum DiffContent {
18 UnifiedDiff {
20 content: String,
22 },
23
24 CreateFile {
26 content: String,
29 },
30
31 DeleteFile,
33
34 BinarySummary {
36 mime_type: String,
38 size_bytes: u64,
40 hash: String,
42 },
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn unified_diff_serialization_round_trip() {
51 let diff = DiffContent::UnifiedDiff {
52 content: "--- a/file.txt\n+++ b/file.txt\n@@ -1 +1 @@\n-old\n+new".to_string(),
53 };
54 let json = serde_json::to_string(&diff).unwrap();
55 let restored: DiffContent = serde_json::from_str(&json).unwrap();
56 assert_eq!(diff, restored);
57 }
58
59 #[test]
60 fn create_file_serialization() {
61 let diff = DiffContent::CreateFile {
62 content: "fn main() {}".to_string(),
63 };
64 let json = serde_json::to_string(&diff).unwrap();
65 assert!(json.contains("\"create_file\""));
66 }
67
68 #[test]
69 fn binary_summary_serialization() {
70 let diff = DiffContent::BinarySummary {
71 mime_type: "image/png".to_string(),
72 size_bytes: 1024,
73 hash: "abc123".to_string(),
74 };
75 let json = serde_json::to_string(&diff).unwrap();
76 let restored: DiffContent = serde_json::from_str(&json).unwrap();
77 assert_eq!(diff, restored);
78 }
79}