From e9758f6b1566c66db68a778a0b16338f9c2ecbf3 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Tue, 28 Mar 2017 19:58:25 +0200 Subject: [PATCH] Bad Rustfmt formattings --- rustfmt.toml | 5 ++++ waltz/src/code_block.rs | 8 +++--- waltz_cli/src/cli.rs | 27 +++++++++++--------- waltz_cli/src/main.rs | 9 ++++--- waltz_cli/tests/concat.rs | 26 +++++++++++++------ waltz_cli/tests/simple.rs | 42 +++++++++++++++++++------------ waltz_cli/tests/utils/mod.rs | 49 ++++++++++++++++-------------------- 7 files changed, 97 insertions(+), 69 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..4afa30d --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +fn_args_layout = "Block" +array_layout = "Block" +where_style = "Rfc" +generics_indent = "Block" +fn_call_style = "Block" \ No newline at end of file diff --git a/waltz/src/code_block.rs b/waltz/src/code_block.rs index f906132..f9e461e 100644 --- a/waltz/src/code_block.rs +++ b/waltz/src/code_block.rs @@ -62,7 +62,7 @@ impl CodeBlock { let path = Path::new(root.as_ref()).join(&self.filename()); let parent = match path.parent() { Some(p) => p, - None => bail!("Can't create file for code block, path has no parent directory"), + None => bail!("Can't create file for code block, path has no parent directory",), }; create_dir_all(parent)?; @@ -82,7 +82,8 @@ mod test { #[test] fn parsing() { - let example = unindent(r#" + let example = unindent( + r#" # Lorem ipsum ## Shell @@ -98,7 +99,8 @@ mod test { println!("Dolor sit amet"); } ``` - "#); + "#, + ); let markdown = ::pulldown_cmark::Parser::new(&example); let code_blocks = ::extract_code_blocks(markdown).unwrap(); diff --git a/waltz_cli/src/cli.rs b/waltz_cli/src/cli.rs index b7006d0..40745bd 100644 --- a/waltz_cli/src/cli.rs +++ b/waltz_cli/src/cli.rs @@ -5,19 +5,22 @@ pub fn app() -> App<'static, 'static> { .version(crate_version!()) .author("Pascal Hertleif ") .about("Extract code blocks from Markdown and save them as files.") - .arg(Arg::with_name("input_file") - .help("The input markdown file") - .index(1) - .required(true) + .arg( + Arg::with_name("input_file") + .help("The input markdown file") + .index(1) + .required(true), ) - .arg(Arg::with_name("target_dir") - .help("The target directory") - .short("o") - .takes_value(true) + .arg( + Arg::with_name("target_dir") + .help("The target directory") + .short("o") + .takes_value(true), ) - .arg(Arg::with_name("v") - .short("v") - .help("Enable logging, use multiple `v`s to increase verbosity") - .multiple(true) + .arg( + Arg::with_name("v") + .short("v") + .help("Enable logging, use multiple `v`s to increase verbosity") + .multiple(true), ) } diff --git a/waltz_cli/src/main.rs b/waltz_cli/src/main.rs index 144003f..6c5a5d6 100644 --- a/waltz_cli/src/main.rs +++ b/waltz_cli/src/main.rs @@ -37,8 +37,8 @@ fn try_main() -> Result<()> { // Parse markdown file let input = { let mut res = String::new(); - let mut f = File::open(input_file) - .chain_err(|| format!("Error opening file `{}`", input_file))?; + let mut f = + File::open(input_file).chain_err(|| format!("Error opening file `{}`", input_file))?; f.read_to_string(&mut res) .chain_err(|| format!("Error reading file `{}`", input_file))?; info!("Read file `{}`", input_file); @@ -48,7 +48,10 @@ fn try_main() -> Result<()> { let code_blocks = waltz::extract_code_blocks(parser)?; - info!("Found {} code blocks (not all might have file names)", code_blocks.len()); + info!( + "Found {} code blocks (not all might have file names)", + code_blocks.len(), + ); // Output files for code_block in code_blocks.iter().filter(|cb| cb.has_filename()) { diff --git a/waltz_cli/tests/concat.rs b/waltz_cli/tests/concat.rs index df9eabd..b706c22 100644 --- a/waltz_cli/tests/concat.rs +++ b/waltz_cli/tests/concat.rs @@ -3,7 +3,8 @@ use utils::*; #[test] fn concat() { - given(r#" + given( + r#" # Getting started First of all, create a simple `Cargo.toml` file: @@ -45,15 +46,22 @@ fn concat() { } } ``` - "#) - .running(waltz) - .creates(file("Cargo.toml").containing(r#" + "#, + ) + .running(waltz) + .creates( + file("Cargo.toml").containing( + r#" [package] authors = ["Pascal Hertleif "] name = "foo" version = "0.1.0" - "#)) - .creates(file("src/lib.rs").containing(r#" + "#, + ), + ) + .creates( + file("src/lib.rs").containing( + r#" struct Foo { x: i32, } @@ -69,6 +77,8 @@ fn concat() { Foo { x: 42 } } } - "#)) - .running(cargo_check); + "#, + ), + ) + .running(cargo_check); } diff --git a/waltz_cli/tests/simple.rs b/waltz_cli/tests/simple.rs index 646cc19..e13ad3a 100644 --- a/waltz_cli/tests/simple.rs +++ b/waltz_cli/tests/simple.rs @@ -3,7 +3,8 @@ use utils::*; #[test] fn simple() { - given(r#" + given( + r#" # Getting started First of all, create a simple `Cargo.toml` file: @@ -22,25 +23,35 @@ fn simple() { println!("Hello, world!"); } ``` - "#) - .running(waltz) - .creates(file("Cargo.toml").containing(r#" + "#, + ) + .running(waltz) + .creates( + file("Cargo.toml").containing( + r#" [package] authors = ["Pascal Hertleif "] name = "foo" version = "0.1.0" - "#)) - .creates(file("src/main.rs").containing(r#" + "#, + ), + ) + .creates( + file("src/main.rs").containing( + r#" fn main() { println!("Hello, world!"); } - "#)) - .running(|cwd| main(cwd).prints("Hello, world!")); + "#, + ), + ) + .running(|cwd| main(cwd).prints("Hello, world!")); } #[test] fn complex_paths() { - given(r#" + given( + r#" First off: ```toml,file=Cargo.toml @@ -61,11 +72,10 @@ fn complex_paths() { println!("Sup dawg I herd u likd nested dirs"); } ``` - "#) - .running(waltz) - .creates(file("Cargo.toml")) - .creates(file("src/bin/lolwut/main.rs")) - .running(|cwd| binary(cwd, "lolwut") - .prints("Sup dawg") - ); + "#, + ) + .running(waltz) + .creates(file("Cargo.toml")) + .creates(file("src/bin/lolwut/main.rs")) + .running(|cwd| binary(cwd, "lolwut").prints("Sup dawg")); } diff --git a/waltz_cli/tests/utils/mod.rs b/waltz_cli/tests/utils/mod.rs index 9144dc5..51b6a05 100644 --- a/waltz_cli/tests/utils/mod.rs +++ b/waltz_cli/tests/utils/mod.rs @@ -25,34 +25,29 @@ pub fn file(path: &str) -> FileAssert { pub fn waltz(cwd: &Path) -> CliAssert { CliAssert::main_binary() - .with_args(&[ - "-vvv", - cwd.join("test.md").to_str().unwrap(), - "-o", cwd.to_str().unwrap(), - ]) + .with_args(&["-vvv", cwd.join("test.md").to_str().unwrap(), "-o", cwd.to_str().unwrap()],) .succeeds() } pub fn main(cwd: &Path) -> CliAssert { - CliAssert::command(&[ - "cargo", "run", - "--manifest-path", cwd.join("Cargo.toml").to_str().unwrap(), - ]) + CliAssert::command(&["cargo", "run", "--manifest-path", cwd.join("Cargo.toml").to_str().unwrap()],) } pub fn binary(cwd: &Path, name: &str) -> CliAssert { - CliAssert::command(&[ - "cargo", "run", - "--manifest-path", cwd.join("Cargo.toml").to_str().unwrap(), - "--bin", name, - ]) + CliAssert::command( + &[ + "cargo", + "run", + "--manifest-path", + cwd.join("Cargo.toml").to_str().unwrap(), + "--bin", + name, + ], + ) } fn cargo(cwd: &Path, subcommand: &str) -> CliAssert { - CliAssert::command(&[ - "cargo", subcommand, - "--manifest-path", cwd.join("Cargo.toml").to_str().unwrap(), - ]) + CliAssert::command(&["cargo", subcommand, "--manifest-path", cwd.join("Cargo.toml").to_str().unwrap()],) } pub fn cargo_check(cwd: &Path) -> CliAssert { @@ -85,18 +80,17 @@ impl Assert { fn with_file(content: &str) -> Self { let a = Assert::default(); - create_dir_all(&a.output_dir) - .expect("error creating output dir"); + create_dir_all(&a.output_dir).expect("error creating output dir"); - let mut f = File::create(a.output_dir.join("test.md")) - .expect("error create md file"); + let mut f = File::create(a.output_dir.join("test.md")).expect("error create md file"); f.write_all(unindent(content).as_bytes()) .expect("error writing md file"); a } - pub fn running(&self, cmd: F) -> &Self where + pub fn running(&self, cmd: F) -> &Self + where F: for<'cwd> Fn(&'cwd Path) -> CliAssert, { cmd(&self.output_dir).unwrap(); @@ -104,8 +98,7 @@ impl Assert { } pub fn creates(&self, fa: FileAssert) -> &Self { - fa.context(self.output_dir.to_owned()) - .unwrap(); + fa.context(self.output_dir.to_owned()).unwrap(); self } } @@ -137,14 +130,16 @@ impl FileAssert { } fn unwrap(self) { - let dir = self.working_dir.expect(&format!("No working dir set for `{}`", self.path)); + let dir = self.working_dir + .expect(&format!("No working dir set for `{}`", self.path)); let path = PathBuf::from(dir).join(&self.path); let mut f = File::open(&path).expect(&format!("no file at {:?}", path)); if let Some(expected_content) = self.content { let mut content = String::new(); - f.read_to_string(&mut content).expect(&format!("failed to read {:?}", path)); + f.read_to_string(&mut content) + .expect(&format!("failed to read {:?}", path)); let diff = Changeset::new(&content, &unindent(&expected_content), "\n"); if diff.distance > 0 {