From 157bab1d560dee45eed3c294188edc1063bc4686 Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Sun, 4 Dec 2022 00:04:28 +0100 Subject: [PATCH] Reformat the code a bit. --- rustfmt.toml | 1 + src/parser.rs | 20 ++++------------ src/password.rs | 10 +------- src/repl.rs | 64 +++++++++++++------------------------------------ 4 files changed, 23 insertions(+), 72 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..b28d8cf --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 160 diff --git a/src/parser.rs b/src/parser.rs index 8fb3806..5c8feaf 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -76,9 +76,7 @@ mod tests { #[test] fn parse_password_test() { assert_eq!( - command_parser::name( - "ableton89 R 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com" - ), + command_parser::name("ableton89 R 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com"), Ok(Password { name: Rc::new("ableton89".to_string()), parent: None, @@ -91,9 +89,7 @@ mod tests { }) ); assert_eq!( - command_parser::name( - "ableton89 U 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com" - ), + command_parser::name("ableton89 U 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com"), Ok(Password { name: Rc::new("ableton89".to_string()), parent: None, @@ -119,9 +115,7 @@ mod tests { }) ); assert_eq!( - command_parser::name( - "#W9 ableton89 R 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com" - ), + command_parser::name("#W9 ableton89 R 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com"), Ok(Password { name: Rc::new("ableton89".to_string()), parent: None, @@ -134,9 +128,7 @@ mod tests { }) ); assert_eq!( - command_parser::name( - "#W9 ableton89 N 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com" - ), + command_parser::name("#W9 ableton89 N 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com"), Ok(Password { name: Rc::new("ableton89".to_string()), parent: None, @@ -149,9 +141,7 @@ mod tests { }) ); assert_eq!( - command_parser::name( - "#W9 ableton89 UN 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com" - ), + command_parser::name("#W9 ableton89 UN 99 2020-12-09 xx.ableton@domain.info https://www.ableton.com"), Ok(Password { name: Rc::new("ableton89".to_string()), parent: None, diff --git a/src/password.rs b/src/password.rs index ccac691..f0f4545 100644 --- a/src/password.rs +++ b/src/password.rs @@ -25,15 +25,7 @@ pub struct Password { } impl Password { - pub fn new( - prefix: Prefix, - name: Name, - length: Length, - mode: Mode, - seq: Seq, - date: Date, - comment: Comment, - ) -> Password { + pub fn new(prefix: Prefix, name: Name, length: Length, mode: Mode, seq: Seq, date: Date, comment: Comment) -> Password { Password { prefix, name: Rc::new(name), diff --git a/src/repl.rs b/src/repl.rs index cf31bc7..c29b72a 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -51,12 +51,7 @@ impl LKRead { } self.cmd = match self.rl.readline(&*self.prompt) { Ok(str) => str, - Err(err) => { - return LKEval::new( - Command::Error(LKErr::ReadError(err.to_string())), - self.state.clone(), - ) - } + Err(err) => return LKEval::new(Command::Error(LKErr::ReadError(err.to_string())), self.state.clone()), }; self.rl.add_history_entry(self.cmd.as_str()); match self.rl.save_history(&history_file) { @@ -98,10 +93,7 @@ impl<'a> LKEval<'a> { if self.state.borrow().db.get(&name.borrow().name).is_some() { out.push("error: password already exist".to_string()); } else { - self.state - .borrow_mut() - .db - .insert(name.borrow().name.clone(), name.clone()); + self.state.borrow_mut().db.insert(name.borrow().name.clone(), name.clone()); self.state.borrow().fix_hierarchy(); } } @@ -170,10 +162,7 @@ mod tests { #[test] fn exec_cmds_basic() { let lk = Rc::new(RefCell::new(LK::new())); - assert_eq!( - LKEval::new(Command::Ls, lk.clone()).eval(), - LKPrint::new(vec![], false, lk.clone()) - ); + assert_eq!(LKEval::new(Command::Ls, lk.clone()).eval(), LKPrint::new(vec![], false, lk.clone())); let pwd1 = Rc::new(RefCell::new(Password { name: Rc::new("t1".to_string()), prefix: None, @@ -184,25 +173,14 @@ mod tests { comment: Some("comment".to_string()), parent: None, })); - assert_eq!( - LKEval::new(Command::Add(pwd1.clone()), lk.clone()) - .eval() - .state - .borrow() - .db, - { - let mut db = HashMap::new(); - db.insert(pwd1.borrow().name.clone(), pwd1.clone()); - db - } - ); + assert_eq!(LKEval::new(Command::Add(pwd1.clone()), lk.clone()).eval().state.borrow().db, { + let mut db = HashMap::new(); + 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() - ) + LKPrint::new(vec!["t1 R 99 2022-12-30 comment".to_string()], false, lk.clone()) ); assert_eq!( LKEval::new(Command::Quit, lk.clone()).eval(), @@ -218,26 +196,16 @@ mod tests { comment: Some("bli blup".to_string()), parent: None, })); - assert_eq!( - LKEval::new(Command::Add(pwd2.clone()), lk.clone()) - .eval() - .state - .borrow() - .db, - { - let mut db = HashMap::new(); - db.insert(pwd1.borrow().name.clone(), pwd1.clone()); - db.insert(pwd2.borrow().name.clone(), pwd2.clone()); - db - } - ); + assert_eq!(LKEval::new(Command::Add(pwd2.clone()), lk.clone()).eval().state.borrow().db, { + let mut db = HashMap::new(); + db.insert(pwd1.borrow().name.clone(), pwd1.clone()); + db.insert(pwd2.borrow().name.clone(), pwd2.clone()); + db + }); 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() - ], + vec!["t1 R 99 2022-12-30 comment".to_string(), "t2 R 99 2022-12-31 bli blup".to_string()], false, lk.clone() )