1#[derive(Debug, PartialEq, Eq, Clone)]
4pub(super) enum Operation {
5 Retain(usize),
7 Insert(String),
9 Delete(usize),
11}
12
13impl ToString for Operation {
14 fn to_string(&self) -> String {
15 match self {
16 &Self::Retain(n) => format!("retain({})", n),
17 Self::Insert(str) => format!("insert(\"{}\")", str.replace('"', "\\\"")),
18 &Self::Delete(n) => format!("delete({})", n),
19 }
20 }
21}
22
23#[cfg(test)]
24mod tests {
25
26 use super::Operation;
27
28 #[test]
29 fn it_works() {
30 assert_eq!("retain(1)", Operation::Retain(1).to_string());
31 assert_eq!(
32 "insert(\"abc\")",
33 Operation::Insert("abc".to_string()).to_string()
34 );
35 assert_eq!(
36 "insert(\"abc\\\"\")",
37 Operation::Insert("abc\"".to_string()).to_string()
38 );
39 }
40}