From 2d2476ffc7545e9f90c5e74b963c9e2dc9660711 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 20 Oct 2018 09:50:19 -0400 Subject: fix: cargo fmt --- src/org.rs | 66 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'src/org.rs') diff --git a/src/org.rs b/src/org.rs index 84df9c2..aa81581 100644 --- a/src/org.rs +++ b/src/org.rs @@ -5,7 +5,7 @@ use std::str; pub enum Org { Unknown(String), Header(u16, String), - Properties(Vec<(String, String)>) + Properties(Vec<(String, String)>), } type OrgDocument = Vec; @@ -27,19 +27,19 @@ matchers! { properties_end <- r"^\s*:END:\s*$"; } -struct Parser> { +struct Parser> { doc: OrgDocument, iter: I, } -impl> Parser { +impl> Parser { fn go(&mut self) { while let Some(line) = self.iter.next() { if let Some(g) = header.captures(&line) { - self.doc.push( - Org::Header( - g.get(1).unwrap().as_str().len() as u16, - g.get(2).unwrap().as_str().to_string())); + self.doc.push(Org::Header( + g.get(1).unwrap().as_str().len() as u16, + g.get(2).unwrap().as_str().to_string(), + )); } else if properties_start.is_match(&line) { &mut self.go_properties(line.clone()); } else { @@ -49,8 +49,8 @@ impl> Parser { } fn go_properties(&mut self, first_line: String) { - let mut fallback = vec!(first_line); - let mut properties = vec!(); + let mut fallback = vec![first_line]; + let mut properties = vec![]; while let Some(line) = self.iter.next() { fallback.push(line.clone()); @@ -58,7 +58,8 @@ impl> Parser { if let Some(g) = property.captures(&line) { properties.push(( g.get(1).unwrap().as_str().to_string(), - g.get(2).unwrap().as_str().to_string())); + g.get(2).unwrap().as_str().to_string(), + )); } else if properties_end.is_match(&line) { break; } else { @@ -71,9 +72,9 @@ impl> Parser { } pub fn parse(input: &str) -> OrgDocument { - let mut parser = Parser{ - doc: vec!(), - iter: input.split('\n').map(|line| line.to_string()) + let mut parser = Parser { + doc: vec![], + iter: input.split('\n').map(|line| line.to_string()), }; parser.go(); parser.doc @@ -90,18 +91,23 @@ mod tests { #[test] fn parse_unknown() { let doc = "hello\nhello"; - assert_eq!(parse(doc), - vec!(Org::Unknown("hello".to_string()), - Org::Unknown("hello".to_string()))); + assert_eq!( + parse(doc), + vec![ + Org::Unknown("hello".to_string()), + Org::Unknown("hello".to_string()), + ] + ); } #[test] fn parse_header() { let doc = "* hello"; - assert_eq!(parse(doc), - vec!(Org::Header(1, "hello".to_string()))); - assert_eq!(parse(" * hello"), - vec!(Org::Unknown(" * hello".to_string()))); + assert_eq!(parse(doc), vec![Org::Header(1, "hello".to_string())]); + assert_eq!( + parse(" * hello"), + vec![Org::Unknown(" * hello".to_string())] + ); } #[test] @@ -110,13 +116,19 @@ mod tests { :VERSION: 1.0 :ANIMAL: dog :END:"; - assert_eq!(parse(doc), - vec!(Org::Properties(vec!( - (s("VERSION"), s("1.0")), - (s("ANIMAL"), s("dog")))))); + assert_eq!( + parse(doc), + vec![ + Org::Properties(vec![(s("VERSION"), s("1.0")), (s("ANIMAL"), s("dog"))]), + ] + ); let doc = ":PROPERTIES:\ninvalid\n:END:"; - assert_eq!(parse(doc), - vec!(Org::Unknown(s(":PROPERTIES:\ninvalid")), - Org::Unknown(s(":END:")))); + assert_eq!( + parse(doc), + vec![ + Org::Unknown(s(":PROPERTIES:\ninvalid")), + Org::Unknown(s(":END:")), + ] + ); } } -- cgit v1.2.3