From de7fd70110e64c998254b65b89d418c1c5ceeb9f Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Sun, 4 Dec 2022 00:13:25 +0100 Subject: [PATCH] Reformat the code a bit more. --- rustfmt.toml | 7 ++++++- src/password.rs | 55 ++++++------------------------------------------- src/repl.rs | 16 +++----------- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index b28d8cf..92dfc5e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,6 @@ -max_width = 160 +max_width = 180 +fn_call_width = 150 +attr_fn_like_width = 140 +array_width = 160 +chain_width = 160 +edition = "2021" diff --git a/src/password.rs b/src/password.rs index f0f4545..98a7a50 100644 --- a/src/password.rs +++ b/src/password.rs @@ -57,10 +57,7 @@ impl std::string::ToString for Password { Some(s) => format!(" ^{}", s.borrow().name), None => "".to_string(), }; - format!( - "{}{} {}{} {} {}{}{}", - prefix, self.name, length, self.mode, self.seq, self.date, comment, parent - ) + format!("{}{} {}{} {} {}{}{}", prefix, self.name, length, self.mode, self.seq, self.date, comment, parent) } } @@ -102,59 +99,19 @@ mod tests { #[test] fn exec_recursion_test() { - let p1 = Rc::new(RefCell::new(Password::new( - None, - "p1".to_string(), - None, - Mode::Regular, - 99, - NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), - None, - ))); + let p1 = Rc::new(RefCell::new(Password::new(None, "p1".to_string(), None, Mode::Regular, 99, NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), None))); p1.borrow_mut().parent = Some(p1.clone()); fix_password_recursion(p1.clone()); assert_eq!(p1.borrow().parent, None); - let p2 = Rc::new(RefCell::new(Password::new( - None, - "p2".to_string(), - None, - Mode::Regular, - 99, - NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), - None, - ))); + let p2 = Rc::new(RefCell::new(Password::new(None, "p2".to_string(), None, Mode::Regular, 99, NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), None))); p2.borrow_mut().parent = Some(p1.clone()); - let p3 = Rc::new(RefCell::new(Password::new( - None, - "p3".to_string(), - None, - Mode::Regular, - 99, - NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), - None, - ))); + let p3 = Rc::new(RefCell::new(Password::new(None, "p3".to_string(), None, Mode::Regular, 99, NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), None))); p3.borrow_mut().parent = Some(p2.clone()); - let p4 = Rc::new(RefCell::new(Password::new( - None, - "p4".to_string(), - None, - Mode::Regular, - 99, - NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), - None, - ))); + let p4 = Rc::new(RefCell::new(Password::new(None, "p4".to_string(), None, Mode::Regular, 99, NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), None))); p4.borrow_mut().parent = Some(p3.clone()); - let p5 = Rc::new(RefCell::new(Password::new( - None, - "p5".to_string(), - None, - Mode::Regular, - 99, - NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), - None, - ))); + let p5 = Rc::new(RefCell::new(Password::new(None, "p5".to_string(), None, Mode::Regular, 99, NaiveDate::from_ymd_opt(2022, 12, 3).unwrap(), None))); p5.borrow_mut().parent = Some(p4.clone()); p1.borrow_mut().parent = Some(p3.clone()); diff --git a/src/repl.rs b/src/repl.rs index c29b72a..fbbc7cd 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -178,14 +178,8 @@ mod tests { db.insert(pwd1.borrow().name.clone(), pwd1.clone()); db }); - assert_eq!( - LKEval::new(Command::Ls, lk.clone()).eval(), - LKPrint::new(vec!["t1 R 99 2022-12-30 comment".to_string()], false, lk.clone()) - ); - assert_eq!( - LKEval::new(Command::Quit, lk.clone()).eval(), - LKPrint::new(vec!["Bye!".to_string()], true, lk.clone()) - ); + assert_eq!(LKEval::new(Command::Ls, lk.clone()).eval(), LKPrint::new(vec!["t1 R 99 2022-12-30 comment".to_string()], false, lk.clone())); + assert_eq!(LKEval::new(Command::Quit, lk.clone()).eval(), LKPrint::new(vec!["Bye!".to_string()], true, lk.clone())); let pwd2 = Rc::new(RefCell::new(Password { name: Rc::new("t2".to_string()), prefix: None, @@ -204,11 +198,7 @@ mod tests { }); assert_eq!( LKEval::new(Command::Ls, lk.clone()).eval(), - LKPrint::new( - vec!["t1 R 99 2022-12-30 comment".to_string(), "t2 R 99 2022-12-31 bli blup".to_string()], - false, - lk.clone() - ) + LKPrint::new(vec!["t1 R 99 2022-12-30 comment".to_string(), "t2 R 99 2022-12-31 bli blup".to_string()], false, lk.clone()) ); } }