sokf_core/report/
fix_op.rs1use serde::{Deserialize, Serialize};
5
6use crate::RepoPath;
7
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
10#[serde(tag = "op", rename_all = "lowercase")]
11pub enum FixOp {
12 Moved {
14 from: RepoPath,
16 to: RepoPath,
18 },
19 Created {
22 path: RepoPath,
24 },
25 Rewrote {
27 path: RepoPath,
29 },
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 fn p(s: &str) -> RepoPath {
37 RepoPath::parse(s).unwrap()
38 }
39
40 #[test]
41 fn fix_ops_serialize_with_an_op_tag() {
42 let moved = FixOp::Moved {
43 from: p("/a.md"),
44 to: p("/b.md"),
45 };
46 assert_eq!(
47 serde_json::to_string(&moved).unwrap(),
48 r#"{"op":"moved","from":"/a.md","to":"/b.md"}"#
49 );
50 let rewrote = FixOp::Rewrote { path: p("/a.md") };
51 assert_eq!(
52 serde_json::to_string(&rewrote).unwrap(),
53 r#"{"op":"rewrote","path":"/a.md"}"#
54 );
55 let created = FixOp::Created {
56 path: p("/k/index.md"),
57 };
58 assert_eq!(
59 serde_json::to_string(&created).unwrap(),
60 r#"{"op":"created","path":"/k/index.md"}"#
61 );
62 }
63}